From dbd80f0e627e6225a6197b12d46040bad3832ba8 Mon Sep 17 00:00:00 2001 From: chaitanyaphalak Date: Thu, 4 Nov 2021 09:42:39 -0700 Subject: [PATCH] add support for pod and namespace labels and annotations --- .../splunk-otel-collector/templates/NOTES.txt | 3 +++ .../templates/config/_common.tpl | 19 +++++++++++++++++++ .../templates/config/_otel-agent.tpl | 8 ++------ .../templates/config/_otel-collector.tpl | 8 ++------ .../splunk-otel-collector/values.schema.json | 12 ++++++++++++ helm-charts/splunk-otel-collector/values.yaml | 17 +++++++++++++---- 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/helm-charts/splunk-otel-collector/templates/NOTES.txt b/helm-charts/splunk-otel-collector/templates/NOTES.txt index e4c34b6dc8..6a1091a560 100644 --- a/helm-charts/splunk-otel-collector/templates/NOTES.txt +++ b/helm-charts/splunk-otel-collector/templates/NOTES.txt @@ -33,3 +33,6 @@ Splunk OpenTelemetry Connector is installed and configured to send data to Splun [WARNING] "logsEnabled" parameter is deprecated, please use "splunkObservability.logsEnabled" instead. Upgrade guidelines: https://github.com/signalfx/splunk-otel-collector-chart/blob/main/UPGRADING.md#0353-to-0360 {{ end }} +{{- if not (eq (toString .Values.extraAttributes.podLabels) "") }} +[WARNING] ".Values.extraAttributes.podLabels" parameter is deprecated, please use ".Values.extraAttributes.fromLabels" instead. +{{ end }} diff --git a/helm-charts/splunk-otel-collector/templates/config/_common.tpl b/helm-charts/splunk-otel-collector/templates/config/_common.tpl index 724831fcd9..df54eef949 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_common.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_common.tpl @@ -217,3 +217,22 @@ splunk_hec/platform_metrics: ca_file: /otel/etc/splunk_platform_hec_ca_file {{- end }} {{- end }} + +{{/* +Add Extra Labels +*/}} +{{- define "splunk-otel-collector.addExtraLabels" -}} +labels: +{{- 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 1986096575..071fc034d1 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl @@ -282,12 +282,8 @@ processors: - key: splunk.com/index tag_name: com.splunk.index from: pod - {{- with .Values.extraAttributes.podLabels }} - labels: - {{- range . }} - - key: {{ . }} - {{- end }} - {{- end }} + {{- include "splunk-otel-collector.addExtraAnnotations" . | nindent 8 }} + {{- include "splunk-otel-collector.addExtraLabels" . | nindent 6 }} {{- if eq .Values.logsEngine "fluentd" }} # Move flat fluentd logs attributes to resource attributes 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 ed32df3f09..77bb89f194 100644 --- a/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl +++ b/helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl @@ -65,12 +65,8 @@ processors: - key: splunk.com/index tag_name: com.splunk.index from: pod - {{- with .Values.extraAttributes.podLabels }} - labels: - {{- range . }} - - key: {{ . }} - {{- end }} - {{- end }} + {{- include "splunk-otel-collector.addExtraAnnotations" . | nindent 8 }} + {{- include "splunk-otel-collector.addExtraLabels" . | nindent 6 }} {{- include "splunk-otel-collector.resourceLogsProcessor" . | nindent 2 }} {{- include "splunk-otel-collector.filterLogsProcessors" . | nindent 2 }} diff --git a/helm-charts/splunk-otel-collector/values.schema.json b/helm-charts/splunk-otel-collector/values.schema.json index b6cbeaab7e..ea567384e7 100644 --- a/helm-charts/splunk-otel-collector/values.schema.json +++ b/helm-charts/splunk-otel-collector/values.schema.json @@ -223,6 +223,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 c238aec174..d022715908 100644 --- a/helm-charts/splunk-otel-collector/values.yaml +++ b/helm-charts/splunk-otel-collector/values.yaml @@ -162,10 +162,19 @@ 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 namespaces (in case they are set) + # and added as extra attributes to the telemetry in the following format: + # k8s.namespace.labels.: + fromLabels: + - key: app + + # Annotations 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.annotations.: + # Annotations that will be collected from k8s namespaces (in case they are set) + # and added as extra attributes to the telemetry in the following format: + # k8s.namespace.annotations.: + fromAnnotations: [] # List of hardcoded key/value pairs that will be added as attributes to # all the telemetry.