diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 1feb8bc379d5..70ad75e4d6a6 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -335,6 +335,7 @@ func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) { firstCommitInTerm: notify.NewNotifier(), clusterVersionChanged: notify.NewNotifier(), } + srv.buildLearnerMetric() serverID.With(prometheus.Labels{"server_id": b.cluster.nodeID.String()}).Set(1) srv.cluster.SetVersionChangedNotifier(srv.clusterVersionChanged) @@ -1085,6 +1086,8 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, toApply *toApply) { s.cluster.Recover(api.UpdateCapability) + s.buildLearnerMetric() + lg.Info("restored cluster configuration") lg.Info("removing old peers from network") @@ -2465,3 +2468,16 @@ func (s *EtcdServer) getTxPostLockInsideApplyHook() func() { func (s *EtcdServer) CorruptionChecker() CorruptionChecker { return s.corruptionChecker } + +func (s *EtcdServer) buildLearnerMetric() { + for _, m := range s.cluster.Members() { + if m.ID == s.MemberId() { + if m.IsLearner { + isLearner.Set(1) + } else { + isLearner.Set(0) + } + break + } + } +}