From e6e4a574cbeba291217118685b38caecb4187a7f Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Tue, 25 Jun 2024 17:34:38 +0530 Subject: [PATCH] feat(k8s-infra): introduce deployment.environment global var (#456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(k8s-infra): introduce deployment.environment global var * chore(release): 🔖 Bump up k8s-infra to 0.11.6 --------- Signed-off-by: Prashant Shahi --- charts/k8s-infra/Chart.yaml | 2 +- charts/k8s-infra/templates/_config.tpl | 32 +++++++++++++++++++ charts/k8s-infra/templates/_helpers.tpl | 6 ++++ .../templates/otel-agent/daemonset.yaml | 2 -- .../templates/otel-deployment/deployment.yaml | 2 -- charts/k8s-infra/values.yaml | 2 ++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/charts/k8s-infra/Chart.yaml b/charts/k8s-infra/Chart.yaml index 2472b581..2a477e10 100644 --- a/charts/k8s-infra/Chart.yaml +++ b/charts/k8s-infra/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: k8s-infra description: Helm chart for collecting metrics and logs in K8s type: application -version: 0.11.5 +version: 0.11.6 appVersion: "0.88.0" home: https://signoz.io icon: https://signoz.io/img/SigNozLogo-orange.svg diff --git a/charts/k8s-infra/templates/_config.tpl b/charts/k8s-infra/templates/_config.tpl index 2f2fb76b..a32ddee6 100644 --- a/charts/k8s-infra/templates/_config.tpl +++ b/charts/k8s-infra/templates/_config.tpl @@ -37,6 +37,9 @@ Build config file for daemonset OpenTelemetry Collector: OtelAgent {{- if .Values.presets.resourceDetectionInternal.enabled }} {{- $config = (include "opentelemetry-collector.applyResourceDetectionInternalConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} +{{- if .Values.global.deploymentEnvironment }} +{{- $config = (include "opentelemetry-collector.applyDeploymentEnvironmentConfig" (dict "Values" $data "config" $config) | fromYaml) }} +{{- end }} {{- if .Values.presets.loggingExporter.enabled }} {{- $config = (include "opentelemetry-collector.applyLoggingExporterConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} @@ -68,6 +71,9 @@ Build config file for deployment OpenTelemetry Collector: OtelDeployment {{- if .Values.presets.resourceDetectionInternal.enabled }} {{- $config = (include "opentelemetry-collector.applyResourceDetectionInternalConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} +{{- if .Values.global.deploymentEnvironment }} +{{- $config = (include "opentelemetry-collector.applyDeploymentEnvironmentConfig" (dict "Values" $data "config" $config) | fromYaml) }} +{{- end }} {{- if .Values.presets.clusterMetrics.enabled }} {{- $config = (include "opentelemetry-collector.applyClusterMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }} {{- end }} @@ -358,3 +364,29 @@ processors: timeout: {{ .Values.presets.resourceDetectionInternal.timeout }} override: {{ .Values.presets.resourceDetectionInternal.override }} {{- end }} + +{{- define "opentelemetry-collector.applyDeploymentEnvironmentConfig" -}} +{{- $config := mustMergeOverwrite (include "opentelemetry-collector.deploymentEnvironmentConfig" .Values | fromYaml) .config }} +{{- if $config.service.pipelines.logs }} +{{- $_ := set $config.service.pipelines.logs "processors" (prepend $config.service.pipelines.logs.processors "resource/deployenv" | uniq) }} +{{- end }} +{{- if $config.service.pipelines.metrics }} +{{- $_ := set $config.service.pipelines.metrics "processors" (prepend $config.service.pipelines.metrics.processors "resource/deployenv" | uniq) }} +{{- end }} +{{- if $config.service.pipelines.traces }} +{{- $_ := set $config.service.pipelines.traces "processors" (prepend $config.service.pipelines.traces.processors "resource/deployenv" | uniq) }} +{{- end }} +{{- if index $config.service.pipelines "metrics/internal" }} +{{- $_ := set (index $config.service.pipelines "metrics/internal") "processors" (prepend (index (index $config.service.pipelines "metrics/internal") "processors") "resource/deployenv" | uniq) }} +{{- end }} +{{- $config | toYaml }} +{{- end }} + +{{- define "opentelemetry-collector.deploymentEnvironmentConfig" -}} +processors: + resource/deployenv: + attributes: + - key: deployment.environment + value: ${env:DEPLOYMENT_ENVIRONMENT} + action: insert +{{- end }} diff --git a/charts/k8s-infra/templates/_helpers.tpl b/charts/k8s-infra/templates/_helpers.tpl index ddd664a6..610ece89 100644 --- a/charts/k8s-infra/templates/_helpers.tpl +++ b/charts/k8s-infra/templates/_helpers.tpl @@ -412,6 +412,12 @@ OTLP exporter environment variables used by OtelAgent and OtelDeployment. value: {{ include "otel.insecureSkipVerify" . }} - name: OTEL_SECRETS_PATH value: {{ include "otel.secretsPath" . }} +- name: K8S_CLUSTER_NAME + value: {{ default .Values.global.clusterName .Values.clusterName }} +{{- with .Values.global.deploymentEnvironment }} +- name: DEPLOYMENT_ENVIRONMENT + value: {{ . }} +{{- end }} {{- end }} {{/* diff --git a/charts/k8s-infra/templates/otel-agent/daemonset.yaml b/charts/k8s-infra/templates/otel-agent/daemonset.yaml index 1e0b2131..c9cfd76e 100644 --- a/charts/k8s-infra/templates/otel-agent/daemonset.yaml +++ b/charts/k8s-infra/templates/otel-agent/daemonset.yaml @@ -93,8 +93,6 @@ spec: env: {{- include "snippet.otlp-env" . | nindent 12 }} {{- include "snippet.k8s-env" . | nindent 12 }} - - name: K8S_CLUSTER_NAME - value: {{ default .Values.global.clusterName .Values.clusterName }} - name: SIGNOZ_COMPONENT value: {{ default "otel-agent" .Values.otelAgent.name }} - name: OTEL_RESOURCE_ATTRIBUTES diff --git a/charts/k8s-infra/templates/otel-deployment/deployment.yaml b/charts/k8s-infra/templates/otel-deployment/deployment.yaml index bd64de79..c7ca923c 100644 --- a/charts/k8s-infra/templates/otel-deployment/deployment.yaml +++ b/charts/k8s-infra/templates/otel-deployment/deployment.yaml @@ -86,8 +86,6 @@ spec: env: {{- include "snippet.otlp-env" . | nindent 12 }} {{- include "snippet.k8s-env" . | nindent 12 }} - - name: K8S_CLUSTER_NAME - value: {{ default .Values.global.clusterName .Values.clusterName }} - name: SIGNOZ_COMPONENT value: {{ default "otel-deployment" .Values.otelDeployment.name }} - name: OTEL_RESOURCE_ATTRIBUTES diff --git a/charts/k8s-infra/values.yaml b/charts/k8s-infra/values.yaml index ea86151d..109dcce0 100644 --- a/charts/k8s-infra/values.yaml +++ b/charts/k8s-infra/values.yaml @@ -12,6 +12,8 @@ global: # -- Kubernetes cluster name # It is used to attached to telemetry data via resource detection processor clusterName: "" + # -- Deployment environment to be attached to telemetry data + deploymentEnvironment: "" # -- Kubernetes cluster cloud provider along with distribution if any. # example: `aws`, `azure`, `gcp`, `gcp/autogke`, `hcloud`, `other` cloud: other