Skip to content

Commit 21cfaa6

Browse files
committed
[feat] Revamp reduced attributes preset
1 parent 54c4fb2 commit 21cfaa6

5 files changed

Lines changed: 147 additions & 64 deletions

File tree

charts/opentelemetry-collector/examples/daemonset-presets/rendered/configmap-agent.yaml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ data:
131131
probabilistic_sampler:
132132
mode: proportional
133133
sampling_percentage: 10
134+
redaction/metrics:
135+
allow_all_keys: false
136+
allowed_keys:
137+
- host.id
138+
- k8s.job.name
139+
- k8s.node.name
140+
- k8s.namespace.name
141+
- k8s.pod.name
142+
- k8s.cronjob.name
143+
- k8s.replicaset.name
144+
- k8s.statefulset.name
145+
- k8s.daemonset.name
146+
summary: silent
134147
resourcedetection/env:
135148
detectors:
136149
- system
@@ -201,24 +214,6 @@ data:
201214
- replace_pattern(attributes["k8s.deployment.name"], "^(.*)-[0-9a-zA-Z]+$",
202215
"$$1") where attributes["k8s.replicaset.name"] != nil
203216
- delete_key(attributes, "k8s.replicaset.name")
204-
transform/reduce:
205-
error_mode: ignore
206-
metric_statements:
207-
- context: resource
208-
statements:
209-
- delete_key(attributes, "container.id")
210-
- delete_key(attributes, "k8s.pod.uid")
211-
- delete_key(attributes, "k8s.replicaset.uid")
212-
- delete_key(attributes, "k8s.daemonset.uid")
213-
- delete_key(attributes, "k8s.deployment.uid")
214-
- delete_key(attributes, "k8s.statefulset.uid")
215-
- delete_key(attributes, "k8s.cronjob.uid")
216-
- delete_key(attributes, "k8s.job.uid")
217-
- delete_key(attributes, "k8s.hpa.uid")
218-
- delete_key(attributes, "k8s.namespace.uid")
219-
- delete_key(attributes, "k8s.node.uid")
220-
- delete_key(attributes, "net.host.name")
221-
- delete_key(attributes, "net.host.port")
222217
transform/span_name:
223218
trace_statements:
224219
- context: span
@@ -477,7 +472,7 @@ data:
477472
- k8sattributes
478473
- transform/k8s_attributes
479474
- filter/k8s_extra_metrics
480-
- transform/reduce
475+
- redaction/metrics
481476
- batch
482477
receivers:
483478
- receiver_creator/mysql

charts/opentelemetry-collector/examples/daemonset-supervisor/rendered/configmap-agent.yaml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ data:
151151
probabilistic_sampler:
152152
mode: proportional
153153
sampling_percentage: 10
154+
redaction/metrics:
155+
allow_all_keys: false
156+
allowed_keys:
157+
- host.id
158+
- k8s.job.name
159+
- k8s.node.name
160+
- k8s.namespace.name
161+
- k8s.pod.name
162+
- k8s.cronjob.name
163+
- k8s.replicaset.name
164+
- k8s.statefulset.name
165+
- k8s.daemonset.name
166+
summary: silent
154167
resourcedetection/env:
155168
detectors:
156169
- system
@@ -240,24 +253,6 @@ data:
240253
== "opentelemetry-collector"
241254
- delete_key(attributes, "otel_scope_name") where attributes["service.name"]
242255
== "opentelemetry-collector"
243-
transform/reduce:
244-
error_mode: ignore
245-
metric_statements:
246-
- context: resource
247-
statements:
248-
- delete_key(attributes, "container.id")
249-
- delete_key(attributes, "k8s.pod.uid")
250-
- delete_key(attributes, "k8s.replicaset.uid")
251-
- delete_key(attributes, "k8s.daemonset.uid")
252-
- delete_key(attributes, "k8s.deployment.uid")
253-
- delete_key(attributes, "k8s.statefulset.uid")
254-
- delete_key(attributes, "k8s.cronjob.uid")
255-
- delete_key(attributes, "k8s.job.uid")
256-
- delete_key(attributes, "k8s.hpa.uid")
257-
- delete_key(attributes, "k8s.namespace.uid")
258-
- delete_key(attributes, "k8s.node.uid")
259-
- delete_key(attributes, "net.host.name")
260-
- delete_key(attributes, "net.host.port")
261256
transform/span_name:
262257
trace_statements:
263258
- context: span
@@ -482,7 +477,7 @@ data:
482477
- k8sattributes
483478
- transform/k8s_attributes
484479
- filter/k8s_extra_metrics
485-
- transform/reduce
480+
- redaction/metrics
486481
- transform/prometheus
487482
- batch
488483
receivers:
@@ -536,3 +531,11 @@ data:
536531
prometheus:
537532
host: ${env:MY_POD_IP}
538533
port: 8888
534+
resource:
535+
cx.agent.type: agent
536+
helm.chart.opentelemetry-collector.version: 0.117.3
537+
k8s.daemonset.name: example-opentelemetry-collector
538+
k8s.namespace.name: default
539+
k8s.node.name: ${env:KUBE_NODE_NAME}
540+
k8s.pod.name: ${env:KUBE_POD_NAME}
541+
service.name: opentelemetry-collector

charts/opentelemetry-collector/templates/_config.tpl

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Build config file for daemonset OpenTelemetry Collector
100100
{{- if and (.Values.presets.fleetManagement.enabled) (not .Values.presets.fleetManagement.supervisor.enabled) }}
101101
{{- $config = (include "opentelemetry-collector.applyFleetManagementConfig" (dict "Values" $data "config" $config) | fromYaml) }}
102102
{{- end }}
103-
{{- if and (.Values.presets.k8sResourceAttributes.enabled) (or (not .Values.presets.fleetManagement.supervisor.enabled) (not .Values.presets.fleetManagement.enabled)) }}
103+
{{- if and (.Values.presets.k8sResourceAttributes.enabled) }}
104104
{{- $config = (include "opentelemetry-collector.applyK8sResourceAttributesConfig" (dict "Values" $data "config" $config) | fromYaml) }}
105105
{{- end }}
106106
{{- if .Values.presets.semconv.enabled }}
@@ -967,35 +967,55 @@ processors:
967967

968968
{{- define "opentelemetry-collector.applyReduceResourceAttributesConfig" -}}
969969
{{- $config := mustMergeOverwrite (include "opentelemetry-collector.reduceResourceAttributesConfig" .Values | fromYaml) .config }}
970-
{{- if and ($config.service.pipelines.metrics) (not (has "transform/reduce" $config.service.pipelines.metrics.processors)) }}
971-
{{- $_ := set $config.service.pipelines.metrics "processors" (append $config.service.pipelines.metrics.processors "transform/reduce" | uniq) }}
970+
{{- $pipelines := .Values.Values.presets.reduceResourceAttributes.pipelines }}
971+
{{- if has "metrics" $pipelines }}
972+
{{- if and ($config.service.pipelines.metrics) (not (has "redaction/metrics" $config.service.pipelines.metrics.processors)) }}
973+
{{- $_ := set $config.service.pipelines.metrics "processors" (append $config.service.pipelines.metrics.processors "redaction/metrics" | uniq) }}
974+
{{- end }}
975+
{{- end }}
976+
{{- if has "traces" $pipelines }}
977+
{{- if and ($config.service.pipelines.traces) (not (has "redaction/traces" $config.service.pipelines.traces.processors)) }}
978+
{{- $_ := set $config.service.pipelines.traces "processors" (append $config.service.pipelines.traces.processors "redaction/traces" | uniq) }}
979+
{{- end }}
980+
{{- end }}
981+
{{- if has "logs" $pipelines }}
982+
{{- if and ($config.service.pipelines.logs) (not (has "redaction/logs" $config.service.pipelines.logs.processors)) }}
983+
{{- $_ := set $config.service.pipelines.logs "processors" (append $config.service.pipelines.logs.processors "redaction/logs" | uniq) }}
984+
{{- end }}
972985
{{- end }}
973986
{{- $config | toYaml }}
974987
{{- end }}
975988

976989
{{- define "opentelemetry-collector.reduceResourceAttributesConfig" -}}
990+
{{- $pipelines := .Values.presets.reduceResourceAttributes.pipelines }}
977991
processors:
978-
transform/reduce:
979-
error_mode: ignore
980-
metric_statements:
981-
- context: resource
982-
statements:
983-
# Removing UIDS from k8scluster / k8sattributes
984-
- delete_key(attributes, "container.id")
985-
- delete_key(attributes, "k8s.pod.uid")
986-
- delete_key(attributes, "k8s.replicaset.uid")
987-
- delete_key(attributes, "k8s.daemonset.uid")
988-
- delete_key(attributes, "k8s.deployment.uid")
989-
- delete_key(attributes, "k8s.statefulset.uid")
990-
- delete_key(attributes, "k8s.cronjob.uid")
991-
- delete_key(attributes, "k8s.job.uid")
992-
- delete_key(attributes, "k8s.hpa.uid")
993-
- delete_key(attributes, "k8s.namespace.uid")
994-
- delete_key(attributes, "k8s.node.uid")
995-
# Removing Prometheus receiver net.host.name + port as it's available in service.instance.id
996-
- delete_key(attributes, "net.host.name")
997-
- delete_key(attributes, "net.host.port")
998-
992+
{{- if has "metrics" $pipelines }}
993+
redaction/metrics:
994+
summary: silent
995+
allow_all_keys: false
996+
allowed_keys:
997+
{{- range $index, $pattern := .Values.presets.reduceResourceAttributes.allowlist.metrics }}
998+
- {{ $pattern }}
999+
{{- end }}
1000+
{{- end }}
1001+
{{- if has "traces" $pipelines }}
1002+
redaction/traces:
1003+
summary: silent
1004+
allow_all_keys: false
1005+
allowed_keys:
1006+
{{- range $index, $pattern := .Values.presets.reduceResourceAttributes.allowlist.traces }}
1007+
- {{ $pattern }}
1008+
{{- end }}
1009+
{{- end }}
1010+
{{- if has "logs" $pipelines }}
1011+
redaction/logs:
1012+
summary: silent
1013+
allow_all_keys: false
1014+
allowed_keys:
1015+
{{- range $index, $pattern := .Values.presets.reduceResourceAttributes.allowlist.logs }}
1016+
- {{ $pattern }}
1017+
{{- end }}
1018+
{{- end }}
9991019
{{- end }}
10001020

10011021
{{- define "opentelemetry-collector.applySemconvConfig" -}}

charts/opentelemetry-collector/values.schema.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,39 @@
864864
"enabled": {
865865
"description": "Specifies whether the collector should drop unneeded resource attributes.",
866866
"type": "boolean"
867+
},
868+
"pipelines": {
869+
"description": "Specifies which pipelines to add the reduce resource attributes processor to.",
870+
"type": "array",
871+
"items": {
872+
"type": "string",
873+
"enum": ["metrics", "traces", "logs"]
874+
}
875+
},
876+
"allowlist": {
877+
"description": "Specifies the allowlist for the reduce resource attributes processor.",
878+
"type": "object",
879+
"additionalProperties": false,
880+
"properties": {
881+
"metrics": {
882+
"type": "array",
883+
"items": {
884+
"type": "string"
885+
}
886+
},
887+
"traces": {
888+
"type": "array",
889+
"items": {
890+
"type": "string"
891+
}
892+
},
893+
"logs": {
894+
"type": "array",
895+
"items": {
896+
"type": "string"
897+
}
898+
}
899+
}
867900
}
868901
}
869902
},

charts/opentelemetry-collector/values.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,42 @@ presets:
352352
enabled: false
353353
waitDuration: 30s
354354

355-
# Removes uids and other uneeded attributes from metric resources.
356-
# This reduces target_info cardinality.
355+
# Only allows a small subset of attributes to be sent to Coralogix.
356+
# It uses an allowlist policy to ensure stability of the set of allowed attributes.
357357
reduceResourceAttributes:
358358
enabled: false
359+
pipelines: ["metrics"]
360+
allowlist:
361+
metrics:
362+
- host.id
363+
- k8s.job.name
364+
- k8s.node.name
365+
- k8s.namespace.name
366+
- k8s.pod.name
367+
- k8s.cronjob.name
368+
- k8s.replicaset.name
369+
- k8s.statefulset.name
370+
- k8s.daemonset.name
371+
traces:
372+
- host.id
373+
- k8s.job.name
374+
- k8s.node.name
375+
- k8s.namespace.name
376+
- k8s.pod.name
377+
- k8s.cronjob.name
378+
- k8s.replicaset.name
379+
- k8s.statefulset.name
380+
- k8s.daemonset.name
381+
logs:
382+
- host.id
383+
- k8s.job.name
384+
- k8s.node.name
385+
- k8s.namespace.name
386+
- k8s.pod.name
387+
- k8s.cronjob.name
388+
- k8s.replicaset.name
389+
- k8s.statefulset.name
390+
- k8s.daemonset.name
359391
# Applies semantic convention transformations.
360392
semconv:
361393
enabled: false

0 commit comments

Comments
 (0)