Skip to content

Refactor Otel Collector Googlecloud ConfigMap Generation #1665

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

tiffanny29631
Copy link
Contributor

To Use Go Struct and YAML Marshaling

Refactor the generation of the otel-collector Googlecloud ConfigMap to construct the configuration using a Go map and marshal it to YAML, replacing the previous approach of using a static YAML string. This change improves maintainability and reduces the risk of formatting errors in the generated config. Add GooglecloudCollectorConfigYAML() and deprecate the old CollectorConfigGooglecloud string constant. This refactor makes the config generation more robust and easier to extend or validate in the future.

Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@tiffanny29631
Copy link
Contributor Author

/test all

@tiffanny29631 tiffanny29631 marked this pull request as ready for review May 12, 2025 21:46
@tiffanny29631 tiffanny29631 force-pushed the otel-cm branch 4 times, most recently from ad2bcb3 to 10f68b7 Compare May 16, 2025 23:33
@tiffanny29631 tiffanny29631 force-pushed the otel-cm branch 2 times, most recently from 6a746be to 4d45a08 Compare May 27, 2025 21:46

// Compare the YAML content as strings
gotYAML := gotConfigMapToYAML(gotConfigMap)
if configYAML != gotYAML {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest using cmp.Diff to compare strings and print a diff. That will be easier to view the difference compared to the full expected yaml. in other words:

  • print the cmp.Diff output for easy human readable diff
  • print the full actual yaml for easy copy/paste if the developer wants to update the expected yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

a few minor nits:

  • the typical pattern is if diff := cmp.Diff(wantYAML, gotYAML); diff != "" { ...
  • use fmt.Printf, because fmt.Println prints an unintended space between args
  • use t.Fatalf to fail immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tiffanny29631
Copy link
Contributor Author

/retest-required

…ruct and YAML Marshaling

Refactor the generation of the otel-collector Googlecloud ConfigMap to construct the configuration using a Go map and marshal it to YAML, replacing the previous approach of using a static YAML string. This change improves maintainability and reduces the risk of formatting errors in the generated config.
Add GooglecloudCollectorConfigYAML() in pkg/metrics/otel.go to build the config as a Go map and marshal it to YAML.
Update OtelReconciler in pkg/reconcilermanager/controllers/otel_controller.go to use the new function when creating/updating the ConfigMap.
Update related tests to use the new function for expected config values.
Deprecate the old CollectorConfigGooglecloud string constant.
This refactor makes the config generation more robust and easier to extend or validate in the future.
Copy link
Contributor

@sdowell sdowell left a comment

Choose a reason for hiding this comment

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

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label May 28, 2025
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sdowell

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 99ffa7b into GoogleContainerTools:main May 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants