-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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 prometheus gauge counters based on the delta between | ||
// old and new deployment conditions. | ||
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() | ||
} | ||
} | ||
} |