Set replication metric to 0 when losing leadership (#20665)

* Set replication metric to 0 when losing leadership

* Fix replication metrics on replication.go also

---------

Co-authored-by: sarahalsmiller <100602640+sarahalsmiller@users.noreply.github.com>
This commit is contained in:
Jorge Marey 2024-08-29 18:51:44 +02:00 committed by GitHub
parent ab794b59f8
commit d12f9cf4d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -771,6 +771,12 @@ func (s *Server) runACLReplicator(
index, exit, err := replicateFunc(ctx, logger, lastRemoteIndex) index, exit, err := replicateFunc(ctx, logger, lastRemoteIndex)
if exit { if exit {
metrics.SetGauge([]string{"leader", "replication", metricName, "status"},
0,
)
metrics.SetGauge([]string{"leader", "replication", metricName, "index"},
0,
)
return nil return nil
} }

View File

@ -153,6 +153,12 @@ func (r *Replicator) Run(ctx context.Context) error {
// Perform a single round of replication // Perform a single round of replication
index, exit, err := r.delegate.Replicate(ctx, atomic.LoadUint64(&r.lastRemoteIndex), r.logger) index, exit, err := r.delegate.Replicate(ctx, atomic.LoadUint64(&r.lastRemoteIndex), r.logger)
if exit { if exit {
metrics.SetGauge([]string{"leader", "replication", r.delegate.MetricName(), "status"},
0,
)
metrics.SetGauge([]string{"leader", "replication", r.delegate.MetricName(), "index"},
0,
)
return nil return nil
} }
if err != nil { if err != nil {