Skip to content

Commit 46a54c2

Browse files
authored
[target allocator] Set the default filter strategy in the CRD (#2515)
1 parent b630f4c commit 46a54c2

File tree

10 files changed

+35
-8
lines changed

10 files changed

+35
-8
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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. operator, target allocator, github action)
5+
component: target allocator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Set the default filter strategy in the CRD
9+
10+
# One or more tracking issues related to the change
11+
issues: [2477]
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:

apis/v1alpha1/opentelemetrycollector_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ type OpenTelemetryTargetAllocator struct {
308308
AllocationStrategy OpenTelemetryTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`
309309
// FilterStrategy determines how to filter targets before allocating them among the collectors.
310310
// The only current option is relabel-config (drops targets based on prom relabel_config).
311-
// Filtering is disabled by default.
311+
// The default is relabel-config.
312312
// +optional
313+
// +kubebuilder:default:=relabel-config
313314
FilterStrategy string `json:"filterStrategy,omitempty"`
314315
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
315316
// the operator will not automatically create a ServiceAccount for the TargetAllocator.

bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5178,6 +5178,7 @@ spec:
51785178
type: object
51795179
type: array
51805180
filterStrategy:
5181+
default: relabel-config
51815182
description: FilterStrategy determines how to filter targets before
51825183
allocating them among the collectors. The only current option
51835184
is relabel-config (drops targets based on prom relabel_config).

config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5175,6 +5175,7 @@ spec:
51755175
type: object
51765176
type: array
51775177
filterStrategy:
5178+
default: relabel-config
51785179
description: FilterStrategy determines how to filter targets before
51795180
allocating them among the collectors. The only current option
51805181
is relabel-config (drops targets based on prom relabel_config).

controllers/builder_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,8 @@ service:
11291129
Image: "test",
11301130
Config: goodConfig,
11311131
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
1132-
Enabled: true,
1132+
Enabled: true,
1133+
FilterStrategy: "relabel-config",
11331134
PrometheusCR: v1alpha1.OpenTelemetryTargetAllocatorPrometheusCR{
11341135
Enabled: true,
11351136
},
@@ -1340,6 +1341,7 @@ config:
13401341
source_labels:
13411342
- __meta_service_name
13421343
target_label: instance
1344+
filter_strategy: relabel-config
13431345
label_selector:
13441346
app.kubernetes.io/component: opentelemetry-collector
13451347
app.kubernetes.io/instance: test.test
@@ -1377,7 +1379,7 @@ label_selector:
13771379
"app.kubernetes.io/version": "latest",
13781380
},
13791381
Annotations: map[string]string{
1380-
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
1382+
"opentelemetry-targetallocator-config/hash": "bf084cbbdcb09d03a40ad2352e0869ccf75d01f5dec977938b94d5a3239ea491",
13811383
},
13821384
},
13831385
Spec: corev1.PodSpec{
@@ -1517,6 +1519,7 @@ label_selector:
15171519
PrometheusCR: v1alpha1.OpenTelemetryTargetAllocatorPrometheusCR{
15181520
Enabled: true,
15191521
},
1522+
FilterStrategy: "relabel-config",
15201523
Observability: v1alpha1.ObservabilitySpec{
15211524
Metrics: v1alpha1.MetricsConfigSpec{
15221525
EnableMetrics: true,
@@ -1729,6 +1732,7 @@ config:
17291732
source_labels:
17301733
- __meta_service_name
17311734
target_label: instance
1735+
filter_strategy: relabel-config
17321736
label_selector:
17331737
app.kubernetes.io/component: opentelemetry-collector
17341738
app.kubernetes.io/instance: test.test
@@ -1766,7 +1770,7 @@ label_selector:
17661770
"app.kubernetes.io/version": "latest",
17671771
},
17681772
Annotations: map[string]string{
1769-
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
1773+
"opentelemetry-targetallocator-config/hash": "bf084cbbdcb09d03a40ad2352e0869ccf75d01f5dec977938b94d5a3239ea491",
17701774
},
17711775
},
17721776
Spec: corev1.PodSpec{

controllers/reconcile_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
459459
}
460460
taConfig["config"] = promConfig["config"]
461461
taConfig["allocation_strategy"] = "consistent-hashing"
462+
taConfig["filter_strategy"] = "relabel-config"
462463
taConfig["prometheus_cr"] = map[string]string{
463464
"scrape_interval": "30s",
464465
}

internal/manifests/targetallocator/configmap.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
6262
taConfig["allocation_strategy"] = v1alpha1.OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing
6363
}
6464

65-
if len(params.OtelCol.Spec.TargetAllocator.FilterStrategy) > 0 {
66-
taConfig["filter_strategy"] = params.OtelCol.Spec.TargetAllocator.FilterStrategy
67-
}
65+
taConfig["filter_strategy"] = params.OtelCol.Spec.TargetAllocator.FilterStrategy
6866

6967
if params.OtelCol.Spec.TargetAllocator.PrometheusCR.ScrapeInterval.Size() > 0 {
7068
prometheusCRConfig["scrape_interval"] = params.OtelCol.Spec.TargetAllocator.PrometheusCR.ScrapeInterval.Duration

internal/manifests/targetallocator/configmap_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ config:
5454
- targets:
5555
- 0.0.0.0:8888
5656
- 0.0.0.0:9999
57+
filter_strategy: relabel-config
5758
label_selector:
5859
app.kubernetes.io/component: opentelemetry-collector
5960
app.kubernetes.io/instance: default.my-instance
@@ -96,6 +97,7 @@ config:
9697
- targets:
9798
- 0.0.0.0:8888
9899
- 0.0.0.0:9999
100+
filter_strategy: relabel-config
99101
label_selector:
100102
app.kubernetes.io/component: opentelemetry-collector
101103
app.kubernetes.io/instance: default.my-instance
@@ -148,6 +150,7 @@ config:
148150
- targets:
149151
- 0.0.0.0:8888
150152
- 0.0.0.0:9999
153+
filter_strategy: relabel-config
151154
label_selector:
152155
app.kubernetes.io/component: opentelemetry-collector
153156
app.kubernetes.io/instance: default.my-instance

internal/manifests/targetallocator/deployment_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ func collectorInstance() v1alpha1.OpenTelemetryCollector {
188188
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0",
189189
Config: string(configYAML),
190190
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
191-
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-targetallocator:0.47.0",
191+
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-targetallocator:0.47.0",
192+
FilterStrategy: "relabel-config",
192193
},
193194
},
194195
}

tests/e2e/targetallocator-features/00-install.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ spec:
6767
- "true"
6868
prometheusCR:
6969
enabled: true
70+
filterStrategy: ""
7071
env:
7172
- name: TEST_ENV
7273
value: "test"

0 commit comments

Comments
 (0)