From 1558b3abfa1ce88ca0c51336f940ca26528fca30 Mon Sep 17 00:00:00 2001 From: Chaitanya Phalak Date: Wed, 17 Nov 2021 11:37:46 -0800 Subject: [PATCH] Fetch all attributes (#273) --- UPGRADING.md | 5 +++ .../splunk-otel-collector/templates/NOTES.txt | 4 +++ .../templates/config/_common.tpl | 18 +++++++++++ .../templates/config/_otel-agent.tpl | 6 ++-- .../templates/config/_otel-collector.tpl | 6 ++-- .../splunk-otel-collector/values.schema.json | 12 +++++++ helm-charts/splunk-otel-collector/values.yaml | 31 ++++++++++++++----- 7 files changed, 71 insertions(+), 11 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index cbd56b0274..457155b4f0 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -16,6 +16,11 @@ If you provide access token for Splunk Observability using a custom Kubernetes secret (secter.create=false), please update the secret name from `splunk_o11y_access_token` to `splunk_observability_access_token` +[#273 Changed configuration to fetch attributes from labels and annotations of pods and namespaces](https://github.com/signalfx/splunk-otel-collector-chart/pull/273) + +The following parameter `podLabels` under the `extraAttributes` group is changed to `fromLabels` +This parameter needs to be updated in your custom values.yaml + ## 0.36.2 to 0.37.0 [#232 Access to underlying node's filesystem was reduced to the minimum scope diff --git a/helm-charts/splunk-otel-collector/templates/NOTES.txt b/helm-charts/splunk-otel-collector/templates/NOTES.txt index 20fd253dfe..6ec253d061 100644 --- a/helm-charts/splunk-otel-collector/templates/NOTES.txt +++ b/helm-charts/splunk-otel-collector/templates/NOTES.txt @@ -41,3 +41,7 @@ Splunk OpenTelemetry Connector is installed and configured to send data to Splun [WARNING] "provider" parameter is deprecated, please use "cloudProvider" instead. Upgrade guidelines: https://github.com/signalfx/splunk-otel-collector-chart/blob/main/UPGRADING.md#0371-to-0380 {{ end }} +{{- if not (eq (toString .Values.extraAttributes.podLabels) "") }} +[WARNING] ".Values.extraAttributes.podLabels" parameter is deprecated, please use ".Values.extraAttributes.fromLabels" instead. + Upgrade guidelines: https://github.com/signalfx/splunk-otel-collector-chart/blob/main/UPGRADING.md#0371-to-0380 +{{ end }} diff --git a/helm-charts/splunk-otel-collector/templates/config/_common.tpl b/helm-charts/splunk-otel-collector/templates/config/_common.tpl index 701466fa83..a316a7e4da 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_common.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_common.tpl @@ -228,3 +228,21 @@ splunk_hec/platform_metrics: ca_file: /otel/etc/splunk_platform_hec_ca_file {{- end }} {{- end }} + +{{/* +Add Extra Labels +*/}} +{{- define "splunk-otel-collector.addExtraLabels" -}} +{{- with .Values.extraAttributes.fromLabels }} +{{ . | toYaml}} +{{- end }} +{{- end }} + +{{/* +Add Extra Annotations +*/}} +{{- define "splunk-otel-collector.addExtraAnnotations" -}} +{{- with .Values.extraAttributes.fromAnnotations }} +{{ . | toYaml}} +{{- end }} +{{- end }} diff --git a/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl b/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl index 579b6d4faa..dec1eed8ec 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl @@ -282,11 +282,13 @@ processors: - key: splunk.com/index tag_name: com.splunk.index from: pod - {{- with .Values.extraAttributes.podLabels }} + {{- include "splunk-otel-collector.addExtraAnnotations" . | nindent 8 }} + {{- if or .Values.extraAttributes.podLabels .Values.extraAttributes.fromLabels }} labels: - {{- range . }} + {{- range .Values.extraAttributes.podLabels }} - key: {{ . }} {{- end }} + {{- include "splunk-otel-collector.addExtraLabels" . | nindent 8 }} {{- end }} {{- if eq .Values.logsEngine "fluentd" }} diff --git a/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl b/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl index a6ad44b3ba..682c936ed8 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl @@ -65,11 +65,13 @@ processors: - key: splunk.com/index tag_name: com.splunk.index from: pod - {{- with .Values.extraAttributes.podLabels }} + {{- include "splunk-otel-collector.addExtraAnnotations" . | nindent 8 }} + {{- if or .Values.extraAttributes.podLabels .Values.extraAttributes.fromLabels }} labels: - {{- range . }} + {{- range .Values.extraAttributes.podLabels }} - key: {{ . }} {{- end }} + {{- include "splunk-otel-collector.addExtraLabels" . | nindent 8 }} {{- end }} {{- include "splunk-otel-collector.resourceLogsProcessor" . | nindent 2 }} diff --git a/helm-charts/splunk-otel-collector/values.schema.json b/helm-charts/splunk-otel-collector/values.schema.json index 07864d65f9..483276c7ae 100644 --- a/helm-charts/splunk-otel-collector/values.schema.json +++ b/helm-charts/splunk-otel-collector/values.schema.json @@ -234,6 +234,18 @@ "type": "string" } }, + "fromLabels": { + "type": "array", + "items": { + "type": "object" + } + }, + "fromAnnotations": { + "type": "array", + "items": { + "type": "object" + } + }, "custom": { "type": "array", "items": { diff --git a/helm-charts/splunk-otel-collector/values.yaml b/helm-charts/splunk-otel-collector/values.yaml index bd37f9e7d8..566aea0133 100644 --- a/helm-charts/splunk-otel-collector/values.yaml +++ b/helm-charts/splunk-otel-collector/values.yaml @@ -159,13 +159,30 @@ autodetect: extraAttributes: - # Labels that will be collected from k8s pods (in case they are set) - # and added as extra attributes to the telemetry in the following format: - # k8s.pod.labels.: - podLabels: - - app - # - k8s-app - # - release + # Labels that will be collected from k8s pods (or namespaces) (in case they are set) + # and added as extra attributes to the telemetry in the following format: + # k8s..labels.: + # For example, if you want to collect "my_key" label from your namespaces, you could use the following: + # fromLabels: + # - key: my_key + # from: namespace + # If you want to collect all labels from your pods, you could do that using a `key_regex: .*` option, e.g.: + # fromLabels: + # - key_regex: .* + # from: pod + # If you want to change the default attribute name `k8s.pod.labels.`, you could do that using a `tag_name` field: + # fromLabels: + # - key: my_key + # tag_name: my_tag + # from: pod + fromLabels: + - key: app + + # Annotations that will be collected from k8s pods (or namespaces) (in case they are set) + # and added as extra attributes to the telemetry in the following format: + # k8s..annotations.: + # fromAnnotations uses the same extraction rules as fromLabels option so refer examples from the fromLabels option. + fromAnnotations: [] # List of hardcoded key/value pairs that will be added as attributes to # all the telemetry.