Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from glog to klog #2787

Merged
merged 5 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions client/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"fmt"
"time"

"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/client/backoff"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
)

// CreateAndInitTree uses the adminClient and logClient to create the tree
Expand All @@ -47,17 +47,17 @@ func CreateAndInitTree(

var tree *trillian.Tree
err := b.Retry(ctx, func() error {
glog.Info("CreateTree...")
klog.Info("CreateTree...")
var err error
tree, err = adminClient.CreateTree(ctx, req)
switch code := status.Code(err); code {
case codes.Unavailable:
glog.Errorf("Admin server unavailable: %v", err)
klog.Errorf("Admin server unavailable: %v", err)
return err
case codes.OK:
return nil
default:
glog.Errorf("failed to CreateTree(%+v): %T %v", req, err, err)
klog.Errorf("failed to CreateTree(%+v): %T %v", req, err, err)
return err
}
})
Expand Down Expand Up @@ -92,22 +92,22 @@ func InitLog(ctx context.Context, tree *trillian.Tree, logClient trillian.Trilli
}

err := b.Retry(ctx, func() error {
glog.Infof("Initialising Log %v...", tree.TreeId)
klog.Infof("Initialising Log %v...", tree.TreeId)
req := &trillian.InitLogRequest{LogId: tree.TreeId}
resp, err := logClient.InitLog(ctx, req)
switch code := status.Code(err); code {
case codes.Unavailable:
glog.Errorf("Log server unavailable: %v", err)
klog.Errorf("Log server unavailable: %v", err)
return err
case codes.AlreadyExists:
glog.Warningf("Bizarrely, the just-created Log (%v) is already initialised!: %v", tree.TreeId, err)
klog.Warningf("Bizarrely, the just-created Log (%v) is already initialised!: %v", tree.TreeId, err)
return err
case codes.OK:
glog.Infof("Initialised Log (%v) with new SignedTreeHead:\n%+v",
klog.Infof("Initialised Log (%v) with new SignedTreeHead:\n%+v",
tree.TreeId, resp.Created)
return nil
default:
glog.Errorf("failed to InitLog(%+v): %T %v", req, err, err)
klog.Errorf("failed to InitLog(%+v): %T %v", req, err, err)
return err
}
})
Expand Down
2 changes: 1 addition & 1 deletion client/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

_ "github.com/golang/glog"
_ "k8s.io/klog/v2"
)

func TestBackoff(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions client/mutating_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"context"
"math/rand"

"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/types"
"google.golang.org/grpc"
"k8s.io/klog/v2"
)

// MutatingLogClient supports applying mutations to the return values of the TrillianLogClient
Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *MutatingLogClient) GetInclusionProofByHash(ctx context.Context, in *tri
if c.mutateInclusionProof {
h := rand.Intn(len(resp.Proof))
if len(resp.Proof[h].Hashes) == 0 {
glog.Warningf("Inclusion proof not modified because treesize = 0")
klog.Warningf("Inclusion proof not modified because treesize = 0")
return resp, nil
}
i := rand.Intn(len(resp.Proof[h].Hashes))
Expand All @@ -85,7 +85,7 @@ func (c *MutatingLogClient) GetConsistencyProof(ctx context.Context, in *trillia
}
if c.mutateConsistencyProof {
if len(resp.Proof.Hashes) == 0 {
glog.Warningf("Consistency proof not modified because len(Hashes) = 0")
klog.Warningf("Consistency proof not modified because len(Hashes) = 0")
return resp, nil
}
i := rand.Intn(len(resp.Proof.Hashes))
Expand Down
4 changes: 2 additions & 2 deletions client/rpcflags/rpcflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package rpcflags
import (
"flag"

"github.com/golang/glog"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"k8s.io/klog/v2"
)

// tlsCertFile is the flag-assigned value for the path to the Trillian server's TLS certificate.
Expand All @@ -32,7 +32,7 @@ func NewClientDialOptionsFromFlags() ([]grpc.DialOption, error) {
dialOpts := []grpc.DialOption{}

if *tlsCertFile == "" {
glog.Warning("Using an insecure gRPC connection to Trillian")
klog.Warning("Using an insecure gRPC connection to Trillian")
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
creds, err := credentials.NewClientTLSFromFile(*tlsCertFile, "")
Expand Down
11 changes: 6 additions & 5 deletions cmd/createtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
"fmt"
"time"

"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/client"
"github.com/google/trillian/client/rpcflags"
"github.com/google/trillian/cmd"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/durationpb"
"k8s.io/klog/v2"
)

var (
Expand Down Expand Up @@ -103,26 +103,27 @@ func newRequest() (*trillian.CreateTreeRequest, error) {
Description: *description,
MaxRootDuration: durationpb.New(*maxRootDuration),
}}
glog.Infof("Creating tree %+v", ctr.Tree)
klog.Infof("Creating tree %+v", ctr.Tree)

return ctr, nil
}

func main() {
klog.InitFlags(nil)
flag.Parse()
defer glog.Flush()
defer klog.Flush()

if *configFile != "" {
if err := cmd.ParseFlagFile(*configFile); err != nil {
glog.Exitf("Failed to load flags from config file %q: %s", *configFile, err)
klog.Exitf("Failed to load flags from config file %q: %s", *configFile, err)
}
}

ctx, cancel := context.WithTimeout(context.Background(), *rpcDeadline)
defer cancel()
tree, err := createTree(ctx)
if err != nil {
glog.Exitf("Failed to create tree: %v", err)
klog.Exitf("Failed to create tree: %v", err)
}

// DO NOT change the output format, scripts are meant to depend on it.
Expand Down
13 changes: 7 additions & 6 deletions cmd/deletetree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"context"
"flag"

"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/client/rpcflags"
"google.golang.org/grpc"
"k8s.io/klog/v2"
)

var (
Expand All @@ -36,30 +36,31 @@ var (
)

func main() {
klog.InitFlags(nil)
flag.Parse()
defer glog.Flush()
defer klog.Flush()

dialOpts, err := rpcflags.NewClientDialOptionsFromFlags()
if err != nil {
glog.Exitf("Failed to determine dial options: %v", err)
klog.Exitf("Failed to determine dial options: %v", err)
}

conn, err := grpc.Dial(*adminServerAddr, dialOpts...)
if err != nil {
glog.Exitf("Failed to dial %v: %v", *adminServerAddr, err)
klog.Exitf("Failed to dial %v: %v", *adminServerAddr, err)
}
defer conn.Close()

a := trillian.NewTrillianAdminClient(conn)
if !*undeleteTree {
_, err = a.DeleteTree(context.Background(), &trillian.DeleteTreeRequest{TreeId: *logID})
if err != nil {
glog.Exitf("Delete failed: %v", err)
klog.Exitf("Delete failed: %v", err)
}
} else {
_, err = a.UndeleteTree(context.Background(), &trillian.UndeleteTreeRequest{TreeId: *logID})
if err != nil {
glog.Exitf("Undelete failed: %v", err)
klog.Exitf("Undelete failed: %v", err)
}
}
}
2 changes: 1 addition & 1 deletion cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"os"
"testing"

_ "github.com/golang/glog"
_ "k8s.io/klog/v2"
)

func TestParseFlags(t *testing.T) {
Expand Down
36 changes: 18 additions & 18 deletions cmd/internal/serverutil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/http"
"time"

"github.com/golang/glog"
"github.com/google/trillian"
"github.com/google/trillian/extension"
"github.com/google/trillian/monitoring"
Expand All @@ -36,6 +35,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/reflection"
"k8s.io/klog/v2"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -107,15 +107,15 @@ func (m *Main) healthz(rw http.ResponseWriter, req *http.Request) {

// Run starts the configured server. Blocks until the server exits.
func (m *Main) Run(ctx context.Context) error {
glog.CopyStandardLogTo("WARNING")
klog.CopyStandardLogTo("WARNING")

if m.HealthyDeadline == 0 {
m.HealthyDeadline = 5 * time.Second
}

srv, err := m.newGRPCServer()
if err != nil {
glog.Exitf("Error creating gRPC server: %v", err)
klog.Exitf("Error creating gRPC server: %v", err)
}
defer srv.GracefulStop()

Expand All @@ -138,7 +138,7 @@ func (m *Main) Run(ctx context.Context) error {
}

run := func() error {
glog.Infof("HTTP server starting on %v", endpoint)
klog.Infof("HTTP server starting on %v", endpoint)

var err error
// Let http.ListenAndServeTLS handle the error case when only one of the flags is set.
Expand All @@ -160,15 +160,15 @@ func (m *Main) Run(ctx context.Context) error {
}

shutdown := func() {
glog.Infof("Stopping HTTP server...")
glog.Flush()
klog.Infof("Stopping HTTP server...")
klog.Flush()

// 15 second exit time limit
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

if err := s.Shutdown(ctx); err != nil {
glog.Errorf("Failed to http server shutdown: %v", err)
klog.Errorf("Failed to http server shutdown: %v", err)
}
}

Expand All @@ -177,15 +177,15 @@ func (m *Main) Run(ctx context.Context) error {
})
}

glog.Infof("RPC server starting on %v", m.RPCEndpoint)
klog.Infof("RPC server starting on %v", m.RPCEndpoint)
lis, err := net.Listen("tcp", m.RPCEndpoint)
if err != nil {
return err
}

if m.TreeGCEnabled {
g.Go(func() error {
glog.Info("Deleted tree GC started")
klog.Info("Deleted tree GC started")
gc := admin.NewDeletedTreeGC(
m.Registry.AdminStorage,
m.TreeDeleteThreshold,
Expand All @@ -205,8 +205,8 @@ func (m *Main) Run(ctx context.Context) error {
}

shutdown := func() {
glog.Infof("Stopping RPC server...")
glog.Flush()
klog.Infof("Stopping RPC server...")
klog.Flush()

srv.GracefulStop()
}
Expand Down Expand Up @@ -264,26 +264,26 @@ func AnnounceSelf(ctx context.Context, client *clientv3.Client, etcdService, end
// Get a lease so our entry self-destructs.
leaseRsp, err := client.Grant(ctx, 30)
if err != nil {
glog.Exitf("Failed to get lease from etcd: %v", err)
klog.Exitf("Failed to get lease from etcd: %v", err)
}

keepAliveRspCh, err := client.KeepAlive(ctx, leaseRsp.ID)
if err != nil {
glog.Exitf("Failed to keep lease alive from etcd: %v", err)
klog.Exitf("Failed to keep lease alive from etcd: %v", err)
}
go listenKeepAliveRsp(ctx, keepAliveRspCh, cancel)

em, err := endpoints.NewManager(client, etcdService)
if err != nil {
glog.Exitf("Failed to create etcd manager: %v", err)
klog.Exitf("Failed to create etcd manager: %v", err)
}
fullEndpoint := fmt.Sprintf("%s/%s", etcdService, endpoint)
em.AddEndpoint(ctx, fullEndpoint, endpoints.Endpoint{Addr: endpoint})
glog.Infof("Announcing our presence in %v", etcdService)
klog.Infof("Announcing our presence in %v", etcdService)

return func() {
// Use a background context because the original context may have been cancelled.
glog.Infof("Removing our presence in %v", etcdService)
klog.Infof("Removing our presence in %v", etcdService)
ctx := context.Background()
em.DeleteEndpoint(ctx, fullEndpoint)
client.Revoke(ctx, leaseRsp.ID)
Expand All @@ -296,11 +296,11 @@ func listenKeepAliveRsp(ctx context.Context, keepAliveRspCh <-chan *clientv3.Lea
for {
select {
case <-ctx.Done():
glog.Infof("listenKeepAliveRsp canceled: %v", ctx.Err())
klog.Infof("listenKeepAliveRsp canceled: %v", ctx.Err())
return
case _, ok := <-keepAliveRspCh:
if !ok {
glog.Errorf("listenKeepAliveRsp canceled: unexpected lease expired")
klog.Errorf("listenKeepAliveRsp canceled: unexpected lease expired")
cancel()
return
}
Expand Down
Loading