8
8
"context"
9
9
"fmt"
10
10
"regexp"
11
+ "strconv"
11
12
"strings"
12
13
"sync"
13
14
@@ -79,7 +80,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
79
80
80
81
It ("generates csv_abnormal metric for OLM pod" , func () {
81
82
82
- Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8081" )).To (And (
83
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ))).To (And (
83
84
ContainElement (LikeMetric (
84
85
WithFamily ("csv_abnormal" ),
85
86
WithName (failingCSV .Name ),
@@ -107,7 +108,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
107
108
108
109
It ("deletes its associated CSV metrics" , func () {
109
110
// Verify that when the csv has been deleted, it deletes the corresponding CSV metrics
110
- Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ), "8081" )).ToNot (And (
111
+ Expect (getMetricsFromPod (c , getPodWithLabel (c , "app=olm-operator" ))).ToNot (And (
111
112
ContainElement (LikeMetric (WithFamily ("csv_abnormal" ), WithName (failingCSV .Name ))),
112
113
ContainElement (LikeMetric (WithFamily ("csv_succeeded" ), WithName (failingCSV .Name ))),
113
114
))
@@ -179,7 +180,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
179
180
180
181
// Verify metrics have been emitted for subscription
181
182
Eventually (func () []Metric {
182
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
183
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
183
184
}).Should (ContainElement (LikeMetric (
184
185
WithFamily ("subscription_sync_total" ),
185
186
WithName ("metric-subscription-for-create" ),
@@ -194,7 +195,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
194
195
// Verify metrics have been emitted for dependency resolution
195
196
Eventually (func () bool {
196
197
return Eventually (func () []Metric {
197
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
198
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
198
199
}).Should (ContainElement (LikeMetric (
199
200
WithFamily ("olm_resolution_duration_seconds" ),
200
201
WithLabel ("outcome" , "failed" ),
@@ -209,7 +210,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
209
210
BeforeEach (func () {
210
211
subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-update" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
211
212
Eventually (func () []Metric {
212
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
213
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
213
214
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-update" ))))
214
215
Eventually (func () error {
215
216
s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .TODO (), subscription .GetName (), metav1.GetOptions {})
@@ -230,7 +231,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
230
231
231
232
It ("deletes the old Subscription metric and emits the new metric" , func () {
232
233
Eventually (func () []Metric {
233
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
234
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
234
235
}).Should (And (
235
236
Not (ContainElement (LikeMetric (
236
237
WithFamily ("subscription_sync_total" ),
@@ -264,7 +265,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
264
265
265
266
It ("deletes the old subscription metric and emits the new metric(there is only one metric for the subscription)" , func () {
266
267
Eventually (func () []Metric {
267
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
268
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
268
269
}).Should (And (
269
270
Not (ContainElement (LikeMetric (
270
271
WithFamily ("subscription_sync_total" ),
@@ -294,7 +295,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
294
295
BeforeEach (func () {
295
296
subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-delete" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
296
297
Eventually (func () []Metric {
297
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
298
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
298
299
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-delete" ))))
299
300
if subscriptionCleanup != nil {
300
301
subscriptionCleanup ()
@@ -310,7 +311,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
310
311
311
312
It ("deletes the Subscription metric" , func () {
312
313
Eventually (func () []Metric {
313
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
314
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
314
315
}).ShouldNot (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithName ("metric-subscription-for-delete" ))))
315
316
})
316
317
})
@@ -353,7 +354,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
353
354
})
354
355
It ("emits metrics for the catalogSource" , func () {
355
356
Eventually (func () []Metric {
356
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
357
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
357
358
}).Should (And (
358
359
ContainElement (LikeMetric (
359
360
WithFamily ("catalog_source_count" ),
@@ -373,7 +374,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
373
374
})
374
375
It ("deletes the metrics for the CatalogSource" , func () {
375
376
Eventually (func () []Metric {
376
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
377
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
377
378
}).Should (And (
378
379
Not (ContainElement (LikeMetric (
379
380
WithFamily ("catalogsource_ready" ),
@@ -397,7 +398,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
397
398
})
398
399
It ("emits metrics for the CatlogSource with a Value greater than 0" , func () {
399
400
Eventually (func () []Metric {
400
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
401
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
401
402
}).Should (And (
402
403
ContainElement (LikeMetric (
403
404
WithFamily ("catalogsource_ready" ),
@@ -407,7 +408,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
407
408
)),
408
409
))
409
410
Consistently (func () []Metric {
410
- return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ), "8081" )
411
+ return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
411
412
}, "3m" ).Should (And (
412
413
ContainElement (LikeMetric (
413
414
WithFamily ("catalogsource_ready" ),
@@ -514,14 +515,13 @@ func getMetricsFromPod(client operatorclient.ClientInterface, pod *corev1.Pod) [
514
515
scheme = "http"
515
516
}
516
517
ctx .Ctx ().Logf ("Retrieving metrics using scheme %v\n " , scheme )
517
-
518
518
mfs := make (map [string ]* io_prometheus_client.MetricFamily )
519
519
EventuallyWithOffset (1 , func () error {
520
520
raw , err := client .KubernetesInterface ().CoreV1 ().RESTClient ().Get ().
521
521
Namespace (pod .GetNamespace ()).
522
522
Resource ("pods" ).
523
523
SubResource ("proxy" ).
524
- Name (net .JoinSchemeNamePort (scheme , pod .GetName (), port )).
524
+ Name (net .JoinSchemeNamePort (scheme , pod .GetName (), extractMetricPortFromPod ( pod ) )).
525
525
Suffix ("metrics" ).
526
526
Do (context .Background ()).Raw ()
527
527
if err != nil {
0 commit comments