Skip to content

Commit 0fb610f

Browse files
author
Jim Minter
committed
separate openshift_template_instance_status_condition_total and openshift_template_instance_total metrics
1 parent 092c32e commit 0fb610f

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

pkg/template/controller/metrics.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import (
1111
var templateInstancesTotal = prometheus.NewGaugeVec(
1212
prometheus.GaugeOpts{
1313
Name: "openshift_template_instance_total",
14+
Help: "Counts TemplateInstance objects",
15+
},
16+
nil,
17+
)
18+
19+
var templateInstanceStatusCondition = prometheus.NewGaugeVec(
20+
prometheus.GaugeOpts{
21+
Name: "openshift_template_instance_status_condition_total",
1422
Help: "Counts TemplateInstance objects by condition type and status",
1523
},
1624
[]string{"type", "status"},
@@ -26,6 +34,7 @@ var templateInstancesActiveStartTime = prometheus.NewGaugeVec(
2634

2735
func (c *TemplateInstanceController) Describe(ch chan<- *prometheus.Desc) {
2836
templateInstancesTotal.Describe(ch)
37+
templateInstanceStatusCondition.Describe(ch)
2938
templateInstancesActiveStartTime.Describe(ch)
3039
}
3140

@@ -37,17 +46,18 @@ func (c *TemplateInstanceController) Collect(ch chan<- prometheus.Metric) {
3746
}
3847

3948
templateInstancesTotal.Reset()
49+
templateInstanceStatusCondition.Reset()
4050
templateInstancesActiveStartTime.Reset()
4151

42-
templateInstancesTotal.WithLabelValues("", "").Set(0)
52+
templateInstancesTotal.WithLabelValues().Set(0)
4353

4454
for _, templateInstance := range templateInstances {
4555
waiting := true
4656

47-
templateInstancesTotal.WithLabelValues("", "").Inc()
57+
templateInstancesTotal.WithLabelValues().Inc()
4858

4959
for _, cond := range templateInstance.Status.Conditions {
50-
templateInstancesTotal.WithLabelValues(string(cond.Type), string(cond.Status)).Inc()
60+
templateInstanceStatusCondition.WithLabelValues(string(cond.Type), string(cond.Status)).Inc()
5161

5262
if cond.Status == kapi.ConditionTrue &&
5363
(cond.Type == templateapi.TemplateInstanceInstantiateFailure || cond.Type == templateapi.TemplateInstanceReady) {
@@ -61,5 +71,6 @@ func (c *TemplateInstanceController) Collect(ch chan<- prometheus.Metric) {
6171
}
6272

6373
templateInstancesTotal.Collect(ch)
74+
templateInstanceStatusCondition.Collect(ch)
6475
templateInstancesActiveStartTime.Collect(ch)
6576
}

pkg/template/controller/metrics_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ func TestMetrics(t *testing.T) {
4444
expectedResponse := `# HELP openshift_template_instance_active_start_time_seconds Show the start time in unix epoch form of active TemplateInstance objects by namespace and name
4545
# TYPE openshift_template_instance_active_start_time_seconds gauge
4646
openshift_template_instance_active_start_time_seconds{name="testname",namespace="testnamespace"} 123
47-
# HELP openshift_template_instance_total Counts TemplateInstance objects by condition type and status
47+
# HELP openshift_template_instance_status_condition_total Counts TemplateInstance objects by condition type and status
48+
# TYPE openshift_template_instance_status_condition_total gauge
49+
openshift_template_instance_status_condition_total{status="False",type="Ready"} 1
50+
openshift_template_instance_status_condition_total{status="True",type="Ready"} 1
51+
# HELP openshift_template_instance_total Counts TemplateInstance objects
4852
# TYPE openshift_template_instance_total gauge
49-
openshift_template_instance_total{status="",type=""} 2
50-
openshift_template_instance_total{status="False",type="Ready"} 1
51-
openshift_template_instance_total{status="True",type="Ready"} 1
53+
openshift_template_instance_total 2
5254
`
5355
registry := prometheus.NewRegistry()
5456

0 commit comments

Comments
 (0)