Skip to content

Commit a9a621b

Browse files
committed
Add e2e test for extra labels
Signed-off-by: Praful Khanduri <[email protected]>
1 parent 537cf33 commit a9a621b

File tree

15 files changed

+379
-10
lines changed

15 files changed

+379
-10
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Add support for extraLabels in ServiceMonitor creation
9+
10+
# One or more tracking issues related to the change
11+
issues: [4138]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
Added extraLabels field to MetricsConfigSpec in v1beta1 API to allow custom labels on ServiceMonitor resources.
18+
This enables users to add additional labels to ServiceMonitors created by the operator for better organization and filtering.

bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2025-07-09T10:15:03Z"
102+
createdAt: "2025-07-11T06:10:34Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
@@ -513,6 +513,8 @@ spec:
513513
- --zap-log-level=info
514514
- --zap-time-encoding=rfc3339nano
515515
- --enable-nginx-instrumentation=true
516+
- --target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.129.1-12-g537cf331
517+
- --operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.129.1-12-g537cf331
516518
env:
517519
- name: SERVICE_ACCOUNT_NAME
518520
valueFrom:

bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ metadata:
9999
categories: Logging & Tracing,Monitoring
100100
certified: "false"
101101
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
102-
createdAt: "2025-07-09T10:15:03Z"
102+
createdAt: "2025-07-11T06:10:34Z"
103103
description: Provides the OpenTelemetry components, including the Collector
104104
operators.operatorframework.io/builder: operator-sdk-v1.29.0
105105
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3

internal/manifests/collector/servicemonitor.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func createServiceMonitor(name string, params manifests.Params, serviceType Serv
5050

5151
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{})
5252
// Add extra labels to the ServiceMonitor
53-
addExtraLabels(&labels, params.OtelCol.Spec.Observability.Metrics.ExtraLabels)
53+
addExtraLabels(&params.Log, &labels, params.OtelCol.Spec.Observability.Metrics.ExtraLabels)
5454
selectorLabels := manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector)
5555
// This label is the one which differentiates the services
5656
selectorLabels[serviceTypeLabel] = serviceType.String()
@@ -115,8 +115,13 @@ func endpointsFromConfig(logger logr.Logger, otelcol v1beta1.OpenTelemetryCollec
115115
}
116116

117117
// addExtraLabels adds extra labels to the ServiceMonitor labels map.
118-
func addExtraLabels(labels *map[string]string, extraLabels map[string]string) {
118+
func addExtraLabels(logger *logr.Logger, labels *map[string]string, extraLabels map[string]string) {
119119
for k, v := range extraLabels {
120+
if existingValue, exists := (*labels)[k]; exists {
121+
if existingValue != v {
122+
logger.Info("Overwriting label", "label", k, "old value", existingValue, "new value", v)
123+
}
124+
}
120125
(*labels)[k] = v
121126
}
122127
}

tests/e2e-prometheuscr/create-sm-prometheus-exporters/01-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -24,5 +30,5 @@ spec:
2430
service:
2531
pipelines:
2632
metrics:
27-
receivers: [otlp]
33+
receivers: [otlp, prometheus]
2834
exporters: [prometheus/dev, prometheus/prod]

tests/e2e-prometheuscr/create-sm-prometheus-exporters/02-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -21,5 +27,5 @@ spec:
2127
service:
2228
pipelines:
2329
metrics:
24-
receivers: [otlp]
30+
receivers: [otlp, prometheus]
2531
exporters: [prometheus/prod]

tests/e2e-prometheuscr/create-sm-prometheus-exporters/03-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -21,5 +27,5 @@ spec:
2127
service:
2228
pipelines:
2329
metrics:
24-
receivers: [otlp]
30+
receivers: [otlp, prometheus]
2531
exporters: [prometheus/prod]

tests/e2e-prometheuscr/create-sm-prometheus-exporters/04-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -21,5 +27,5 @@ spec:
2127
service:
2228
pipelines:
2329
metrics:
24-
receivers: [otlp]
30+
receivers: [otlp, prometheus]
2531
exporters: [prometheus/prod]

tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -27,5 +33,5 @@ spec:
2733
service:
2834
pipelines:
2935
metrics:
30-
receivers: [otlp]
36+
receivers: [otlp, prometheus]
3137
exporters: [prometheus/dev, prometheus/prod, prometheusremotewrite/prometheus]

tests/e2e-prometheuscr/create-sm-prometheus-exporters/06-install.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
protocols:
1414
grpc:
1515
http:
16+
prometheus:
17+
config:
18+
scrape_configs:
19+
- job_name: 'test-job'
20+
static_configs:
21+
- targets: ['localhost:9090']
1622
1723
exporters:
1824
prometheus/prod:
@@ -24,5 +30,5 @@ spec:
2430
service:
2531
pipelines:
2632
metrics:
27-
receivers: [otlp]
33+
receivers: [otlp, prometheus]
2834
exporters: [prometheus/dev]

0 commit comments

Comments
 (0)