Skip to content

Commit 407c68c

Browse files
awgreeneanik120
authored andcommitted
Update getMetricsFromPort to infer port number
Problem: The getMetricsFromPod function assumes that metrics are exposed on port 8080. This function fails to retrieve metrics from the olm or catalog operator when the port is changed. Solution: Name the port in each of the deployments and update the getMetricsFromPod function to infer the port number from the deployments. Signed-off-by: Alexander Greene <[email protected]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 08a1d4b2f06fda1a6d6b4cadf779e1ce2259af3e
1 parent 363fe49 commit 407c68c

6 files changed

+37
-17
lines changed

Diff for: manifests/0000_50_olm_07-olm-operator.deployment.ibm-cloud-managed.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ spec:
4141
image: quay.io/operator-framework/olm@sha256:de396b540b82219812061d0d753440d5655250c621c753ed1dc67d6154741607
4242
imagePullPolicy: IfNotPresent
4343
ports:
44+
<<<<<<< HEAD
4445
- containerPort: 8080
4546
- containerPort: 8081
4647
name: metrics
4748
protocol: TCP
49+
=======
50+
- containerPort: 8443
51+
name: metrics
52+
>>>>>>> ec51a3dd2 (Update getMetricsFromPort to infer port number)
4853
livenessProbe:
4954
httpGet:
5055
path: /healthz

Diff for: manifests/0000_50_olm_07-olm-operator.deployment.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ spec:
4242
image: quay.io/operator-framework/olm@sha256:de396b540b82219812061d0d753440d5655250c621c753ed1dc67d6154741607
4343
imagePullPolicy: IfNotPresent
4444
ports:
45+
<<<<<<< HEAD
4546
- containerPort: 8080
4647
- containerPort: 8081
4748
name: metrics
4849
protocol: TCP
50+
=======
51+
- containerPort: 8443
52+
name: metrics
53+
>>>>>>> ec51a3dd2 (Update getMetricsFromPort to infer port number)
4954
livenessProbe:
5055
httpGet:
5156
path: /healthz

Diff for: manifests/0000_50_olm_08-catalog-operator.deployment.ibm-cloud-managed.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ spec:
4242
image: quay.io/operator-framework/olm@sha256:de396b540b82219812061d0d753440d5655250c621c753ed1dc67d6154741607
4343
imagePullPolicy: IfNotPresent
4444
ports:
45+
<<<<<<< HEAD
4546
- containerPort: 8080
4647
- containerPort: 8081
4748
name: metrics
4849
protocol: TCP
50+
=======
51+
- containerPort: 8443
52+
name: metrics
53+
>>>>>>> ec51a3dd2 (Update getMetricsFromPort to infer port number)
4954
livenessProbe:
5055
httpGet:
5156
path: /healthz

Diff for: manifests/0000_50_olm_08-catalog-operator.deployment.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ spec:
4343
image: quay.io/operator-framework/olm@sha256:de396b540b82219812061d0d753440d5655250c621c753ed1dc67d6154741607
4444
imagePullPolicy: IfNotPresent
4545
ports:
46+
<<<<<<< HEAD
4647
- containerPort: 8080
4748
- containerPort: 8081
4849
name: metrics
4950
protocol: TCP
51+
=======
52+
- containerPort: 8443
53+
name: metrics
54+
>>>>>>> ec51a3dd2 (Update getMetricsFromPort to infer port number)
5055
livenessProbe:
5156
httpGet:
5257
path: /healthz

Diff for: staging/operator-lifecycle-manager/test/e2e/installplan_e2e_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var _ = Describe("Install Plan", func() {
8989

9090
BeforeEach(func() {
9191
counter = 0
92-
for _, metric := range getMetricsFromPod(ctx.Ctx().KubeClient(), getPodWithLabel(ctx.Ctx().KubeClient(), "app=catalog-operator"), "8081") {
92+
for _, metric := range getMetricsFromPod(ctx.Ctx().KubeClient(), getPodWithLabel(ctx.Ctx().KubeClient(), "app=catalog-operator")) {
9393
if metric.Family == "installplan_warnings_total" {
9494
counter = metric.Value
9595
}
@@ -189,7 +189,7 @@ var _ = Describe("Install Plan", func() {
189189

190190
It("increments a metric counting the warning", func() {
191191
Eventually(func() []Metric {
192-
return getMetricsFromPod(ctx.Ctx().KubeClient(), getPodWithLabel(ctx.Ctx().KubeClient(), "app=catalog-operator"), "8081")
192+
return getMetricsFromPod(ctx.Ctx().KubeClient(), getPodWithLabel(ctx.Ctx().KubeClient(), "app=catalog-operator"))
193193
}).Should(ContainElement(LikeMetric(
194194
WithFamily("installplan_warnings_total"),
195195
WithValueGreaterThan(counter),

Diff for: staging/operator-lifecycle-manager/test/e2e/metrics_e2e_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"regexp"
11+
"strconv"
1112
"strings"
1213
"sync"
1314

@@ -79,7 +80,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
7980

8081
It("generates csv_abnormal metric for OLM pod", func() {
8182

82-
Expect(getMetricsFromPod(c, getPodWithLabel(c, "app=olm-operator"), "8081")).To(And(
83+
Expect(getMetricsFromPod(c, getPodWithLabel(c, "app=olm-operator"))).To(And(
8384
ContainElement(LikeMetric(
8485
WithFamily("csv_abnormal"),
8586
WithName(failingCSV.Name),
@@ -107,7 +108,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
107108

108109
It("deletes its associated CSV metrics", func() {
109110
// 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(
111112
ContainElement(LikeMetric(WithFamily("csv_abnormal"), WithName(failingCSV.Name))),
112113
ContainElement(LikeMetric(WithFamily("csv_succeeded"), WithName(failingCSV.Name))),
113114
))
@@ -179,7 +180,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
179180

180181
// Verify metrics have been emitted for subscription
181182
Eventually(func() []Metric {
182-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
183+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
183184
}).Should(ContainElement(LikeMetric(
184185
WithFamily("subscription_sync_total"),
185186
WithName("metric-subscription-for-create"),
@@ -194,7 +195,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
194195
// Verify metrics have been emitted for dependency resolution
195196
Eventually(func() bool {
196197
return Eventually(func() []Metric {
197-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
198+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
198199
}).Should(ContainElement(LikeMetric(
199200
WithFamily("olm_resolution_duration_seconds"),
200201
WithLabel("outcome", "failed"),
@@ -209,7 +210,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
209210
BeforeEach(func() {
210211
subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, testNamespace, "metric-subscription-for-update", testPackageName, stableChannel, v1alpha1.ApprovalManual)
211212
Eventually(func() []Metric {
212-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
213+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
213214
}).Should(ContainElement(LikeMetric(WithFamily("subscription_sync_total"), WithLabel("name", "metric-subscription-for-update"))))
214215
Eventually(func() error {
215216
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() {
230231

231232
It("deletes the old Subscription metric and emits the new metric", func() {
232233
Eventually(func() []Metric {
233-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
234+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
234235
}).Should(And(
235236
Not(ContainElement(LikeMetric(
236237
WithFamily("subscription_sync_total"),
@@ -264,7 +265,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
264265

265266
It("deletes the old subscription metric and emits the new metric(there is only one metric for the subscription)", func() {
266267
Eventually(func() []Metric {
267-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
268+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
268269
}).Should(And(
269270
Not(ContainElement(LikeMetric(
270271
WithFamily("subscription_sync_total"),
@@ -294,7 +295,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
294295
BeforeEach(func() {
295296
subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, testNamespace, "metric-subscription-for-delete", testPackageName, stableChannel, v1alpha1.ApprovalManual)
296297
Eventually(func() []Metric {
297-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
298+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
298299
}).Should(ContainElement(LikeMetric(WithFamily("subscription_sync_total"), WithLabel("name", "metric-subscription-for-delete"))))
299300
if subscriptionCleanup != nil {
300301
subscriptionCleanup()
@@ -310,7 +311,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
310311

311312
It("deletes the Subscription metric", func() {
312313
Eventually(func() []Metric {
313-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
314+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
314315
}).ShouldNot(ContainElement(LikeMetric(WithFamily("subscription_sync_total"), WithName("metric-subscription-for-delete"))))
315316
})
316317
})
@@ -353,7 +354,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
353354
})
354355
It("emits metrics for the catalogSource", func() {
355356
Eventually(func() []Metric {
356-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
357+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
357358
}).Should(And(
358359
ContainElement(LikeMetric(
359360
WithFamily("catalog_source_count"),
@@ -373,7 +374,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
373374
})
374375
It("deletes the metrics for the CatalogSource", func() {
375376
Eventually(func() []Metric {
376-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
377+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
377378
}).Should(And(
378379
Not(ContainElement(LikeMetric(
379380
WithFamily("catalogsource_ready"),
@@ -397,7 +398,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
397398
})
398399
It("emits metrics for the CatlogSource with a Value greater than 0", func() {
399400
Eventually(func() []Metric {
400-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
401+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
401402
}).Should(And(
402403
ContainElement(LikeMetric(
403404
WithFamily("catalogsource_ready"),
@@ -407,7 +408,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
407408
)),
408409
))
409410
Consistently(func() []Metric {
410-
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"), "8081")
411+
return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator"))
411412
}, "3m").Should(And(
412413
ContainElement(LikeMetric(
413414
WithFamily("catalogsource_ready"),
@@ -514,14 +515,13 @@ func getMetricsFromPod(client operatorclient.ClientInterface, pod *corev1.Pod) [
514515
scheme = "http"
515516
}
516517
ctx.Ctx().Logf("Retrieving metrics using scheme %v\n", scheme)
517-
518518
mfs := make(map[string]*io_prometheus_client.MetricFamily)
519519
EventuallyWithOffset(1, func() error {
520520
raw, err := client.KubernetesInterface().CoreV1().RESTClient().Get().
521521
Namespace(pod.GetNamespace()).
522522
Resource("pods").
523523
SubResource("proxy").
524-
Name(net.JoinSchemeNamePort(scheme, pod.GetName(), port)).
524+
Name(net.JoinSchemeNamePort(scheme, pod.GetName(), extractMetricPortFromPod(pod))).
525525
Suffix("metrics").
526526
Do(context.Background()).Raw()
527527
if err != nil {

0 commit comments

Comments
 (0)