From a9f5c36a68cf0ccb5c756c9f851d79c57823f644 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Wed, 26 May 2021 18:32:49 +0100 Subject: [PATCH] Minor logging changes to coordination packages --- coordination/election/election.go | 4 ++++ coordination/watcher/watcher.go | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/coordination/election/election.go b/coordination/election/election.go index 6578702a..b1e7d255 100644 --- a/coordination/election/election.go +++ b/coordination/election/election.go @@ -52,6 +52,7 @@ func (s ElectionState) String() string { // Election manages (or witnesses) an election protocol on a given // database prefix. type Election struct { + path string session *concurrency.Session election *concurrency.Election self *pb.Endpoint @@ -63,6 +64,7 @@ type Election struct { func New(session *concurrency.Session, path string, self *pb.Endpoint) *Election { el := concurrency.NewElection(session, path) return &Election{ + path: path, session: session, election: el, self: self, @@ -120,10 +122,12 @@ func (e *Election) runOnce(ctx context.Context, data string, op Op) error { } // Invoke the leader operation. + log.Printf("we are now the leader for %s", e.path) err = op(ctx) // Resign, if the session is still valid. Use a standalone // Context to resign even on cancellation. + log.Printf("resigning leadership for %s", e.path) rctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) rerr := e.election.Resign(rctx) cancel() diff --git a/coordination/watcher/watcher.go b/coordination/watcher/watcher.go index bb347bbc..bc8deb4d 100644 --- a/coordination/watcher/watcher.go +++ b/coordination/watcher/watcher.go @@ -2,7 +2,6 @@ package watcher import ( "context" - "fmt" "log" "sync" "time" @@ -131,7 +130,6 @@ func watchOnce(ctx context.Context, cli *clientv3.Client, prefix string, target rch := cli.Watch(ctx, prefix, clientv3.WithPrefix(), clientv3.WithRev(rev)) for resp := range rch { for _, ev := range resp.Events { - fmt.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value) key := string(ev.Kv.Key)[plen:] switch ev.Type { case clientv3.EventTypePut: -- GitLab