Skip to content

Commit

Permalink
[target allocator] Set the default filter strategy in the CRD (#2515)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm authored Jan 17, 2024
1 parent f7fb840 commit 75da899
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix_filterstrategy-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Set the default filter strategy in the CRD

# One or more tracking issues related to the change
issues: [2477]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
3 changes: 2 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ type OpenTelemetryTargetAllocator struct {
AllocationStrategy OpenTelemetryTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`
// FilterStrategy determines how to filter targets before allocating them among the collectors.
// The only current option is relabel-config (drops targets based on prom relabel_config).
// Filtering is disabled by default.
// The default is relabel-config.
// +optional
// +kubebuilder:default:=relabel-config
FilterStrategy string `json:"filterStrategy,omitempty"`
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
// the operator will not automatically create a ServiceAccount for the TargetAllocator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5178,6 +5178,7 @@ spec:
type: object
type: array
filterStrategy:
default: relabel-config
description: FilterStrategy determines how to filter targets before
allocating them among the collectors. The only current option
is relabel-config (drops targets based on prom relabel_config).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5175,6 +5175,7 @@ spec:
type: object
type: array
filterStrategy:
default: relabel-config
description: FilterStrategy determines how to filter targets before
allocating them among the collectors. The only current option
is relabel-config (drops targets based on prom relabel_config).
Expand Down
10 changes: 7 additions & 3 deletions controllers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,8 @@ service:
Image: "test",
Config: goodConfig,
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
Enabled: true,
Enabled: true,
FilterStrategy: "relabel-config",
PrometheusCR: v1alpha1.OpenTelemetryTargetAllocatorPrometheusCR{
Enabled: true,
},
Expand Down Expand Up @@ -1340,6 +1341,7 @@ config:
source_labels:
- __meta_service_name
target_label: instance
filter_strategy: relabel-config
label_selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: test.test
Expand Down Expand Up @@ -1377,7 +1379,7 @@ label_selector:
"app.kubernetes.io/version": "latest",
},
Annotations: map[string]string{
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
"opentelemetry-targetallocator-config/hash": "bf084cbbdcb09d03a40ad2352e0869ccf75d01f5dec977938b94d5a3239ea491",
},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -1517,6 +1519,7 @@ label_selector:
PrometheusCR: v1alpha1.OpenTelemetryTargetAllocatorPrometheusCR{
Enabled: true,
},
FilterStrategy: "relabel-config",
Observability: v1alpha1.ObservabilitySpec{
Metrics: v1alpha1.MetricsConfigSpec{
EnableMetrics: true,
Expand Down Expand Up @@ -1729,6 +1732,7 @@ config:
source_labels:
- __meta_service_name
target_label: instance
filter_strategy: relabel-config
label_selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: test.test
Expand Down Expand Up @@ -1766,7 +1770,7 @@ label_selector:
"app.kubernetes.io/version": "latest",
},
Annotations: map[string]string{
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
"opentelemetry-targetallocator-config/hash": "bf084cbbdcb09d03a40ad2352e0869ccf75d01f5dec977938b94d5a3239ea491",
},
},
Spec: corev1.PodSpec{
Expand Down
1 change: 1 addition & 0 deletions controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
}
taConfig["config"] = promConfig["config"]
taConfig["allocation_strategy"] = "consistent-hashing"
taConfig["filter_strategy"] = "relabel-config"
taConfig["prometheus_cr"] = map[string]string{
"scrape_interval": "30s",
}
Expand Down
4 changes: 1 addition & 3 deletions internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
taConfig["allocation_strategy"] = v1alpha1.OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing
}

if len(params.OtelCol.Spec.TargetAllocator.FilterStrategy) > 0 {
taConfig["filter_strategy"] = params.OtelCol.Spec.TargetAllocator.FilterStrategy
}
taConfig["filter_strategy"] = params.OtelCol.Spec.TargetAllocator.FilterStrategy

if params.OtelCol.Spec.TargetAllocator.PrometheusCR.ScrapeInterval.Size() > 0 {
prometheusCRConfig["scrape_interval"] = params.OtelCol.Spec.TargetAllocator.PrometheusCR.ScrapeInterval.Duration
Expand Down
3 changes: 3 additions & 0 deletions internal/manifests/targetallocator/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ config:
- targets:
- 0.0.0.0:8888
- 0.0.0.0:9999
filter_strategy: relabel-config
label_selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: default.my-instance
Expand Down Expand Up @@ -96,6 +97,7 @@ config:
- targets:
- 0.0.0.0:8888
- 0.0.0.0:9999
filter_strategy: relabel-config
label_selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: default.my-instance
Expand Down Expand Up @@ -148,6 +150,7 @@ config:
- targets:
- 0.0.0.0:8888
- 0.0.0.0:9999
filter_strategy: relabel-config
label_selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: default.my-instance
Expand Down
3 changes: 2 additions & 1 deletion internal/manifests/targetallocator/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func collectorInstance() v1alpha1.OpenTelemetryCollector {
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0",
Config: string(configYAML),
TargetAllocator: v1alpha1.OpenTelemetryTargetAllocator{
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-targetallocator:0.47.0",
Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-targetallocator:0.47.0",
FilterStrategy: "relabel-config",
},
},
}
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/targetallocator-features/00-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
- "true"
prometheusCR:
enabled: true
filterStrategy: ""
env:
- name: TEST_ENV
value: "test"
Expand Down

0 comments on commit 75da899

Please sign in to comment.