From 805bcc828c45a8a8cbabf47e0059b46bddb31ebc Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 27 Nov 2017 13:42:20 -0800 Subject: [PATCH] clientv3: simplify V(4) logger with Lvl(4) Signed-off-by: Gyu-Ho Lee --- clientv3/health_balancer.go | 36 +++++++++--------------------------- clientv3/retry.go | 16 ++++------------ 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/clientv3/health_balancer.go b/clientv3/health_balancer.go index 41fba4790..5918cba84 100644 --- a/clientv3/health_balancer.go +++ b/clientv3/health_balancer.go @@ -158,34 +158,26 @@ func (b *healthBalancer) pinned() string { func (b *healthBalancer) hostPortError(hostPort string, err error) { if b.endpoint(hostPort) == "" { - if logger.V(4) { - logger.Infof("clientv3/balancer: %q is stale (skip marking as unhealthy on %q)", hostPort, err.Error()) - } + logger.Lvl(4).Infof("clientv3/balancer: %q is stale (skip marking as unhealthy on %q)", hostPort, err.Error()) return } b.unhealthyMu.Lock() b.unhealthyHostPorts[hostPort] = time.Now() b.unhealthyMu.Unlock() - if logger.V(4) { - logger.Infof("clientv3/balancer: %q is marked unhealthy (%q)", hostPort, err.Error()) - } + logger.Lvl(4).Infof("clientv3/balancer: %q is marked unhealthy (%q)", hostPort, err.Error()) } func (b *healthBalancer) removeUnhealthy(hostPort, msg string) { if b.endpoint(hostPort) == "" { - if logger.V(4) { - logger.Infof("clientv3/balancer: %q was not in unhealthy (%q)", hostPort, msg) - } + logger.Lvl(4).Infof("clientv3/balancer: %q was not in unhealthy (%q)", hostPort, msg) return } b.unhealthyMu.Lock() delete(b.unhealthyHostPorts, hostPort) b.unhealthyMu.Unlock() - if logger.V(4) { - logger.Infof("clientv3/balancer: %q is removed from unhealthy (%q)", hostPort, msg) - } + logger.Lvl(4).Infof("clientv3/balancer: %q is removed from unhealthy (%q)", hostPort, msg) } func (b *healthBalancer) countUnhealthy() (count int) { @@ -207,9 +199,7 @@ func (b *healthBalancer) cleanupUnhealthy() { for k, v := range b.unhealthyHostPorts { if time.Since(v) > b.healthCheckTimeout { delete(b.unhealthyHostPorts, k) - if logger.V(4) { - logger.Infof("clientv3/balancer: removed %q from unhealthy after %v", k, b.healthCheckTimeout) - } + logger.Lvl(4).Infof("clientv3/balancer: removed %q from unhealthy after %v", k, b.healthCheckTimeout) } } b.unhealthyMu.Unlock() @@ -412,9 +402,7 @@ func (b *healthBalancer) Up(addr grpc.Address) func(error) { } if b.pinAddr != "" { - if logger.V(4) { - logger.Infof("clientv3/balancer: %q is up but not pinned (already pinned %q)", addr.Addr, b.pinAddr) - } + logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (already pinned %q)", addr.Addr, b.pinAddr) return func(err error) {} } @@ -422,9 +410,7 @@ func (b *healthBalancer) Up(addr grpc.Address) func(error) { close(b.upc) b.downc = make(chan struct{}) b.pinAddr = addr.Addr - if logger.V(4) { - logger.Infof("clientv3/balancer: pin %q", addr.Addr) - } + logger.Lvl(4).Infof("clientv3/balancer: pin %q", addr.Addr) // notify client that a connection is up b.readyOnce.Do(func() { close(b.readyc) }) @@ -441,9 +427,7 @@ func (b *healthBalancer) Up(addr grpc.Address) func(error) { close(b.downc) b.pinAddr = "" b.mu.Unlock() - if logger.V(4) { - logger.Infof("clientv3/balancer: unpin %q (%q)", addr.Addr, err.Error()) - } + logger.Lvl(4).Infof("clientv3/balancer: unpin %q (%q)", addr.Addr, err.Error()) } } @@ -470,9 +454,7 @@ func (b *healthBalancer) mayPin(addr grpc.Address) bool { // 3. grpc-healthcheck still SERVING, thus retry to pin // instead, return before grpc-healthcheck if failed within healthcheck timeout if elapsed := time.Since(failedTime); elapsed < b.healthCheckTimeout { - if logger.V(4) { - logger.Infof("clientv3/balancer: %q is up but not pinned (failed %v ago, require minimum %v after failure)", addr.Addr, elapsed, b.healthCheckTimeout) - } + logger.Lvl(4).Infof("clientv3/balancer: %q is up but not pinned (failed %v ago, require minimum %v after failure)", addr.Addr, elapsed, b.healthCheckTimeout) return false } diff --git a/clientv3/retry.go b/clientv3/retry.go index 5ad66ebfe..5ad815d74 100644 --- a/clientv3/retry.go +++ b/clientv3/retry.go @@ -60,17 +60,13 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRPCFunc { if err == nil { return nil } - if logger.V(4) { - logger.Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned) - } + logger.Lvl(4).Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned) if s, ok := status.FromError(err); ok && (s.Code() == codes.Unavailable || s.Code() == codes.DeadlineExceeded || s.Code() == codes.Internal) { // mark this before endpoint switch is triggered c.balancer.hostPortError(pinned, err) c.balancer.next() - if logger.V(4) { - logger.Infof("clientv3/retry: switching from %q due to error %q", pinned, err.Error()) - } + logger.Lvl(4).Infof("clientv3/retry: switching from %q due to error %q", pinned, err.Error()) } if isStop(err) { @@ -88,16 +84,12 @@ func (c *Client) newAuthRetryWrapper() retryRPCFunc { if err == nil { return nil } - if logger.V(4) { - logger.Infof("clientv3/auth-retry: error %q on pinned endpoint %q", err.Error(), pinned) - } + logger.Lvl(4).Infof("clientv3/auth-retry: error %q on pinned endpoint %q", err.Error(), pinned) // always stop retry on etcd errors other than invalid auth token if rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken { gterr := c.getToken(rpcCtx) if gterr != nil { - if logger.V(4) { - logger.Infof("clientv3/auth-retry: cannot retry due to error %q(%q) on pinned endpoint %q", err.Error(), gterr.Error(), pinned) - } + logger.Lvl(4).Infof("clientv3/auth-retry: cannot retry due to error %q(%q) on pinned endpoint %q", err.Error(), gterr.Error(), pinned) return err // return the original error for simplicity } continue