Skip to content

Commit

Permalink
When the pod is leader, is_leader is true, and its value becomes 1. O…
Browse files Browse the repository at this point in the history
…therwise, is_leader is false, and the value is 0.
  • Loading branch information
keisku committed Dec 27, 2024
1 parent 701ea4a commit 7794eac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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},
)
}

0 comments on commit 7794eac

Please sign in to comment.