mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Rework 'running_managed_controllers' metric interface
This commit is contained in:
parent
e7845861a5
commit
d6db6443b4
@ -24,17 +24,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
)
|
controllerInstanceCount = k8smetrics.NewGaugeVec(
|
||||||
|
|
||||||
// ControllerMetrics includes all the metrics of the proxy server.
|
|
||||||
type ControllerMetrics struct {
|
|
||||||
controllerInstanceCount *k8smetrics.GaugeVec
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewControllerMetrics create a new ControllerMetrics, configured with default metric names.
|
|
||||||
func NewControllerMetrics() *ControllerMetrics {
|
|
||||||
controllerInstanceCount := k8smetrics.NewGaugeVec(
|
|
||||||
&k8smetrics.GaugeOpts{
|
&k8smetrics.GaugeOpts{
|
||||||
Name: "running_managed_controllers",
|
Name: "running_managed_controllers",
|
||||||
Help: "Indicates where instances of a controller are currently running",
|
Help: "Indicates where instances of a controller are currently running",
|
||||||
@ -42,27 +33,36 @@ func NewControllerMetrics() *ControllerMetrics {
|
|||||||
},
|
},
|
||||||
[]string{"name", "manager"},
|
[]string{"name", "manager"},
|
||||||
)
|
)
|
||||||
controllerMetrics := &ControllerMetrics{
|
)
|
||||||
controllerInstanceCount: controllerInstanceCount,
|
|
||||||
|
// ControllerManagerMetrics is a proxy to set controller manager specific metrics.
|
||||||
|
type ControllerManagerMetrics struct {
|
||||||
|
manager string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewControllerManagerMetrics create a new ControllerManagerMetrics, with specific manager name.
|
||||||
|
func NewControllerManagerMetrics(manager string) *ControllerManagerMetrics {
|
||||||
|
controllerMetrics := &ControllerManagerMetrics{
|
||||||
|
manager: manager,
|
||||||
}
|
}
|
||||||
once.Do(func() {
|
|
||||||
controllerMetrics.Register()
|
|
||||||
})
|
|
||||||
return controllerMetrics
|
return controllerMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ControllerMetrics) Register() {
|
// Register controller manager metrics.
|
||||||
legacyregistry.MustRegister(a.controllerInstanceCount)
|
func Register() {
|
||||||
|
once.Do(func() {
|
||||||
|
legacyregistry.MustRegister(controllerInstanceCount)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerStarted sets the controllerInstanceCount to 1.
|
// ControllerStarted sets the controllerInstanceCount to 1.
|
||||||
// These values use set instead of inc/dec to avoid accidentally double counting
|
// These values use set instead of inc/dec to avoid accidentally double counting
|
||||||
// a controller that starts but fails to properly signal when it crashes.
|
// a controller that starts but fails to properly signal when it crashes.
|
||||||
func (a *ControllerMetrics) ControllerStarted(name string, manager string) {
|
func (a *ControllerManagerMetrics) ControllerStarted(name string) {
|
||||||
a.controllerInstanceCount.With(k8smetrics.Labels{"name": name, "manager": manager}).Set(float64(1))
|
controllerInstanceCount.With(k8smetrics.Labels{"name": name, "manager": a.manager}).Set(float64(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerStopped sets the controllerInstanceCount to 0.
|
// ControllerStopped sets the controllerInstanceCount to 0.
|
||||||
func (a *ControllerMetrics) ControllerStopped(name string, manager string) {
|
func (a *ControllerManagerMetrics) ControllerStopped(name string) {
|
||||||
a.controllerInstanceCount.With(k8smetrics.Labels{"name": name, "manager": manager}).Set(float64(0))
|
controllerInstanceCount.With(k8smetrics.Labels{"name": name, "manager": a.manager}).Set(float64(0))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user