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

Conversation

jefchien
Copy link
Member

Issue #, if available: N/A

Description of changes: With the current implementation, the otelConfig expects a YAML object in the values.yaml

  otelConfig:
    receivers:
      otlp/custom-suffix:
        protocols:
          http:
    exporters:
      awscloudwatchlogs/custom-suffix:
        log_group_name: "test-group"
        log_stream_name: "test-stream"
    service:
      pipelines:
        logs/from-values:
          receivers: [ otlp/custom-suffix ]
          exporters: [ awscloudwatchlogs/custom-suffix ]

but does not work for YAML strings (e.g. when passing in the value using --set agent.otelConfig).

Error: UPGRADE FAILED: template: amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml:84:17: executing "amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml" at <include "cloudwatch-agent.modify-yaml-config" (merge (dict "OtelConfig" $agent.otelConfig) .)>: error calling include: template: amazon-cloudwatch-observability/templates/_helpers.tpl:52:31: executing "cloudwatch-agent.modify-yaml-config" at <$configCopy>: range can't iterate over 

With the change, the helm chart can now accept either a YAML object or string, which means the values.yaml can take an object and --set agent.otelConfig can be used to pass in a string.

helm upgrade --install --namespace amazon-cloudwatch amazon-cloudwatch-observability ./charts/amazon-cloudwatch-observability/ --create-namespace --set region=$REGION --set clusterName=$CLUSTER_NAME --set agent.otelConfig='
  receivers:
    otlp/custom-suffix:
      protocols:
        http:
  exporters:
    awscloudwatchlogs/custom-suffix:
      log_group_name: "test-group"
      log_stream_name: "test-stream"
  service:
    pipelines:
      logs/on-set:
        receivers: [otlp/custom-suffix]
        exporters: [awscloudwatchlogs/custom-suffix]                                                                                                                                                           
Release "amazon-cloudwatch-observability" has been upgraded. Happy Helming!
NAME: amazon-cloudwatch-observability
LAST DEPLOYED: Fri Jan 24 11:08:44 2025
NAMESPACE: amazon-cloudwatch
STATUS: deployed
REVISION: 37
TEST SUITE: None

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

{{- 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

@jefchien jefchien merged commit 9312162 into main Jan 24, 2025
3 checks passed
@jefchien jefchien deleted the yaml-fix branch January 24, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants