7
7
"context"
8
8
"fmt"
9
9
"regexp"
10
+ "strconv"
10
11
"strings"
11
12
"sync"
12
13
@@ -80,7 +81,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
80
81
81
82
It ("generates csv_abnormal metric for OLM pod" , func () {
82
83
83
- Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8080" )).To (And (
84
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ))).To (And (
84
85
ContainElement (LikeMetric (
85
86
WithFamily ("csv_abnormal" ),
86
87
WithName (failingCSV .Name ),
@@ -108,7 +109,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
108
109
109
110
It ("deletes its associated CSV metrics" , func () {
110
111
// Verify that when the csv has been deleted, it deletes the corresponding CSV metrics
111
- Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8080" )).ToNot (And (
112
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ))).ToNot (And (
112
113
ContainElement (LikeMetric (WithFamily ("csv_abnormal" ), WithName (failingCSV .Name ))),
113
114
ContainElement (LikeMetric (WithFamily ("csv_succeeded" ), WithName (failingCSV .Name ))),
114
115
))
@@ -138,7 +139,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
138
139
139
140
// Verify metrics have been emitted for subscription
140
141
Eventually (func () []Metric {
141
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
142
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
142
143
}).Should (ContainElement (LikeMetric (
143
144
WithFamily ("subscription_sync_total" ),
144
145
WithName ("metric-subscription-for-create" ),
@@ -153,7 +154,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
153
154
// Verify metrics have been emitted for dependency resolution
154
155
Eventually (func () bool {
155
156
return Eventually (func () []Metric {
156
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
157
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
157
158
}).Should (ContainElement (LikeMetric (
158
159
WithFamily ("olm_resolution_duration_seconds" ),
159
160
WithLabel ("outcome" , "failed" ),
@@ -168,7 +169,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
168
169
BeforeEach (func () {
169
170
subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-update" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
170
171
Eventually (func () []Metric {
171
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
172
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
172
173
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-update" ))))
173
174
Eventually (func () error {
174
175
s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .TODO (), subscription .GetName (), metav1.GetOptions {})
@@ -189,7 +190,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
189
190
190
191
It ("deletes the old Subscription metric and emits the new metric" , func () {
191
192
Eventually (func () []Metric {
192
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
193
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
193
194
}).Should (And (
194
195
Not (ContainElement (LikeMetric (
195
196
WithFamily ("subscription_sync_total" ),
@@ -223,7 +224,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
223
224
224
225
It ("deletes the old subscription metric and emits the new metric(there is only one metric for the subscription)" , func () {
225
226
Eventually (func () []Metric {
226
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
227
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
227
228
}).Should (And (
228
229
Not (ContainElement (LikeMetric (
229
230
WithFamily ("subscription_sync_total" ),
@@ -253,7 +254,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
253
254
BeforeEach (func () {
254
255
subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-delete" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
255
256
Eventually (func () []Metric {
256
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
257
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
257
258
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-delete" ))))
258
259
if subscriptionCleanup != nil {
259
260
subscriptionCleanup ()
@@ -269,7 +270,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
269
270
270
271
It ("deletes the Subscription metric" , func () {
271
272
Eventually (func () []Metric {
272
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
273
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
273
274
}).ShouldNot (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithName ("metric-subscription-for-delete" ))))
274
275
})
275
276
})
@@ -312,7 +313,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
312
313
})
313
314
It ("emits metrics for the catalogSource" , func () {
314
315
Eventually (func () []Metric {
315
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
316
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
316
317
}).Should (And (
317
318
ContainElement (LikeMetric (
318
319
WithFamily ("catalog_source_count" ),
@@ -332,7 +333,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
332
333
})
333
334
It ("deletes the metrics for the CatalogSource" , func () {
334
335
Eventually (func () []Metric {
335
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
336
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
336
337
}).Should (And (
337
338
Not (ContainElement (LikeMetric (
338
339
WithFamily ("catalogsource_ready" ),
@@ -356,7 +357,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
356
357
})
357
358
It ("emits metrics for the CatlogSource with a Value greater than 0" , func () {
358
359
Eventually (func () []Metric {
359
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
360
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
360
361
}).Should (And (
361
362
ContainElement (LikeMetric (
362
363
WithFamily ("catalogsource_ready" ),
@@ -366,7 +367,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
366
367
)),
367
368
))
368
369
Consistently (func () []Metric {
369
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8080" )
370
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
370
371
}, "3m" ).Should (And (
371
372
ContainElement (LikeMetric (
372
373
WithFamily ("catalogsource_ready" ),
@@ -395,7 +396,18 @@ func getPodWithLabel(client operatorclient.ClientInterface, label string) *corev
395
396
return & podList .Items [0 ]
396
397
}
397
398
398
- func getMetricsFromPod (client operatorclient.ClientInterface , pod * corev1.Pod , port string ) []Metric {
399
+ func extractMetricPortFromPod (pod * corev1.Pod ) string {
400
+ for _ , container := range pod .Spec .Containers {
401
+ for _ , port := range container .Ports {
402
+ if port .Name == "metrics" {
403
+ return strconv .Itoa (int (port .ContainerPort ))
404
+ }
405
+ }
406
+ }
407
+ return "-1"
408
+ }
409
+
410
+ func getMetricsFromPod (client operatorclient.ClientInterface , pod * corev1.Pod ) []Metric {
399
411
ctx .Ctx ().Logf ("querying pod %s/%s\n " , pod .GetNamespace (), pod .GetName ())
400
412
401
413
// assuming -tls-cert and -tls-key aren't used anywhere else as a parameter value
@@ -417,14 +429,13 @@ func getMetricsFromPod(client operatorclient.ClientInterface, pod *corev1.Pod, p
417
429
scheme = "http"
418
430
}
419
431
ctx .Ctx ().Logf ("Retrieving metrics using scheme %v\n " , scheme )
420
-
421
432
mfs := make (map [string ]* io_prometheus_client.MetricFamily )
422
433
EventuallyWithOffset (1 , func () error {
423
434
raw , err := client .KubernetesInterface ().CoreV1 ().RESTClient ().Get ().
424
435
Namespace (pod .GetNamespace ()).
425
436
Resource ("pods" ).
426
437
SubResource ("proxy" ).
427
- Name (net .JoinSchemeNamePort (scheme , pod .GetName (), port )).
438
+ Name (net .JoinSchemeNamePort (scheme , pod .GetName (), extractMetricPortFromPod ( pod ) )).
428
439
Suffix ("metrics" ).
429
440
Do (context .Background ()).Raw ()
430
441
if err != nil {
0 commit comments