Skip to content

Support CWAGENT_ROLE env var for Container Insights mode in JSON v2 config#2185

Open
Paamicky wants to merge 6 commits into
mainfrom
mcommey/container_insights_config
Open

Support CWAGENT_ROLE env var for Container Insights mode in JSON v2 config#2185
Paamicky wants to merge 6 commits into
mainfrom
mcommey/container_insights_config

Conversation

@Paamicky

@Paamicky Paamicky commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description of the issue

The OTel Container Insights pipeline had no defined priority order for resolving the pipeline mode. The getMode function returned "" when no mode was configured, leaving callers to implicitly treat an empty string as "node". There was also no way for the Helm chart to set the mode without an explicit JSON config change

Description of changes

Introduces a defined priority order for resolving the Container Insights pipeline mode:

  • JSON config field (mode) takes highest precedence
  • CWAGENT_ROLE environment variable: used by the Helm chart to indicate whether the agent runs as a DaemonSet (NODE) or Deployment (LEADER)
  • Default: "node": if neither is set, the agent defaults to DaemonSet/node mode

The getMode function is updated to implement this priority order explicitly. The NewTranslators function is updated to use named constants (modeNode, modeCluster) instead of bare string comparisons, and a nil/missing-key guard is added to return early with zero translators if the container_insights config key is not present.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Added unit tests covering all priority order cases:

  • TestGetMode_JSONConfig: mode read from JSON config
  • TestGetMode_EnvVarFallback: env var used when JSON config has no mode set
  • TestGetMode_DefaultsToNode: defaults to "node" when neither config nor env var is set
  • TestGetMode_JSONOverridesEnv: JSON config wins when both are present
  • TestNewTranslators_MissingKey: returns zero translators for nil/empty config

Requirements

  1. Run make fmt and make fmt-sh
  2. Run make lint

@Paamicky Paamicky added the ready for testing Indicates this PR is ready for integration tests to run label Jul 6, 2026
@Paamicky Paamicky self-assigned this Jul 6, 2026
@Paamicky Paamicky changed the title Mcommey/container insights config Support CWAGENT_ROLE env var for Container Insights mode in JSON v2 config Jul 6, 2026
@Paamicky Paamicky marked this pull request as ready for review July 6, 2026 16:44
@Paamicky Paamicky requested a review from a team as a code owner July 6, 2026 16:44
@Paamicky Paamicky requested review from JayPolanco, jefchien and mitali-salvi and removed request for JayPolanco July 6, 2026 16:59
Comment thread translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go Outdated
Comment thread translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for testing Indicates this PR is ready for integration tests to run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants