Skip to content

Commit

Permalink
Add DD_AGENT_IPC_* env vars (#1661)
Browse files Browse the repository at this point in the history
* Add DD_AGENT_IPC_* env vars

This PR adds DD_AGENT_IPC_PORT and DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL env vars in otel agent and core agent. It does not override them if they are added by the user. This is necessary for the otel-agent to pull the api key from core config in the case where backend secrets are used.

* only add env vars to core agent if otel agent is enabled

* update version

* add test

* move found logic to helpers

* Don't consider user set env varts

* fix test

* update chart
  • Loading branch information
mackjmr authored Feb 6, 2025
1 parent 2b1aea4 commit f7282b2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
4 changes: 4 additions & 0 deletions charts/datadog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Datadog changelog

## 3.90.2

* Adds env vars `DD_AGENT_IPC_PORT` and `DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL` when Otel Agent is enabled and adds flag `--sync-delay=30s` to otel agent.

## 3.90.1

* Add rule to clusterrole to allow the node agent to query the EKS control plane metrics API
Expand Down
2 changes: 1 addition & 1 deletion charts/datadog/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: v1
name: datadog
version: 3.90.1
version: 3.90.2
appVersion: "7"
description: Datadog Agent
keywords:
Expand Down
2 changes: 1 addition & 1 deletion charts/datadog/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Datadog

![Version: 3.90.1](https://img.shields.io/badge/Version-3.90.1-informational?style=flat-square) ![AppVersion: 7](https://img.shields.io/badge/AppVersion-7-informational?style=flat-square)
![Version: 3.90.2](https://img.shields.io/badge/Version-3.90.2-informational?style=flat-square) ![AppVersion: 7](https://img.shields.io/badge/AppVersion-7-informational?style=flat-square)

[Datadog](https://www.datadoghq.com/) is a hosted infrastructure monitoring platform. This chart adds the Datadog Agent to all nodes in your cluster via a DaemonSet. It also optionally depends on the [kube-state-metrics chart](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics). For more information about monitoring Kubernetes with Datadog, please refer to the [Datadog documentation website](https://docs.datadoghq.com/agent/basic_agent_usage/kubernetes/).

Expand Down
6 changes: 6 additions & 0 deletions charts/datadog/templates/_container-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
{{- include "containers-common-env" . | nindent 4 }}
{{- include "fips-envvar" . | nindent 4 }}
{{- include "processes-common-envs" . | nindent 4 }}
{{- if eq (include "should-enable-otel-agent" .) "true" }}
- name: DD_AGENT_IPC_PORT
value: "5009"
- name: DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL
value: "60"
{{- end }}

{{- if .Values.datadog.logLevel }}
- name: DD_LOG_LEVEL
Expand Down
8 changes: 6 additions & 2 deletions charts/datadog/templates/_container-otel-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
image: "{{ include "image-path" (dict "root" .Values "image" .Values.agents.image) }}"
imagePullPolicy: {{ .Values.agents.image.pullPolicy }}
{{- if eq .Values.targetSystem "linux" }}
command: ["otel-agent", "--config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml"]
command: ["otel-agent", "--config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml", "--sync-delay=30s"]
{{- end -}}
{{- if eq .Values.targetSystem "windows" }}
command: ["otel-agent", "-foreground", "-config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml"]
command: ["otel-agent", "-foreground", "-config={{ template "datadog.otelconfPath" . }}/otel-config.yaml", "--core-config={{ template "datadog.confPath" . }}/datadog.yaml", "--sync-delay=30s"]
{{- end -}}
{{ include "generate-security-context" (dict "securityContext" .Values.agents.containers.otelAgent.securityContext "targetSystem" .Values.targetSystem "seccomp" "" "kubeversion" .Capabilities.KubeVersion.Version) | indent 2 }}
resources:
Expand All @@ -32,6 +32,10 @@
env:
{{- include "containers-common-env" . | nindent 4 }}
{{- include "containers-cluster-agent-env" . | nindent 4 }}
- name: DD_AGENT_IPC_PORT
value: "5009"
- name: DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL
value: "60"
{{- include "fips-envvar" . | nindent 4 }}
- name: DD_LOG_LEVEL
value: {{ .Values.agents.containers.otelAgent.logLevel | default .Values.datadog.logLevel | quote }}
Expand Down
2 changes: 0 additions & 2 deletions charts/datadog/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ false
{{- end -}}
{{- end -}}



{{/*
Return secret name to be used based on provided values.
*/}}
Expand Down
75 changes: 75 additions & 0 deletions test/datadog/otel_agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package datadog

import (
"testing"

"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"

"github.com/DataDog/helm-charts/test/common"
)

const (
DDAgentIpcPort = "DD_AGENT_IPC_PORT"
DDAgentIpcConfigRefreshInterval = "DD_AGENT_IPC_CONFIG_REFRESH_INTERVAL"
)

type ExpectedIpcEnv struct {
ipcPort string
ipcConfigRefreshInterval string
}

func Test_otelAgentConfigs(t *testing.T) {
tests := []struct {
name string
command common.HelmCommand
assertions func(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv)
expectedIpcEnv ExpectedIpcEnv
}{
{
name: "no ipc provided",
command: common.HelmCommand{
ReleaseName: "datadog",
ChartPath: "../../charts/datadog",
ShowOnly: []string{"templates/daemonset.yaml"},
Values: []string{"../../charts/datadog/values.yaml"},
Overrides: map[string]string{
"datadog.apiKeyExistingSecret": "datadog-secret",
"datadog.appKeyExistingSecret": "datadog-secret",
"datadog.otelCollector.enabled": "true",
},
},
expectedIpcEnv: ExpectedIpcEnv{
ipcPort: "5009",
ipcConfigRefreshInterval: "60",
},
assertions: verifyOtelAgentEnvVars,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
manifest, err := common.RenderChart(t, tt.command)
assert.Nil(t, err, "couldn't render template")
tt.assertions(t, manifest, tt.expectedIpcEnv)
})
}
}

func verifyOtelAgentEnvVars(t *testing.T, manifest string, expectedIpcEnv ExpectedIpcEnv) {
var deployment appsv1.DaemonSet
common.Unmarshal(t, manifest, &deployment)
// otel agent
otelAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "otel-agent")
assert.True(t, ok)
coreEnvs := getEnvVarMap(otelAgentContainer.Env)
assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort])
assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval])

// core agent
coreAgentContainer, ok := getContainer(t, deployment.Spec.Template.Spec.Containers, "agent")
assert.True(t, ok)
coreEnvs = getEnvVarMap(coreAgentContainer.Env)
assert.Equal(t, expectedIpcEnv.ipcPort, coreEnvs[DDAgentIpcPort])
assert.Equal(t, expectedIpcEnv.ipcConfigRefreshInterval, coreEnvs[DDAgentIpcConfigRefreshInterval])
}

0 comments on commit f7282b2

Please sign in to comment.