From 131f5b5fde0efa7305d7a24e6ac9bb0d2c517e1b Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Sun, 22 Jun 2025 21:29:15 +0200 Subject: [PATCH 1/3] fix: e2e test checks label value by name and not by index Signed-off-by: Jorge Turrado --- tests/helper/helper.go | 10 ++++++++++ .../opentelemetry_metrics_test.go | 16 ++++++++-------- .../prometheus_metrics_test.go | 16 ++++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/helper/helper.go b/tests/helper/helper.go index 90d12f6f2dc..0e5b61586bb 100644 --- a/tests/helper/helper.go +++ b/tests/helper/helper.go @@ -26,6 +26,7 @@ import ( "time" "github.com/joho/godotenv" + prommodel "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" autoscalingv2 "k8s.io/api/autoscaling/v2" @@ -1145,3 +1146,12 @@ func WatchForEventAfterTrigger( assert.Fail(t, "Timed out waiting for result from Kubernetes event watch channel") } } + +func ExtractPrometheusLabelValue(key string, labels []*prommodel.LabelPair) string { + for _, label := range labels { + if label.Name != nil && *label.Name == key { + return *label.Value + } + } + return "" +} diff --git a/tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go b/tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go index 7a9bbd16ea0..c828c3fbad2 100644 --- a/tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go +++ b/tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go @@ -1213,10 +1213,10 @@ func testCloudEventEmitted(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 5 && - *labels[0].Value == "opentelemetry-metrics-test-ce" && - *labels[1].Value == "http" && - *labels[3].Value == "opentelemetry-metrics-test-ns" && - *labels[4].Value == "emitted" { + ExtractPrometheusLabelValue("cloudEventSource", labels) == "opentelemetry-metrics-test-ce" && + ExtractPrometheusLabelValue("eventsink", labels) == "http" && + ExtractPrometheusLabelValue("namespace", labels) == "opentelemetry-metrics-test-ns" && + ExtractPrometheusLabelValue("state", labels) == "emitted" { assert.GreaterOrEqual(t, *metric.Counter.Value, float64(1)) found = true } @@ -1245,10 +1245,10 @@ func testCloudEventEmittedError(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 5 && - *labels[0].Value == "opentelemetry-metrics-test-ce-w" && - *labels[1].Value == "http" && - *labels[3].Value == "opentelemetry-metrics-test-ns" && - *labels[4].Value == "failed" { + ExtractPrometheusLabelValue("cloudEventSource", labels) == "opentelemetry-metrics-test-ce-w" && + ExtractPrometheusLabelValue("eventsink", labels) == "http" && + ExtractPrometheusLabelValue("namespace", labels) == "opentelemetry-metrics-test-ns" && + ExtractPrometheusLabelValue("state", labels) == "failed" { assert.GreaterOrEqual(t, *metric.Counter.Value, float64(5)) found = true } diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index 51ffa91bc19..6e3f78e45fe 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -1361,10 +1361,10 @@ func testCloudEventEmitted(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 4 && - *labels[0].Value == "prometheus-metrics-test-ce" && - *labels[1].Value == "http" && - *labels[2].Value == "prometheus-metrics-test-ns" && - *labels[3].Value == "emitted" { + ExtractPrometheusLabelValue("cloudEventSource", labels) == "prometheus-metrics-test-ce" && + ExtractPrometheusLabelValue("eventsink", labels) == "http" && + ExtractPrometheusLabelValue("namespace", labels) == "prometheus-metrics-test-ns" && + ExtractPrometheusLabelValue("state", labels) == "emitted" { assert.GreaterOrEqual(t, *metric.Counter.Value, float64(1)) found = true } @@ -1393,10 +1393,10 @@ func testCloudEventEmittedError(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 4 && - *labels[0].Value == "prometheus-metrics-test-ce-w" && - *labels[1].Value == "http" && - *labels[2].Value == "prometheus-metrics-test-ns" && - *labels[3].Value == "failed" { + ExtractPrometheusLabelValue("cloudEventSource", labels) == "prometheus-metrics-test-ce-w" && + ExtractPrometheusLabelValue("eventsink", labels) == "http" && + ExtractPrometheusLabelValue("namespace", labels) == "prometheus-metrics-test-ns" && + ExtractPrometheusLabelValue("state", labels) == "failed" { assert.GreaterOrEqual(t, *metric.Counter.Value, float64(5)) found = true } From 0d5097cc710328982b46bba90bde98c029a58f9c Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Sun, 22 Jun 2025 23:25:34 +0200 Subject: [PATCH 2/3] fix: e2e test checks label value by name and not by index Signed-off-by: Jorge Turrado --- tests/sequential/prometheus_metrics/prometheus_metrics_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index 6e3f78e45fe..d46e0abd32b 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -1361,7 +1361,7 @@ func testCloudEventEmitted(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 4 && - ExtractPrometheusLabelValue("cloudEventSource", labels) == "prometheus-metrics-test-ce" && + ExtractPrometheusLabelValue("cloudeventsource", labels) == "prometheus-metrics-test-ce" && ExtractPrometheusLabelValue("eventsink", labels) == "http" && ExtractPrometheusLabelValue("namespace", labels) == "prometheus-metrics-test-ns" && ExtractPrometheusLabelValue("state", labels) == "emitted" { From 030022201afd8a25a08d360724d58c363bcd876d Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Mon, 23 Jun 2025 22:34:53 +0200 Subject: [PATCH 3/3] fix: e2e test checks label value by name and not by index Signed-off-by: Jorge Turrado --- tests/sequential/prometheus_metrics/prometheus_metrics_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index d46e0abd32b..ac641b844fb 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -1393,7 +1393,7 @@ func testCloudEventEmittedError(t *testing.T, data templateData) { for _, metric := range metrics { labels := metric.GetLabel() if len(labels) >= 4 && - ExtractPrometheusLabelValue("cloudEventSource", labels) == "prometheus-metrics-test-ce-w" && + ExtractPrometheusLabelValue("cloudeventsource", labels) == "prometheus-metrics-test-ce-w" && ExtractPrometheusLabelValue("eventsink", labels) == "http" && ExtractPrometheusLabelValue("namespace", labels) == "prometheus-metrics-test-ns" && ExtractPrometheusLabelValue("state", labels) == "failed" {