Skip to content

Commit

Permalink
Change label name from buildrunname to buildrun
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtbj committed Nov 11, 2020
1 parent edbfe16 commit 76d3882
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
14 changes: 7 additions & 7 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Following build metrics are exposed at service `build-operator-metrics` on port
| ---- | ---- | ----------- | ------ | ------ |
| `build_builds_registered_total` | Counter | Number of total registered Builds. | buildstrategy=<build_buildstrategy_name> | experimental |
| `build_buildruns_completed_total` | Counter | Number of total completed BuildRuns. | buildstrategy=<build_buildstrategy_name> | experimental |
| `build_buildrun_establish_duration_seconds` | Histogram | BuildRun establish duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrunname=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_completion_duration_seconds` | Histogram | BuildRun completion duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrunname=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_rampup_duration_seconds` | Histogram | BuildRun ramp-up duration in seconds | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrunname=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_taskrun_rampup_duration_seconds` | Histogram | BuildRun taskrun ramp-up duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrunname=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_taskrun_pod_rampup_duration_seconds` | Histogram | BuildRun taskrun pod ramp-up duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrunname=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_establish_duration_seconds` | Histogram | BuildRun establish duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrun=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_completion_duration_seconds` | Histogram | BuildRun completion duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrun=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_rampup_duration_seconds` | Histogram | BuildRun ramp-up duration in seconds | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrun=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_taskrun_rampup_duration_seconds` | Histogram | BuildRun taskrun ramp-up duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrun=<buildrun_name> <sup>1</sup> | experimental |
| `build_buildrun_taskrun_pod_rampup_duration_seconds` | Histogram | BuildRun taskrun pod ramp-up duration in seconds. | buildstrategy=<build_buildstrategy_name> <sup>1</sup><br>namespace=<buildrun_namespace> <sup>1</sup><br>buildrun=<buildrun_name> <sup>1</sup> | experimental |

<sup>1</sup> Labels for histograms are disabled by default. See [Configuration of histogram labels](#configuration-of-histogram-labels) to enable them.

Expand Down Expand Up @@ -57,7 +57,7 @@ As the amount of buckets and labels has a direct impact on the number of Prometh

* buildstrategy
* namespace
* buildrunname
* buildrun

Use a comma-separated value to enable multiple labels. For example:

Expand All @@ -69,7 +69,7 @@ make local
or

```bash
export PROMETHEUS_HISTOGRAM_ENABLED_LABELS=buildstrategy,namespace,buildrunname
export PROMETHEUS_HISTOGRAM_ENABLED_LABELS=buildstrategy,namespace,buildrun
make local
```

Expand Down
36 changes: 18 additions & 18 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
const (
BuildStrategyLabel string = "buildstrategy"
NamespaceLabel string = "namespace"
BuildRunNameLabel string = "buildrunname"
BuildRunLabel string = "buildrun"
)

var (
Expand All @@ -44,7 +44,7 @@ var (

histogramBuildStrategyLabelEnabled = false
histogramNamespaceLabelEnabled = false
histogramBuildRunNameLabelEnabled = false
histogramBuildRunLabelEnabled = false

initialized = false
)
Expand All @@ -66,9 +66,9 @@ func InitPrometheus(config *config.Config) {
histogramLabels = append(histogramLabels, NamespaceLabel)
histogramNamespaceLabelEnabled = true
}
if contains(config.Prometheus.HistogramEnabledLabels, BuildRunNameLabel) {
histogramLabels = append(histogramLabels, BuildRunNameLabel)
histogramBuildRunNameLabelEnabled = true
if contains(config.Prometheus.HistogramEnabledLabels, BuildRunLabel) {
histogramLabels = append(histogramLabels, BuildRunLabel)
histogramBuildRunLabelEnabled = true
}

buildRunEstablishDuration = prometheus.NewHistogramVec(
Expand Down Expand Up @@ -132,7 +132,7 @@ func contains(slice []string, element string) bool {
return false
}

func createHistogramLabels(buildStrategy string, namespace string, buildRunName string) prometheus.Labels {
func createHistogramLabels(buildStrategy string, namespace string, buildRun string) prometheus.Labels {
labels := prometheus.Labels{}

if histogramBuildStrategyLabelEnabled {
Expand All @@ -141,8 +141,8 @@ func createHistogramLabels(buildStrategy string, namespace string, buildRunName
if histogramNamespaceLabelEnabled {
labels[NamespaceLabel] = namespace
}
if histogramBuildRunNameLabelEnabled {
labels[BuildRunNameLabel] = buildRunName
if histogramBuildRunLabelEnabled {
labels[BuildRunLabel] = buildRun
}

return labels
Expand All @@ -161,36 +161,36 @@ func BuildRunCountInc(buildStrategy string) {
}

// BuildRunEstablishObserve sets the build run establish time
func BuildRunEstablishObserve(buildStrategy string, namespace string, buildRunName string, duration time.Duration) {
func BuildRunEstablishObserve(buildStrategy string, namespace string, buildRun string, duration time.Duration) {
if buildRunEstablishDuration != nil {
buildRunEstablishDuration.With(createHistogramLabels(buildStrategy, namespace, buildRunName)).Observe(duration.Seconds())
buildRunEstablishDuration.With(createHistogramLabels(buildStrategy, namespace, buildRun)).Observe(duration.Seconds())
}
}

// BuildRunCompletionObserve sets the build run completion time
func BuildRunCompletionObserve(buildStrategy string, namespace string, buildRunName string, duration time.Duration) {
func BuildRunCompletionObserve(buildStrategy string, namespace string, buildRun string, duration time.Duration) {
if buildRunCompletionDuration != nil {
buildRunCompletionDuration.With(createHistogramLabels(buildStrategy, namespace, buildRunName)).Observe(duration.Seconds())
buildRunCompletionDuration.With(createHistogramLabels(buildStrategy, namespace, buildRun)).Observe(duration.Seconds())
}
}

// BuildRunRampUpDurationObserve processes the observation of a new buildrun ramp-up duration
func BuildRunRampUpDurationObserve(buildStrategy string, namespace string, buildRunName string, duration time.Duration) {
func BuildRunRampUpDurationObserve(buildStrategy string, namespace string, buildRun string, duration time.Duration) {
if buildRunRampUpDuration != nil {
buildRunRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRunName)).Observe(duration.Seconds())
buildRunRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRun)).Observe(duration.Seconds())
}
}

// TaskRunRampUpDurationObserve processes the observation of a new taskrun ramp-up duration
func TaskRunRampUpDurationObserve(buildStrategy string, namespace string, buildRunName string, duration time.Duration) {
func TaskRunRampUpDurationObserve(buildStrategy string, namespace string, buildRun string, duration time.Duration) {
if taskRunRampUpDuration != nil {
taskRunRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRunName)).Observe(duration.Seconds())
taskRunRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRun)).Observe(duration.Seconds())
}
}

// TaskRunPodRampUpDurationObserve processes the observation of a new taskrun pod ramp-up duration
func TaskRunPodRampUpDurationObserve(buildStrategy string, namespace string, buildRunName string, duration time.Duration) {
func TaskRunPodRampUpDurationObserve(buildStrategy string, namespace string, buildRun string, duration time.Duration) {
if taskRunPodRampUpDuration != nil {
taskRunPodRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRunName)).Observe(duration.Seconds())
taskRunPodRampUpDuration.With(createHistogramLabels(buildStrategy, namespace, buildRun)).Observe(duration.Seconds())
}
}
24 changes: 12 additions & 12 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ = Describe("Custom Metrics", func() {
type buildRunLabels struct {
buildStrategy string
namespace string
buildRunName string
buildRun string
}

var (
Expand All @@ -35,8 +35,8 @@ var _ = Describe("Custom Metrics", func() {
result.buildStrategy = *label.Value
case NamespaceLabel:
result.namespace = *label.Value
case BuildRunNameLabel:
result.buildRunName = *label.Value
case BuildRunLabel:
result.buildRun = *label.Value
}
}

Expand All @@ -47,8 +47,8 @@ var _ = Describe("Custom Metrics", func() {
BeforeSuite(func() {
var (
testLabels = []buildRunLabels{
{buildStrategy: "kaniko", namespace: "default", buildRunName: "kaniko-buildrun"},
{buildStrategy: "buildpacks", namespace: "default", buildRunName: "buildpacks-buildrun"},
{buildStrategy: "kaniko", namespace: "default", buildRun: "kaniko-buildrun"},
{buildStrategy: "buildpacks", namespace: "default", buildRun: "buildpacks-buildrun"},
}

knownCounterMetrics = []string{
Expand Down Expand Up @@ -77,22 +77,22 @@ var _ = Describe("Custom Metrics", func() {

// initialize prometheus (second init should be no-op)
config := config.NewDefaultConfig()
config.Prometheus.HistogramEnabledLabels = []string{BuildStrategyLabel, NamespaceLabel, BuildRunNameLabel}
config.Prometheus.HistogramEnabledLabels = []string{BuildStrategyLabel, NamespaceLabel, BuildRunLabel}
InitPrometheus(config)
InitPrometheus(config)

// and fire some examples
for _, entry := range testLabels {
buildStrategy, namespace, buildRunName := entry.buildStrategy, entry.namespace, entry.buildRunName
buildStrategy, namespace, buildRun := entry.buildStrategy, entry.namespace, entry.buildRun

// tell prometheus some things have happened
BuildCountInc(buildStrategy)
BuildRunCountInc(buildStrategy)
BuildRunEstablishObserve(buildStrategy, namespace, buildRunName, time.Duration(1)*time.Second)
BuildRunCompletionObserve(buildStrategy, namespace, buildRunName, time.Duration(200)*time.Second)
BuildRunRampUpDurationObserve(buildStrategy, namespace, buildRunName, time.Duration(1)*time.Second)
TaskRunRampUpDurationObserve(buildStrategy, namespace, buildRunName, time.Duration(2)*time.Second)
TaskRunPodRampUpDurationObserve(buildStrategy, namespace, buildRunName, time.Duration(3)*time.Second)
BuildRunEstablishObserve(buildStrategy, namespace, buildRun, time.Duration(1)*time.Second)
BuildRunCompletionObserve(buildStrategy, namespace, buildRun, time.Duration(200)*time.Second)
BuildRunRampUpDurationObserve(buildStrategy, namespace, buildRun, time.Duration(1)*time.Second)
TaskRunRampUpDurationObserve(buildStrategy, namespace, buildRun, time.Duration(2)*time.Second)
TaskRunPodRampUpDurationObserve(buildStrategy, namespace, buildRun, time.Duration(3)*time.Second)
}

// gather metrics from prometheus and fill the result maps
Expand Down

0 comments on commit 76d3882

Please sign in to comment.