Skip to content

Commit 2da9a30

Browse files
metrics: Report reason as a label on the conditions metric
Conditions are read by telemetry and the reason incentivizes teams to have good reasons on their operators. Should not increase cardinality significantly, but instead provide better insight.
1 parent edee0c5 commit 2da9a30

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/dev/metrics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Metrics about cluster operators:
3131
```
3232
# HELP cluster_operator_conditions Report the conditions for active cluster operators. 0 is False and 1 is True.
3333
# TYPE cluster_operator_conditions gauge
34-
cluster_operator_conditions{condition="Available",name="version",namespace="openshift-cluster-version"} 1
35-
cluster_operator_conditions{condition="Degraded",name="version",namespace="openshift-cluster-version"} 0
36-
cluster_operator_conditions{condition="Progressing",name="version",namespace="openshift-cluster-version"} 0
37-
cluster_operator_conditions{condition="RetrievedUpdates",name="version",namespace="openshift-cluster-version"} 0
34+
cluster_operator_conditions{condition="Available",name="version",namespace="openshift-cluster-version",reason="Happy"} 1
35+
cluster_operator_conditions{condition="Degraded",name="version",namespace="openshift-cluster-version",reason=""} 0
36+
cluster_operator_conditions{condition="Progressing",name="version",namespace="openshift-cluster-version",reason=""} 0
37+
cluster_operator_conditions{condition="RetrievedUpdates",name="version",namespace="openshift-cluster-version",reason=""} 0
3838
# HELP cluster_operator_up Reports key highlights of the active cluster operators.
3939
# TYPE cluster_operator_up gauge
4040
cluster_operator_up{name="version",namespace="openshift-cluster-version",version="4.0.1"} 1

pkg/cvo/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ started.
7070
clusterOperatorConditions: prometheus.NewGaugeVec(prometheus.GaugeOpts{
7171
Name: "cluster_operator_conditions",
7272
Help: "Report the conditions for active cluster operators. 0 is False and 1 is True.",
73-
}, []string{"name", "condition"}),
73+
}, []string{"name", "condition", "reason"}),
7474
clusterOperatorConditionTransitions: prometheus.NewGaugeVec(prometheus.GaugeOpts{
7575
Name: "cluster_operator_condition_transitions",
7676
Help: "Reports the number of times that a condition on a cluster operator changes status",
@@ -122,7 +122,7 @@ func (m *operatorMetrics) Describe(ch chan<- *prometheus.Desc) {
122122
ch <- m.version.WithLabelValues("", "", "").Desc()
123123
ch <- m.availableUpdates.WithLabelValues("", "").Desc()
124124
ch <- m.clusterOperatorUp.WithLabelValues("", "").Desc()
125-
ch <- m.clusterOperatorConditions.WithLabelValues("", "").Desc()
125+
ch <- m.clusterOperatorConditions.WithLabelValues("", "", "").Desc()
126126
ch <- m.clusterOperatorConditionTransitions.WithLabelValues("", "").Desc()
127127
}
128128

@@ -227,7 +227,7 @@ func (m *operatorMetrics) Collect(ch chan<- prometheus.Metric) {
227227
if condition.Status == configv1.ConditionUnknown {
228228
continue
229229
}
230-
g := m.clusterOperatorConditions.WithLabelValues(op.Name, string(condition.Type))
230+
g := m.clusterOperatorConditions.WithLabelValues(op.Name, string(condition.Type), string(condition.Reason))
231231
if condition.Status == configv1.ConditionTrue {
232232
g.Set(1)
233233
} else {

pkg/cvo/metrics_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func Test_operatorMetrics_Collect(t *testing.T) {
161161
Status: configv1.ClusterOperatorStatus{
162162
Conditions: []configv1.ClusterOperatorStatusCondition{
163163
{Type: configv1.OperatorAvailable, Status: configv1.ConditionTrue},
164-
{Type: configv1.ClusterStatusConditionType("Custom"), Status: configv1.ConditionFalse},
164+
{Type: configv1.ClusterStatusConditionType("Custom"), Status: configv1.ConditionFalse, Reason: "CustomReason"},
165165
{Type: configv1.ClusterStatusConditionType("Unknown"), Status: configv1.ConditionUnknown},
166166
},
167167
},
@@ -175,8 +175,8 @@ func Test_operatorMetrics_Collect(t *testing.T) {
175175
}
176176
expectMetric(t, metrics[0], 0, map[string]string{"type": "current", "version": "", "image": ""})
177177
expectMetric(t, metrics[1], 1, map[string]string{"name": "test", "version": ""})
178-
expectMetric(t, metrics[2], 1, map[string]string{"name": "test", "condition": "Available"})
179-
expectMetric(t, metrics[3], 0, map[string]string{"name": "test", "condition": "Custom"})
178+
expectMetric(t, metrics[2], 1, map[string]string{"name": "test", "condition": "Available", "reason": ""})
179+
expectMetric(t, metrics[3], 0, map[string]string{"name": "test", "condition": "Custom", "reason": "CustomReason"})
180180
},
181181
},
182182
{

0 commit comments

Comments
 (0)