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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from tiffanny29631. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@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 3 times, most recently from a856164 to ad2bcb3 Compare May 16, 2025 23:31
…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.
)

// CollectorConfigGooglecloudYAML returns the otel-collector-googlecloud config as YAML.
func CollectorConfigGooglecloudYAML() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like valid configs can be generated programmatically, e.g. https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/extension/healthcheckextension/factory.go#L20

Would it be possible for us to use that to generate canonical/valid configs and then marshal to YAML?

)

// CollectorConfigGooglecloudYAML returns the otel-collector-googlecloud config as YAML.
func CollectorConfigGooglecloudYAML() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a unit test for this function which validates the output yaml string against a static/hardcoded test yaml string? That will make it easier for a human reviewer to inspect the actual output yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants