Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow both YAML string and objects to get passed in for OTEL config. #165

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions charts/amazon-cloudwatch-observability/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ Helper function to modify customer supplied agent config if ContainerInsights or
{{/*
Helper function to modify cloudwatch-agent YAML config
*/}}
{{- define "cloudwatch-agent.modify-yaml-config" -}}
{{- define "cloudwatch-agent.modify-otel-config" -}}
{{- $configCopy := deepCopy .OtelConfig }}
{{- if kindIs "string" $configCopy }}
{{- $configCopy = fromYaml $configCopy }}
{{- end }}

{{- range $name, $component := $configCopy }}
{{- if $component -}}
{{- if and $component (kindIs "map" $component) }}
{{- range $key, $value := $component }}
{{- if (and (quote $value | empty) (not (hasKey $component $key))) }}
{{- $component = set $component $key (dict) }}
{{- if eq $value nil }}
{{- $_ := set $component $key dict }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was simplified, was this verified to change the ConfigMap properly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it works.

--set agent.otelConfig='
  extensions:
    health_check/custom-suffix:
  receivers:
    otlp/custom-suffix:
      protocols:
        http:
  processors:
    batch/custom-suffix:
  exporters:
    awscloudwatchlogs/custom-suffix:
      log_group_name: "test-group"
      log_stream_name: "test-stream"
  service:
    extensions: [health_check/custom-suffix]
    pipelines:
      logs/custom-suffix:
        receivers: [otlp/custom-suffix]
        processors: [batch/custom-suffix]
        exporters: [awscloudwatchlogs/custom-suffix]
'

becomes

cwagentotelconfig.yaml:
----
exporters:
  awscloudwatchlogs/custom-suffix:
    log_group_name: test-group
    log_stream_name: test-stream
extensions:
  health_check/custom-suffix: {}
processors:
  batch/custom-suffix: {}
receivers:
  otlp/custom-suffix:
    protocols:
      http: null
service:
  extensions:
  - health_check/custom-suffix
  pipelines:
    logs/custom-suffix:
      exporters:
      - awscloudwatchlogs/custom-suffix
      processors:
      - batch/custom-suffix
      receivers:
      - otlp/custom-suffix

{{- end -}}
{{- end }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spec:
config: {{ include "cloudwatch-agent.modify-config" (merge (dict "Config" $agent.defaultConfig) $ ) }}
{{- end }}
{{- if $agent.otelConfig }}
otelConfig: {{ include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $agent.otelConfig) . ) }}
otelConfig: {{ include "cloudwatch-agent.modify-otel-config" (merge (dict "OtelConfig" $agent.otelConfig) . ) }}
{{- end }}
{{- if $agent.prometheus.config }}
prometheus:
Expand Down
Loading