-
Notifications
You must be signed in to change notification settings - Fork 437
/
metrics.go
37 lines (28 loc) · 1016 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package kube
import (
k8sleaderelection "k8s.io/client-go/tools/leaderelection"
k8smetrics "k8s.io/component-base/metrics"
)
var _ k8sleaderelection.MetricsProvider = new(prometheusMetricsProvider)
var (
leaderGauge = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
Name: "leader_election_leader_status",
Help: "Gauge of if the reporting system is owner of the relevant lease, 0 indicates candidate, 1 indicates leader. 'name' is the string used to identify the lease. Please make sure to group by name.",
}, []string{"name"})
)
func init() {
k8sleaderelection.SetProvider(prometheusMetricsProvider{})
}
type prometheusMetricsProvider struct{}
func (prometheusMetricsProvider) NewLeaderMetric() k8sleaderelection.SwitchMetric {
return &switchAdapter{gauge: leaderGauge}
}
type switchAdapter struct {
gauge *k8smetrics.GaugeVec
}
func (s *switchAdapter) On(name string) {
s.gauge.WithLabelValues(name).Set(1.0)
}
func (s *switchAdapter) Off(name string) {
s.gauge.WithLabelValues(name).Set(0.0)
}