From 2d12115714a9bd6acde2ab59e2cdfd727d7e5920 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 19 Aug 2020 18:18:05 +0800 Subject: [PATCH 1/2] refine log in metricutil/etcdutil Signed-off-by: Ryan Leung --- go.mod | 4 +--- go.sum | 2 ++ pkg/errs/errno.go | 11 +++++++++++ pkg/etcdutil/etcdutil.go | 7 ++++--- pkg/metricutil/metricutil.go | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index e71190f4eee..352d630948d 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200807020752-01f0abe88e93 github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12 github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9 - github.com/pingcap/errors v0.11.5-0.20200729012136-4e113ddee29e + github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d github.com/pingcap/kvproto v0.0.0-20200810113304-6157337686b1 github.com/pingcap/log v0.0.0-20200511115504-543df19646ad @@ -54,5 +54,3 @@ require ( ) replace go.etcd.io/bbolt => go.etcd.io/bbolt v1.3.5 - -replace github.com/pingcap/errors => github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff diff --git a/go.sum b/go.sum index b4bdfbb351e..506184baf4b 100644 --- a/go.sum +++ b/go.sum @@ -284,6 +284,8 @@ github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12 h1:rfD9v3+ppLPzoQBgZ github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12/go.mod h1:PYMCGwN0JHjoqGr3HrZoD+b8Tgx8bKnArhSq8YVzUMc= github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9 h1:KH4f4Si9XK6/IW50HtoaiLIFHGkapOM6w83za47UYik= github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9/go.mod h1:4b2X8xSqxIroj/IZ9MX/VGZhAwc11wB9wRIzHvz6SeM= +github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff h1:5MCSOM1ydTR9tXY2IrdWODUrnDdSjb1yluNHDO1sVN4= github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ= github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d h1:F8vp38kTAckN+v8Jlc98uMBvKIzr1a+UhnLyVYn8Q5Q= diff --git a/pkg/errs/errno.go b/pkg/errs/errno.go index abebcb42f98..ac69582e17e 100644 --- a/pkg/errs/errno.go +++ b/pkg/errs/errno.go @@ -69,3 +69,14 @@ var ( ErrReadHTTPBody = errors.Normalize("read HTTP body failed", errors.RFCCodeText("PD:apiutil:ErrReadHTTPBody")) ErrWriteHTTPBody = errors.Normalize("write HTTP body failed", errors.RFCCodeText("PD:apiutil:ErrWriteHTTPBody")) ) + +// metricutil errors +var ( + ErrPushGateway = errors.Normalize("push metrics to gateway failed", errors.RFCCodeText("PD:metricutil:ErrPushGateway")) +) + +// etcdutil errors +var ( + ErrLoadValue = errors.Normalize("load value from etcd failed", errors.RFCCodeText("PD:etcdutil:ErrLoadValue")) + ErrGetCluster = errors.Normalize("get cluster from remote peer failed", errors.RFCCodeText("PD:etcdutil:ErrGetCluster")) +) diff --git a/pkg/etcdutil/etcdutil.go b/pkg/etcdutil/etcdutil.go index 6c7d9991c20..94b7c18efcb 100644 --- a/pkg/etcdutil/etcdutil.go +++ b/pkg/etcdutil/etcdutil.go @@ -20,8 +20,9 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/pkg/errors" + "github.com/tikv/pd/pkg/errs" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/etcdserver" "go.etcd.io/etcd/pkg/types" @@ -61,7 +62,7 @@ func CheckClusterID(localClusterID types.ID, um types.URLsMap, tlsConfig *tls.Co trp.CloseIdleConnections() if gerr != nil { // Do not return error, because other members may be not ready. - log.Error("failed to get cluster from remote", zap.Error(gerr)) + log.Error("failed to get cluster from remote", errs.ZapError(errs.ErrGetCluster, gerr)) continue } @@ -105,7 +106,7 @@ func EtcdKVGet(c *clientv3.Client, key string, opts ...clientv3.OpOption) (*clie start := time.Now() resp, err := clientv3.NewKV(c).Get(ctx, key, opts...) if err != nil { - log.Error("load from etcd meet error", zap.Error(err)) + log.Error("load from etcd meet error", errs.ZapError(errs.ErrLoadValue, err)) } if cost := time.Since(start); cost > DefaultSlowRequestTime { log.Warn("kv gets too slow", zap.String("request-key", key), zap.Duration("cost", cost), zap.Error(err)) diff --git a/pkg/metricutil/metricutil.go b/pkg/metricutil/metricutil.go index 64e7db47a4b..a1e5d8e7846 100644 --- a/pkg/metricutil/metricutil.go +++ b/pkg/metricutil/metricutil.go @@ -21,8 +21,8 @@ import ( "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/push" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/typeutil" - "go.uber.org/zap" ) const zeroDuration = time.Duration(0) @@ -68,7 +68,7 @@ func prometheusPushClient(job, addr string, interval time.Duration) { for { err := pusher.Push() if err != nil { - log.Error("could not push metrics to Prometheus Pushgateway", zap.Error(err)) + log.Error("could not push metrics to Prometheus Pushgateway", errs.ZapError(errs.ErrPushGateway, err)) } time.Sleep(interval) From 62c131e027ef4dd1ad816b4654870fbc00d6fe92 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 20 Aug 2020 12:05:26 +0800 Subject: [PATCH 2/2] update errors dependency Signed-off-by: Ryan Leung --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 352d630948d..63d84908ea0 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200807020752-01f0abe88e93 github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12 github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9 - github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff + github.com/pingcap/errors v0.11.5-0.20200820035142-66eb5bf1d1cd github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d github.com/pingcap/kvproto v0.0.0-20200810113304-6157337686b1 github.com/pingcap/log v0.0.0-20200511115504-543df19646ad diff --git a/go.sum b/go.sum index 506184baf4b..aff20f6e712 100644 --- a/go.sum +++ b/go.sum @@ -286,8 +286,8 @@ github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9 h1:KH4f4Si9XK6/IW5 github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9/go.mod h1:4b2X8xSqxIroj/IZ9MX/VGZhAwc11wB9wRIzHvz6SeM= github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff h1:5MCSOM1ydTR9tXY2IrdWODUrnDdSjb1yluNHDO1sVN4= -github.com/pingcap/errors v0.11.5-0.20200812093836-57ec461934ff/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ= +github.com/pingcap/errors v0.11.5-0.20200820035142-66eb5bf1d1cd h1:ay+wAVWHI/Z6vIik13hsK+FT9ZCNSPBElGr0qgiZpjg= +github.com/pingcap/errors v0.11.5-0.20200820035142-66eb5bf1d1cd/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ= github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d h1:F8vp38kTAckN+v8Jlc98uMBvKIzr1a+UhnLyVYn8Q5Q= github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI= github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=