Skip to content

Commit

Permalink
server: fix learner metric incorrect issue
Browse files Browse the repository at this point in the history
Signed-off-by: YaoC <chengyao09@hotmail.com>
  • Loading branch information
YaoC committed Dec 29, 2023
1 parent 2eb0e2d commit 82aca90
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
}
}
}

0 comments on commit 82aca90

Please sign in to comment.