Skip to content

Commit

Permalink
Merge pull request #16588 from jim-minter/trello138-tsb-prometheus-3
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

separate openshift_template_instance_status_condition_total and openshift_template_instance_total metrics

follow-up from #16455

@smarterclayton @bparees ptal
@gabemontero fyi
  • Loading branch information
openshift-merge-robot committed Oct 4, 2017
2 parents 684a845 + 0fb610f commit 79da86b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 14 additions & 3 deletions pkg/template/controller/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (
var templateInstancesTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "openshift_template_instance_total",
Help: "Counts TemplateInstance objects",
},
nil,
)

var templateInstanceStatusCondition = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "openshift_template_instance_status_condition_total",
Help: "Counts TemplateInstance objects by condition type and status",
},
[]string{"type", "status"},
Expand All @@ -26,6 +34,7 @@ var templateInstancesActiveStartTime = prometheus.NewGaugeVec(

func (c *TemplateInstanceController) Describe(ch chan<- *prometheus.Desc) {
templateInstancesTotal.Describe(ch)
templateInstanceStatusCondition.Describe(ch)
templateInstancesActiveStartTime.Describe(ch)
}

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

templateInstancesTotal.Reset()
templateInstanceStatusCondition.Reset()
templateInstancesActiveStartTime.Reset()

templateInstancesTotal.WithLabelValues("", "").Set(0)
templateInstancesTotal.WithLabelValues().Set(0)

for _, templateInstance := range templateInstances {
waiting := true

templateInstancesTotal.WithLabelValues("", "").Inc()
templateInstancesTotal.WithLabelValues().Inc()

for _, cond := range templateInstance.Status.Conditions {
templateInstancesTotal.WithLabelValues(string(cond.Type), string(cond.Status)).Inc()
templateInstanceStatusCondition.WithLabelValues(string(cond.Type), string(cond.Status)).Inc()

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

templateInstancesTotal.Collect(ch)
templateInstanceStatusCondition.Collect(ch)
templateInstancesActiveStartTime.Collect(ch)
}
10 changes: 6 additions & 4 deletions pkg/template/controller/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func TestMetrics(t *testing.T) {
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
# TYPE openshift_template_instance_active_start_time_seconds gauge
openshift_template_instance_active_start_time_seconds{name="testname",namespace="testnamespace"} 123
# HELP openshift_template_instance_total Counts TemplateInstance objects by condition type and status
# HELP openshift_template_instance_status_condition_total Counts TemplateInstance objects by condition type and status
# TYPE openshift_template_instance_status_condition_total gauge
openshift_template_instance_status_condition_total{status="False",type="Ready"} 1
openshift_template_instance_status_condition_total{status="True",type="Ready"} 1
# HELP openshift_template_instance_total Counts TemplateInstance objects
# TYPE openshift_template_instance_total gauge
openshift_template_instance_total{status="",type=""} 2
openshift_template_instance_total{status="False",type="Ready"} 1
openshift_template_instance_total{status="True",type="Ready"} 1
openshift_template_instance_total 2
`
registry := prometheus.NewRegistry()

Expand Down

0 comments on commit 79da86b

Please sign in to comment.