Skip to content

Commit 33cab8f

Browse files
authored
rebuild metric for current status phase (#1058)
1 parent c411423 commit 33cab8f

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pkg/util/provider/machinecontroller/metrics.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
// Describe is method required to implement the prometheus.Collect interface.
2020
func (c *controller) Describe(ch chan<- *prometheus.Desc) {
2121
ch <- metrics.MachineCountDesc
22+
ch <- metrics.MachineCSPhase
2223
}
2324

2425
// Collect is method required to implement the prometheus.Collect interface.
@@ -41,7 +42,7 @@ func (c *controller) CollectMachineMetrics(ch chan<- prometheus.Metric) {
4142
mSpec := machine.Spec
4243
updateMachineInfoMetric(mMeta, mSpec)
4344
updateMachineStatusConditionMetric(machine, mMeta)
44-
updateMachineCSPhaseMetric(machine, mMeta)
45+
updateMachineCSPhaseMetric(machine, mMeta, ch)
4546
}
4647

4748
updateMachineCountMetric(ch, machineList)
@@ -70,7 +71,7 @@ func updateMachineCountMetric(ch chan<- prometheus.Metric, machineList []*v1alph
7071
ch <- metric
7172
}
7273

73-
func updateMachineCSPhaseMetric(machine *v1alpha1.Machine, mMeta metav1.ObjectMeta) {
74+
func updateMachineCSPhaseMetric(machine *v1alpha1.Machine, mMeta metav1.ObjectMeta, ch chan<- prometheus.Metric) {
7475
var phase float64
7576
switch machine.Status.CurrentStatus.Phase {
7677
case v1alpha1.MachineTerminating:
@@ -86,10 +87,14 @@ func updateMachineCSPhaseMetric(machine *v1alpha1.Machine, mMeta metav1.ObjectMe
8687
case v1alpha1.MachineRunning:
8788
phase = 1
8889
}
89-
metrics.MachineCSPhase.With(prometheus.Labels{
90-
"name": mMeta.Name,
91-
"namespace": mMeta.Namespace,
92-
}).Set(phase)
90+
91+
ch <- prometheus.MustNewConstMetric(
92+
metrics.MachineCSPhase,
93+
prometheus.GaugeValue,
94+
phase,
95+
mMeta.Name,
96+
mMeta.Namespace,
97+
)
9398
}
9499

95100
func updateMachineStatusConditionMetric(machine *v1alpha1.Machine, mMeta metav1.ObjectMeta) {

pkg/util/provider/metrics/metrics.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ var (
2424
MachineCountDesc = prometheus.NewDesc("mcm_machine_items_total", "Count of machines currently managed by the mcm.", nil, nil)
2525

2626
// MachineCSPhase Current status phase of the Machines currently managed by the mcm.
27-
MachineCSPhase = prometheus.NewGaugeVec(prometheus.GaugeOpts{
28-
Namespace: namespace,
29-
Subsystem: machineSubsystem,
30-
Name: "current_status_phase",
31-
Help: "Current status phase of the Machines currently managed by the mcm.",
32-
}, []string{"name", "namespace"})
27+
MachineCSPhase = prometheus.NewDesc(
28+
prometheus.BuildFQName(namespace, machineSubsystem, "current_status_phase"),
29+
"Current status phase of the Machines currently managed by the mcm.",
30+
[]string{"name", "namespace"},
31+
nil)
3332

3433
// MachineInfo Information of the Machines currently managed by the mcm.
3534
MachineInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -112,7 +111,6 @@ var (
112111
func registerMachineSubsystemMetrics() {
113112
prometheus.MustRegister(MachineInfo)
114113
prometheus.MustRegister(MachineStatusCondition)
115-
prometheus.MustRegister(MachineCSPhase)
116114
}
117115

118116
func registerCloudAPISubsystemMetrics() {

0 commit comments

Comments
 (0)