From 2534ea1cbd21de36eefda5803fb1e5c0ce90bd87 Mon Sep 17 00:00:00 2001 From: Michael Commey Date: Thu, 2 Jul 2026 14:11:39 +0000 Subject: [PATCH 1/4] Add mode priority order for OTel Container Insights --- .../opentelemetry/containerinsights/common.go | 36 ++++- .../containerinsights/common_test.go | 87 ++++++++++- .../containerinsights/translator.go | 13 +- .../containerinsights/translators_test.go | 139 ++++++++++++++++++ 4 files changed, 263 insertions(+), 12 deletions(-) create mode 100644 translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go index 912d5c3645..88b7e5853d 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go @@ -5,6 +5,7 @@ package containerinsights import ( "fmt" + "os" "regexp" "time" @@ -17,6 +18,16 @@ import ( const ( ciPrefix = "cw_k8s_ci_v0" defaultCollectionInterval = 30 * time.Second + + // envCWAgentRole is the environment variable used by the helm chart to indicate + // whether the agent runs as a DaemonSet (node-level) or Deployment (cluster-level). + envCWAgentRole = "CWAGENT_ROLE" + // Environment variable values for CWAGENT_ROLE + envRoleNode = "NODE" + envRoleLeader = "LEADER" + // Mode values + modeNode = "node" + modeCluster = "cluster" ) var ciConfigKey = common.ConfigKey(common.OpenTelemetryKey, common.CollectKey, common.OtelContainerInsightsKey) @@ -117,16 +128,27 @@ func logsEnabled(conf *confmap.Conf) bool { return common.GetOrDefaultBool(conf, key, false) } -// getMode returns the container_insights.mode value ("node", "cluster", or "" for all). +// getMode resolves the container insights pipeline mode using the following +// priority order: +// 1. JSON config field +// 2. Environment variable +// 3. Default: "node" (DaemonSet) func getMode(conf *confmap.Conf) string { - if conf == nil { - return "" + if conf != nil { + key := common.ConfigKey(ciConfigKey, "mode") + if v, ok := common.GetString(conf, key); ok && v != "" { + return v + } } - key := common.ConfigKey(ciConfigKey, "mode") - if v, ok := common.GetString(conf, key); ok { - return v + if role := os.Getenv(envCWAgentRole); role != "" { + switch role { + case envRoleNode: + return modeNode + case envRoleLeader: + return modeCluster + } } - return "" + return modeNode } type pipelineSpec struct { diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go index 57a7e3de73..13751f42d6 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go @@ -3,7 +3,13 @@ package containerinsights -import "testing" +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/confmap" +) func TestEscapeDollarDigit(t *testing.T) { tests := []struct { @@ -35,3 +41,82 @@ func TestEscapeDollarDigit(t *testing.T) { }) } } + +func TestGetMode_JSONConfig(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "mode": "cluster", + }, + }, + }, + }) + assert.Equal(t, modeCluster, getMode(cfg)) +} + +func TestGetMode_EnvVarFallback(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{}, + }, + }, + }) + + t.Setenv(envCWAgentRole, envRoleLeader) + assert.Equal(t, modeCluster, getMode(cfg)) + + t.Setenv(envCWAgentRole, envRoleNode) + assert.Equal(t, modeNode, getMode(cfg)) +} + +func TestGetMode_DefaultsToNode(t *testing.T) { + os.Unsetenv(envCWAgentRole) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{}, + }, + }, + }) + assert.Equal(t, modeNode, getMode(cfg)) +} + +func TestGetMode_JSONOverridesEnv(t *testing.T) { + t.Setenv(envCWAgentRole, envRoleNode) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "mode": "cluster", + }, + }, + }, + }) + assert.Equal(t, modeCluster, getMode(cfg)) +} + +func TestLogsEnabled(t *testing.T) { + tests := []struct { + name string + cfg *confmap.Conf + want bool + }{ + {"nil config", nil, false}, + {"not set", confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{"collect": map[string]interface{}{"container_insights": map[string]interface{}{}}}, + }), false}, + {"enabled true", confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{"collect": map[string]interface{}{"container_insights": map[string]interface{}{"logs": map[string]interface{}{"enabled": true}}}}, + }), true}, + {"enabled false", confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{"collect": map[string]interface{}{"container_insights": map[string]interface{}{"logs": map[string]interface{}{"enabled": false}}}}, + }), false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, logsEnabled(tt.cfg)) + }) + } +} \ No newline at end of file diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translator.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translator.go index a6eb6c1115..cbd309655a 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translator.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translator.go @@ -74,16 +74,21 @@ var apiserverYAML string var kubeStateMetricsYAML string // NewTranslators returns all container insights pipeline translators. -// The pipelines generated depend on the "mode" config field: +// The pipelines generated depend on the resolved mode (see getMode for priority): // - "node": daemonset pipelines (per-node metrics + logs) // - "cluster": deployment pipelines (cluster-wide metrics) -// - omitted: all pipelines func NewTranslators(conf *confmap.Conf) common.PipelineTranslatorMap { translators := common.NewTranslatorMap[*common.ComponentTranslators, pipeline.ID]() + + // Guard: no container_insights config key means no pipelines to build. + if conf == nil || !conf.IsSet(ciConfigKey) { + return translators + } + mode := getMode(conf) // Daemonset metrics pipelines - if mode == "" || mode == "node" { + if mode == modeNode { translators.Set(newYAMLPipeline("kubeletstats", pipeline.SignalMetrics, kubeletstatsYAML)) translators.Set(newYAMLPipeline("cadvisor", pipeline.SignalMetrics, cadvisorYAML)) translators.Set(newYAMLPipeline("node_exporter", pipeline.SignalMetrics, nodeExporterYAML)) @@ -101,7 +106,7 @@ func NewTranslators(conf *confmap.Conf) common.PipelineTranslatorMap { } // Deployment metrics pipelines - if mode == "cluster" { + if mode == modeCluster { translators.Set(newYAMLPipeline("apiserver", pipeline.SignalMetrics, apiserverYAML)) translators.Set(newYAMLPipeline("kube_state_metrics", pipeline.SignalMetrics, kubeStateMetricsYAML)) } diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go new file mode 100644 index 0000000000..727c2ca61a --- /dev/null +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go @@ -0,0 +1,139 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: MIT + +package containerinsights + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/confmap" +) + +func TestNewTranslators_MissingKey(t *testing.T) { + // nil config - should return 0 translators (no container_insights key present) + assert.Equal(t, 0, NewTranslators(nil).Len()) + // empty config - should return 0 translators + assert.Equal(t, 0, NewTranslators(confmap.NewFromStringMap(map[string]interface{}{})).Len()) +} + +func TestNewTranslators_ModeNode(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + "mode": "node", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // node mode: kubeletstats, cadvisor, node_exporter, dcgm, neuron, efa, ebs_csi, lis_csi = 8 pipelines + assert.Equal(t, 8, translators.Len()) +} + +func TestNewTranslators_ModeNodeWithLogs(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + "mode": "node", + "logs": map[string]interface{}{ + "enabled": true, + }, + }, + }, + }, + }) + translators := NewTranslators(cfg) + // node mode + logs: 8 metric pipelines + 2 log pipelines = 10 + assert.Equal(t, 10, translators.Len()) +} + +func TestNewTranslators_ModeCluster(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + "mode": "cluster", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // cluster mode: apiserver, kube_state_metrics = 2 pipelines + assert.Equal(t, 2, translators.Len()) +} + +func TestNewTranslators_DefaultMode(t *testing.T) { + // No mode specified, no env var - should default to node + os.Unsetenv(envCWAgentRole) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // defaults to node mode: 8 pipelines + assert.Equal(t, 8, translators.Len()) +} + +func TestNewTranslators_EnvVarFallback_Node(t *testing.T) { + // No mode in config, CWAGENT_ROLE=NODE + t.Setenv(envCWAgentRole, envRoleNode) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // env var NODE -> node mode: 8 pipelines + assert.Equal(t, 8, translators.Len()) +} + +func TestNewTranslators_EnvVarFallback_Leader(t *testing.T) { + // No mode in config, CWAGENT_ROLE=LEADER + t.Setenv(envCWAgentRole, envRoleLeader) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // env var LEADER -> cluster mode: 2 pipelines + assert.Equal(t, 2, translators.Len()) +} + +func TestNewTranslators_JSONConfigOverridesEnvVar(t *testing.T) { + // JSON says cluster, env var says NODE -> JSON wins + t.Setenv(envCWAgentRole, envRoleNode) + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{ + "cluster_name": "test-cluster", + "mode": "cluster", + }, + }, + }, + }) + translators := NewTranslators(cfg) + // JSON config wins: cluster mode = 2 pipelines + assert.Equal(t, 2, translators.Len()) +} From 2dc544ec0b187e5655b6f2553c772c5fcf119252 Mon Sep 17 00:00:00 2001 From: Michael Commey Date: Thu, 2 Jul 2026 14:11:39 +0000 Subject: [PATCH 2/4] Add mode priority order for OTel Container Insights --- .../pipeline/opentelemetry/containerinsights/common_test.go | 4 +--- .../opentelemetry/containerinsights/translators_test.go | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go index 13751f42d6..ef8ad09508 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go @@ -4,7 +4,6 @@ package containerinsights import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -72,7 +71,6 @@ func TestGetMode_EnvVarFallback(t *testing.T) { } func TestGetMode_DefaultsToNode(t *testing.T) { - os.Unsetenv(envCWAgentRole) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{ @@ -119,4 +117,4 @@ func TestLogsEnabled(t *testing.T) { assert.Equal(t, tt.want, logsEnabled(tt.cfg)) }) } -} \ No newline at end of file +} diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go index 727c2ca61a..cba7c9eb51 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go @@ -4,7 +4,6 @@ package containerinsights import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -71,7 +70,6 @@ func TestNewTranslators_ModeCluster(t *testing.T) { func TestNewTranslators_DefaultMode(t *testing.T) { // No mode specified, no env var - should default to node - os.Unsetenv(envCWAgentRole) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{ From 151ea2d084fafd022cc972b5d02dda681c8a059a Mon Sep 17 00:00:00 2001 From: Michael Commey Date: Thu, 2 Jul 2026 14:11:39 +0000 Subject: [PATCH 3/4] Add mode priority order for OTel Container Insights --- .../opentelemetry/containerinsights/common.go | 3 ++- .../containerinsights/common_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go index 88b7e5853d..0f41149d13 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "regexp" + "strings" "time" "go.opentelemetry.io/collector/component" @@ -140,7 +141,7 @@ func getMode(conf *confmap.Conf) string { return v } } - if role := os.Getenv(envCWAgentRole); role != "" { + if role := strings.ToUpper(os.Getenv(envCWAgentRole)); role != "" { switch role { case envRoleNode: return modeNode diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go index ef8ad09508..edb7fd8c4a 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go @@ -81,6 +81,25 @@ func TestGetMode_DefaultsToNode(t *testing.T) { assert.Equal(t, modeNode, getMode(cfg)) } +func TestGetMode_EnvVarCaseInsensitive(t *testing.T) { + cfg := confmap.NewFromStringMap(map[string]interface{}{ + "opentelemetry": map[string]interface{}{ + "collect": map[string]interface{}{ + "container_insights": map[string]interface{}{}, + }, + }, + }) + + t.Setenv(envCWAgentRole, "leader") // lowercase + assert.Equal(t, modeCluster, getMode(cfg)) + + t.Setenv(envCWAgentRole, "node") // lowercase + assert.Equal(t, modeNode, getMode(cfg)) + + t.Setenv(envCWAgentRole, "Leader") // mixed case + assert.Equal(t, modeCluster, getMode(cfg)) +} + func TestGetMode_JSONOverridesEnv(t *testing.T) { t.Setenv(envCWAgentRole, envRoleNode) cfg := confmap.NewFromStringMap(map[string]interface{}{ From 3af68f37bf70c9ed02f665d9569f2d1c2f27d05b Mon Sep 17 00:00:00 2001 From: Michael Commey Date: Mon, 6 Jul 2026 20:08:02 +0000 Subject: [PATCH 4/4] Address PR comments --- translator/config/schema.json | 2 +- .../opentelemetry/containerinsights/common.go | 14 ++++---------- .../opentelemetry/containerinsights/common_test.go | 14 ++++++++------ .../containerinsights/translators_test.go | 8 +++++--- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/translator/config/schema.json b/translator/config/schema.json index 680eed8111..648b6fdb03 100644 --- a/translator/config/schema.json +++ b/translator/config/schema.json @@ -1859,7 +1859,7 @@ "$ref": "#/definitions/timeIntervalDefinition" }, "mode": { - "description": "Pipeline mode: node (daemonset), cluster (deployment), or omit for all", + "description": "Pipeline mode: node (daemonset), cluster (deployment). If omitted, falls back to CWAGENT_ROLE env var", "type": "string", "enum": ["node", "cluster"] }, diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go index 0f41149d13..4aeb66d17a 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" + "github.com/aws/amazon-cloudwatch-agent/cfg/envconfig" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" ) @@ -20,13 +21,6 @@ const ( ciPrefix = "cw_k8s_ci_v0" defaultCollectionInterval = 30 * time.Second - // envCWAgentRole is the environment variable used by the helm chart to indicate - // whether the agent runs as a DaemonSet (node-level) or Deployment (cluster-level). - envCWAgentRole = "CWAGENT_ROLE" - // Environment variable values for CWAGENT_ROLE - envRoleNode = "NODE" - envRoleLeader = "LEADER" - // Mode values modeNode = "node" modeCluster = "cluster" ) @@ -141,11 +135,11 @@ func getMode(conf *confmap.Conf) string { return v } } - if role := strings.ToUpper(os.Getenv(envCWAgentRole)); role != "" { + if role := strings.ToUpper(os.Getenv(envconfig.CWAGENT_ROLE)); role != "" { switch role { - case envRoleNode: + case envconfig.NODE: return modeNode - case envRoleLeader: + case envconfig.LEADER: return modeCluster } } diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go index edb7fd8c4a..bcc8c86b02 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/common_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/confmap" + + "github.com/aws/amazon-cloudwatch-agent/cfg/envconfig" ) func TestEscapeDollarDigit(t *testing.T) { @@ -63,10 +65,10 @@ func TestGetMode_EnvVarFallback(t *testing.T) { }, }) - t.Setenv(envCWAgentRole, envRoleLeader) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.LEADER) assert.Equal(t, modeCluster, getMode(cfg)) - t.Setenv(envCWAgentRole, envRoleNode) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.NODE) assert.Equal(t, modeNode, getMode(cfg)) } @@ -90,18 +92,18 @@ func TestGetMode_EnvVarCaseInsensitive(t *testing.T) { }, }) - t.Setenv(envCWAgentRole, "leader") // lowercase + t.Setenv(envconfig.CWAGENT_ROLE, "leader") // lowercase assert.Equal(t, modeCluster, getMode(cfg)) - t.Setenv(envCWAgentRole, "node") // lowercase + t.Setenv(envconfig.CWAGENT_ROLE, "node") // lowercase assert.Equal(t, modeNode, getMode(cfg)) - t.Setenv(envCWAgentRole, "Leader") // mixed case + t.Setenv(envconfig.CWAGENT_ROLE, "Leader") // mixed case assert.Equal(t, modeCluster, getMode(cfg)) } func TestGetMode_JSONOverridesEnv(t *testing.T) { - t.Setenv(envCWAgentRole, envRoleNode) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.NODE) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{ diff --git a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go index cba7c9eb51..526356860f 100644 --- a/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/containerinsights/translators_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/confmap" + + "github.com/aws/amazon-cloudwatch-agent/cfg/envconfig" ) func TestNewTranslators_MissingKey(t *testing.T) { @@ -86,7 +88,7 @@ func TestNewTranslators_DefaultMode(t *testing.T) { func TestNewTranslators_EnvVarFallback_Node(t *testing.T) { // No mode in config, CWAGENT_ROLE=NODE - t.Setenv(envCWAgentRole, envRoleNode) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.NODE) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{ @@ -103,7 +105,7 @@ func TestNewTranslators_EnvVarFallback_Node(t *testing.T) { func TestNewTranslators_EnvVarFallback_Leader(t *testing.T) { // No mode in config, CWAGENT_ROLE=LEADER - t.Setenv(envCWAgentRole, envRoleLeader) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.LEADER) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{ @@ -120,7 +122,7 @@ func TestNewTranslators_EnvVarFallback_Leader(t *testing.T) { func TestNewTranslators_JSONConfigOverridesEnvVar(t *testing.T) { // JSON says cluster, env var says NODE -> JSON wins - t.Setenv(envCWAgentRole, envRoleNode) + t.Setenv(envconfig.CWAGENT_ROLE, envconfig.NODE) cfg := confmap.NewFromStringMap(map[string]interface{}{ "opentelemetry": map[string]interface{}{ "collect": map[string]interface{}{