From 819a554a4b3d1e5b72835c7fcf6b3859d07e8d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E6=85=95?= Date: Thu, 16 May 2019 12:23:45 +0800 Subject: [PATCH] etcdserver: add learner metrics --- docs/metrics/latest | 15 +++++++++++++++ etcdserver/metrics.go | 14 ++++++++++++++ etcdserver/server.go | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/docs/metrics/latest b/docs/metrics/latest index db3017c51059..a82e6afee909 100644 --- a/docs/metrics/latest +++ b/docs/metrics/latest @@ -533,6 +533,21 @@ etcd_server_is_leader # type: "counter" etcd_server_leader_changes_seen_total +# name: "etcd_server_is_learner" +# description: "Whether or not this member is a learner. 1 if is, 0 otherwise." +# type: "gauge" +etcd_server_is_learner + +# name: "etcd_server_learner_promote_failures" +# description: "The total number of learner promote failures (likely learner not ready)." +# type: "counter" +etcd_server_learner_promote_failures + +# name: "etcd_server_learner_promote_successes" +# description: "The total number of successful learner promotions." +# type: "counter" +etcd_server_learner_promote_successes + # name: "etcd_server_proposals_applied_total" # description: "The total number of consensus proposals applied." # type: "gauge" diff --git a/etcdserver/metrics.go b/etcdserver/metrics.go index 748e7edb5da7..595d169ac2cb 100644 --- a/etcdserver/metrics.go +++ b/etcdserver/metrics.go @@ -44,6 +44,20 @@ var ( Name: "leader_changes_seen_total", Help: "The number of leader changes seen.", }) + learnerPromoteFailed = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: "etcd", + Subsystem: "server", + Name: "learner_promote_failures", + Help: "The total number of learner promote failures (likely learner not ready).", + }, + []string{"Reason"}, + ) + learnerPromoteSucceed = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "etcd", + Subsystem: "server", + Name: "learner_promote_successes", + Help: "The total number of successful learner promotions.", + }) heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "etcd", Subsystem: "server", diff --git a/etcdserver/server.go b/etcdserver/server.go index 722922eeff2d..602e3d7dddcc 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -1646,7 +1646,11 @@ func (s *EtcdServer) PromoteMember(ctx context.Context, id uint64) ([]*membershi // fails with ErrNotLeader, forward the request to leader node via HTTP. If promoteMember call fails with error // other than ErrNotLeader, return the error. resp, err := s.promoteMember(ctx, id) + if err == nil { + learnerPromoteSuceed.Inc() + } if err != ErrNotLeader { + learnerPromoteFailed.WithLabelValues(err.Error()).Inc() return resp, err }