Skip to content

Commit

Permalink
deploy: add conditions metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Jun 22, 2017
1 parent 2edc9c8 commit d458bf8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/deploy/controller/deploymentconfig/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (c *DeploymentConfigController) Run(workers int, stopCh <-chan struct{}) {

func (c *DeploymentConfigController) addDeploymentConfig(obj interface{}) {
dc := obj.(*deployapi.DeploymentConfig)
updateConditionsMetrics([]deployapi.DeploymentCondition{}, dc.Status.Conditions)
glog.V(4).Infof("Adding deployment config %q", dc.Name)
c.enqueueDeploymentConfig(dc)
}
Expand All @@ -113,6 +114,8 @@ func (c *DeploymentConfigController) updateDeploymentConfig(old, cur interface{}
return
}

// Track conditions changes in prometheus metrics
updateConditionsMetrics(oldDc.Status.Conditions, newDc.Status.Conditions)
glog.V(4).Infof("Updating deployment config %q", newDc.Name)
c.enqueueDeploymentConfig(newDc)
}
Expand All @@ -131,6 +134,8 @@ func (c *DeploymentConfigController) deleteDeploymentConfig(obj interface{}) {
return
}
}
// Remove conditions of deleted dc from the counter
updateConditionsMetrics(dc.Status.Conditions, []deployapi.DeploymentCondition{})
glog.V(4).Infof("Deleting deployment config %q", dc.Name)
c.enqueueDeploymentConfig(dc)
}
Expand Down
60 changes: 60 additions & 0 deletions pkg/deploy/controller/deploymentconfig/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package deploymentconfig

import (
"strings"

deployapi "github.com/openshift/origin/pkg/deploy/api"
"github.com/prometheus/client_golang/prometheus"
)

// DeploymentConfigControllerSubsystem is how this controller is represented in
// prometheus metrics.
const DeploymentConfigControllerSubsystem = "deploymentconfig_controller"

var (
deploymentConditionsCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: DeploymentConfigControllerSubsystem,
Name: "current_conditions",
Help: "Gauge of current number of deployment conditions per condition type, reason and status",
},
[]string{"type", "reason", "status"},
)
)

func init() {
prometheus.MustRegister(deploymentConditionsCounter)
}

// updateConditionsMetrics updates the metrics for
func updateConditionsMetrics(old, new []deployapi.DeploymentCondition) {
conditionToLabelValues := func(c deployapi.DeploymentCondition) []string {
return []string{
strings.ToLower(string(c.Type)),
strings.ToLower(string(c.Reason)),
strings.ToLower(string(c.Status)),
}
}
for _, n := range new {
found := false
for _, o := range old {
if found = n == o; found {
break
}
}
if !found {
deploymentConditionsCounter.WithLabelValues(conditionToLabelValues(n)...).Inc()
}
}
for _, o := range old {
found := false
for _, n := range new {
if found = o == n; found {
break
}
}
if !found {
deploymentConditionsCounter.WithLabelValues(conditionToLabelValues(o)...).Dec()
}
}
}

0 comments on commit d458bf8

Please sign in to comment.