Add promehteus metric about leader election status

This commit is contained in:
Manuel Alejandro de Brito Fontes 2019-03-10 19:12:33 -03:00
parent 476d0106d6
commit 7c717cabcf
No known key found for this signature in database
GPG key ID: 786136016A8BA02A
4 changed files with 42 additions and 0 deletions

View file

@ -46,6 +46,8 @@ type Controller struct {
constLabels prometheus.Labels
labels prometheus.Labels
leaderElection *prometheus.GaugeVec
}
// NewController creates a new prometheus collector for the
@ -112,6 +114,13 @@ func NewController(pod, namespace, class string) *Controller {
},
sslLabelHost,
),
leaderElection: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "leader_election_status",
Help: "Gauge reporting status of the leader election, 0 indicates follower, 1 indicates leader. 'name' is the string used to identify the lease",
},
[]string{"name"},
),
}
return cm
@ -127,6 +136,16 @@ func (cm *Controller) IncReloadErrorCount() {
cm.reloadOperationErrors.With(cm.constLabels).Inc()
}
// OnStartedLeading indicates the pod is not the current leader
func (cm *Controller) OnStartedLeading(electionID string) {
cm.leaderElection.WithLabelValues(electionID).Set(0)
}
// OnStoppedLeading indicates the pod is not the current leader
func (cm *Controller) OnStoppedLeading(electionID string) {
cm.leaderElection.WithLabelValues(electionID).Set(1.0)
}
// ConfigSuccess set a boolean flag according to the output of the controller configuration reload
func (cm *Controller) ConfigSuccess(hash uint64, success bool) {
if success {