mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-29 09:40:22 +00:00
c1ee11261e
Bumps the k8s-dependencies group with 1 update in the / directory: [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime). Updates `sigs.k8s.io/controller-runtime` from 0.17.3 to 0.18.2 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes-sigs/controller-runtime/compare/v0.17.3...v0.18.2) --- updated-dependencies: - dependency-name: sigs.k8s.io/controller-runtime dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"k8s.io/client-go/tools/leaderelection"
|
|
)
|
|
|
|
// This file is copied and adapted from k8s.io/component-base/metrics/prometheus/clientgo/leaderelection
|
|
// which registers metrics to the k8s legacy Registry. We require very
|
|
// similar functionality, but must register metrics to a different Registry.
|
|
|
|
var (
|
|
leaderGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Name: "leader_election_master_status",
|
|
Help: "Gauge of if the reporting system is master of the relevant lease, 0 indicates backup, 1 indicates master. 'name' is the string used to identify the lease. Please make sure to group by name.",
|
|
}, []string{"name"})
|
|
|
|
leaderSlowpathCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "leader_election_slowpath_total",
|
|
Help: "Total number of slow path exercised in renewing leader leases. 'name' is the string used to identify the lease. Please make sure to group by name.",
|
|
}, []string{"name"})
|
|
)
|
|
|
|
func init() {
|
|
Registry.MustRegister(leaderGauge)
|
|
leaderelection.SetProvider(leaderelectionMetricsProvider{})
|
|
}
|
|
|
|
type leaderelectionMetricsProvider struct{}
|
|
|
|
func (leaderelectionMetricsProvider) NewLeaderMetric() leaderelection.LeaderMetric {
|
|
return leaderElectionPrometheusAdapter{}
|
|
}
|
|
|
|
type leaderElectionPrometheusAdapter struct{}
|
|
|
|
func (s leaderElectionPrometheusAdapter) On(name string) {
|
|
leaderGauge.WithLabelValues(name).Set(1.0)
|
|
}
|
|
|
|
func (s leaderElectionPrometheusAdapter) Off(name string) {
|
|
leaderGauge.WithLabelValues(name).Set(0.0)
|
|
}
|
|
|
|
func (leaderElectionPrometheusAdapter) SlowpathExercised(name string) {
|
|
leaderSlowpathCounter.WithLabelValues(name).Inc()
|
|
}
|