-
Notifications
You must be signed in to change notification settings - Fork 47
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
Refactor Otel Collector Googlecloud ConfigMap Generation #1665
Conversation
Skipping CI for Draft Pull Request. |
/test all |
ad2bcb3
to
10f68b7
Compare
6a746be
to
4d45a08
Compare
|
||
// Compare the YAML content as strings | ||
gotYAML := gotConfigMapToYAML(gotConfigMap) | ||
if configYAML != gotYAML { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
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
, becausefmt.Println
prints an unintended space between args - use
t.Fatalf
to fail immediately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
99ffa7b
into
GoogleContainerTools:main
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.