Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Leader Election metrics #32511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package leaderelection
import (
"context"
"encoding/json"
"strconv"

coordv1 "k8s.io/api/coordination/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -217,7 +216,11 @@ func (le *LeaderEngine) reportLeaderMetric(isLeader bool) {
le.leaderMetric.Delete(metrics.JoinLeaderValue, "false")
le.leaderMetric.Delete(metrics.JoinLeaderValue, "true")

le.leaderMetric.Set(1.0, metrics.JoinLeaderValue, strconv.FormatBool(isLeader))
if isLeader {
le.leaderMetric.Set(1.0, metrics.JoinLeaderValue, "true")
} else {
le.leaderMetric.Set(0, metrics.JoinLeaderValue, "false")
}
}

// notify sends a notification to subscribers when the leadership state of the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewLeaderMetric() telemetry.Gauge {
"leader_election",
"is_leader",
[]string{JoinLeaderLabel, isLeaderLabel}, // join_leader is for label joins
"The label is_leader is true if the reporting pod is leader, equals false otherwise.",
"When the pod is leader, is_leader is true, and its value becomes 1. Otherwise, is_leader is false, and the value is 0.",
telemetry.Options{NoDoubleUnderscoreSep: true},
)
}
Loading