@@ -18,8 +18,9 @@ import (
18
18
19
19
var _ = Describe ("Custom Metrics" , func () {
20
20
type buildRunLabels struct {
21
- namespace string
22
21
buildStrategy string
22
+ namespace string
23
+ buildRun string
23
24
}
24
25
25
26
var (
@@ -30,11 +31,12 @@ var _ = Describe("Custom Metrics", func() {
30
31
var result = buildRunLabels {}
31
32
for _ , label := range in {
32
33
switch * label .Name {
33
- case "buildstrategy" :
34
+ case BuildStrategyLabel :
34
35
result .buildStrategy = * label .Value
35
-
36
- case "namespace" :
36
+ case NamespaceLabel :
37
37
result .namespace = * label .Value
38
+ case BuildRunLabel :
39
+ result .buildRun = * label .Value
38
40
}
39
41
}
40
42
@@ -45,8 +47,8 @@ var _ = Describe("Custom Metrics", func() {
45
47
BeforeSuite (func () {
46
48
var (
47
49
testLabels = []buildRunLabels {
48
- {namespace : "default" , buildStrategy : "kaniko" },
49
- {namespace : "default" , buildStrategy : "buildpacks" },
50
+ {buildStrategy : "kaniko" , namespace : "default" , buildRun : "kaniko-buildrun " },
51
+ {buildStrategy : "buildpacks" , namespace : "default" , buildRun : "buildpacks-buildrun " },
50
52
}
51
53
52
54
knownCounterMetrics = []string {
@@ -75,22 +77,22 @@ var _ = Describe("Custom Metrics", func() {
75
77
76
78
// initialize prometheus (second init should be no-op)
77
79
config := config .NewDefaultConfig ()
78
- config .Prometheus .HistogramEnabledLabels = []string {"buildstrategy" , "namespace" }
80
+ config .Prometheus .HistogramEnabledLabels = []string {BuildStrategyLabel , NamespaceLabel , BuildRunLabel }
79
81
InitPrometheus (config )
80
82
InitPrometheus (config )
81
83
82
84
// and fire some examples
83
85
for _ , entry := range testLabels {
84
- buildStrategy , namespace := entry .buildStrategy , entry .namespace
86
+ buildStrategy , namespace , buildRun := entry .buildStrategy , entry .namespace , entry . buildRun
85
87
86
88
// tell prometheus some things have happened
87
89
BuildCountInc (buildStrategy )
88
90
BuildRunCountInc (buildStrategy )
89
- BuildRunEstablishObserve (buildStrategy , namespace , time .Duration (1 )* time .Second )
90
- BuildRunCompletionObserve (buildStrategy , namespace , time .Duration (200 )* time .Second )
91
- BuildRunRampUpDurationObserve (buildStrategy , namespace , time .Duration (1 )* time .Second )
92
- TaskRunRampUpDurationObserve (buildStrategy , namespace , time .Duration (2 )* time .Second )
93
- TaskRunPodRampUpDurationObserve (buildStrategy , namespace , time .Duration (3 )* time .Second )
91
+ BuildRunEstablishObserve (buildStrategy , namespace , buildRun , time .Duration (1 )* time .Second )
92
+ BuildRunCompletionObserve (buildStrategy , namespace , buildRun , time .Duration (200 )* time .Second )
93
+ BuildRunRampUpDurationObserve (buildStrategy , namespace , buildRun , time .Duration (1 )* time .Second )
94
+ TaskRunRampUpDurationObserve (buildStrategy , namespace , buildRun , time .Duration (2 )* time .Second )
95
+ TaskRunPodRampUpDurationObserve (buildStrategy , namespace , buildRun , time .Duration (3 )* time .Second )
94
96
}
95
97
96
98
// gather metrics from prometheus and fill the result maps
@@ -130,22 +132,22 @@ var _ = Describe("Custom Metrics", func() {
130
132
131
133
It ("should record the kaniko buildrun establish time" , func () {
132
134
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_establish_duration_seconds" ))
133
- Expect (histogramMetrics ["build_buildrun_establish_duration_seconds" ][buildRunLabels {"default" , "kaniko" }]).To (Equal (1.0 ))
135
+ Expect (histogramMetrics ["build_buildrun_establish_duration_seconds" ][buildRunLabels {"kaniko" , " default" , "kaniko-buildrun " }]).To (Equal (1.0 ))
134
136
})
135
137
136
138
It ("should record the kaniko buildrun completion time" , func () {
137
139
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_completion_duration_seconds" ))
138
- Expect (histogramMetrics ["build_buildrun_completion_duration_seconds" ][buildRunLabels {"default" , "kaniko" }]).To (Equal (200.0 ))
140
+ Expect (histogramMetrics ["build_buildrun_completion_duration_seconds" ][buildRunLabels {"kaniko" , " default" , "kaniko-buildrun " }]).To (Equal (200.0 ))
139
141
})
140
142
141
143
It ("should record the kaniko ramp-up durations" , func () {
142
144
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_rampup_duration_seconds" ))
143
145
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_taskrun_rampup_duration_seconds" ))
144
146
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_taskrun_pod_rampup_duration_seconds" ))
145
147
146
- Expect (histogramMetrics ["build_buildrun_rampup_duration_seconds" ][buildRunLabels {"default" , "kaniko" }]).To (BeNumerically (">" , 0.0 ))
147
- Expect (histogramMetrics ["build_buildrun_taskrun_rampup_duration_seconds" ][buildRunLabels {"default" , "kaniko" }]).To (BeNumerically (">" , 0.0 ))
148
- Expect (histogramMetrics ["build_buildrun_taskrun_pod_rampup_duration_seconds" ][buildRunLabels {"default" , "kaniko" }]).To (BeNumerically (">" , 0.0 ))
148
+ Expect (histogramMetrics ["build_buildrun_rampup_duration_seconds" ][buildRunLabels {"kaniko" , " default" , "kaniko-buildrun " }]).To (BeNumerically (">" , 0.0 ))
149
+ Expect (histogramMetrics ["build_buildrun_taskrun_rampup_duration_seconds" ][buildRunLabels {"kaniko" , " default" , "kaniko-buildrun " }]).To (BeNumerically (">" , 0.0 ))
150
+ Expect (histogramMetrics ["build_buildrun_taskrun_pod_rampup_duration_seconds" ][buildRunLabels {"kaniko" , " default" , "kaniko-buildrun " }]).To (BeNumerically (">" , 0.0 ))
149
151
})
150
152
})
151
153
@@ -163,22 +165,22 @@ var _ = Describe("Custom Metrics", func() {
163
165
164
166
It ("should record the buildpacks buildrun establish time" , func () {
165
167
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_establish_duration_seconds" ))
166
- Expect (histogramMetrics ["build_buildrun_establish_duration_seconds" ][buildRunLabels {"default" , "buildpacks" }]).To (Equal (1.0 ))
168
+ Expect (histogramMetrics ["build_buildrun_establish_duration_seconds" ][buildRunLabels {"buildpacks" , " default" , "buildpacks-buildrun " }]).To (Equal (1.0 ))
167
169
})
168
170
169
171
It ("should record the buildpacks buildrun completion time" , func () {
170
172
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_completion_duration_seconds" ))
171
- Expect (histogramMetrics ["build_buildrun_completion_duration_seconds" ][buildRunLabels {"default" , "buildpacks" }]).To (Equal (200.0 ))
173
+ Expect (histogramMetrics ["build_buildrun_completion_duration_seconds" ][buildRunLabels {"buildpacks" , " default" , "buildpacks-buildrun " }]).To (Equal (200.0 ))
172
174
})
173
175
174
176
It ("should record the buildpacks ramp-up durations" , func () {
175
177
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_rampup_duration_seconds" ))
176
178
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_taskrun_rampup_duration_seconds" ))
177
179
Expect (histogramMetrics ).To (HaveKey ("build_buildrun_taskrun_pod_rampup_duration_seconds" ))
178
180
179
- Expect (histogramMetrics ["build_buildrun_rampup_duration_seconds" ][buildRunLabels {"default" , "buildpacks" }]).To (BeNumerically (">" , 0.0 ))
180
- Expect (histogramMetrics ["build_buildrun_taskrun_rampup_duration_seconds" ][buildRunLabels {"default" , "buildpacks" }]).To (BeNumerically (">" , 0.0 ))
181
- Expect (histogramMetrics ["build_buildrun_taskrun_pod_rampup_duration_seconds" ][buildRunLabels {"default" , "buildpacks" }]).To (BeNumerically (">" , 0.0 ))
181
+ Expect (histogramMetrics ["build_buildrun_rampup_duration_seconds" ][buildRunLabels {"buildpacks" , " default" , "buildpacks-buildrun " }]).To (BeNumerically (">" , 0.0 ))
182
+ Expect (histogramMetrics ["build_buildrun_taskrun_rampup_duration_seconds" ][buildRunLabels {"buildpacks" , " default" , "buildpacks-buildrun " }]).To (BeNumerically (">" , 0.0 ))
183
+ Expect (histogramMetrics ["build_buildrun_taskrun_pod_rampup_duration_seconds" ][buildRunLabels {"buildpacks" , " default" , "buildpacks-buildrun " }]).To (BeNumerically (">" , 0.0 ))
182
184
})
183
185
})
184
186
})
0 commit comments