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

WIP: otelcol: use ocb to autogenerate source files #5382

Closed
wants to merge 1 commit into from

Conversation

mauri870
Copy link
Member

@mauri870 mauri870 commented Aug 29, 2024

What does this PR do?

This PR uses the OpenTelemetry collector builder (ocb for short) to automate the generation of collector source files.

Why is it important?

Updating otel collector files manually can be time consuming and error prone, we can let ocb generate the source files.

@mauri870 mauri870 added enhancement New feature or request skip-changelog opentelemetry Related to the Elastic Distribution of the OpenTelemetry Collector labels Aug 29, 2024
@mauri870 mauri870 self-assigned this Aug 29, 2024
@mauri870 mauri870 requested a review from a team as a code owner August 29, 2024 11:58
Copy link
Contributor

mergify bot commented Aug 29, 2024

This pull request does not have a backport label. Could you fix it @mauri870? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

output_path: .

extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.107.0
Copy link
Member Author

@mauri870 mauri870 Aug 29, 2024

Choose a reason for hiding this comment

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

Unfortunately, we can't manage versions in this file and sync them with a go.mod file, since the dependencies are defined in the elastic-agent go.mod located at the root of the repository. We could consider using Go workspaces and moving this code to ${REPO_ROOT}/otel, for example, so it can be its own module with its own go.mod file. This approach would also clean up the otelcol dependencies in the root go.mod file.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have dependabot currently bumping up the OTel dependency versions in go.mod: https://github.com/elastic/elastic-agent/blob/main/.github/dependabot.yml. Perhaps we can add a new step or job to https://github.com/elastic/elastic-agent/blob/main/.github/workflows/post-dependabot.yml to do some parsing of the go.mod file and sync the versions in this file with the parsed results?


all:
go run go.opentelemetry.io/collector/cmd/[email protected] --skip-compilation --skip-get-modules --config builder-config.yaml
@rm main.go main_others.go main_windows.go go.mod
Copy link
Member Author

@mauri870 mauri870 Aug 29, 2024

Choose a reason for hiding this comment

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

This is a bit hacky since ocb expects to build a final binary. Having an otel collector embedded into another binary seems to be quite useful, I wonder if the folks at OpenTelemetry would be willing to support a ocb mode to build a library instead of a final binary.

@pierrehilbert pierrehilbert requested review from andrzej-stencel and swiatekm and removed request for michel-laterman August 29, 2024 13:10
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Aug 29, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@@ -0,0 +1,6 @@
.PHONY: all
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure you include this in mage update target at root.
It would be nice if mage update could regenerate sources. Update go mod versions and then update readme file as it does today.

@mauri870 mauri870 changed the title otelcol: use ocb to autogenerate source files WIP: otelcol: use ocb to autogenerate source files Aug 29, 2024
@andrzej-stencel
Copy link
Contributor

In general, I like the idea of keeping OTel dependencies in a canonical Builder config Yaml file. For engineers oriented around the OpenTelemetry Collector, this is the idiomatic way to understand what components are included.

However, given that the Elastic Agent is not simply an OTel Collector binary built by the OTel Collector Builder, but rather a binary that incorporates OTel Collector libraries into an existing code base, and given the current feature set of the Builder, my opinion is that the benefit of declaring OTel dependencies in Builder config file does not outweigh the added complexity.

Introducing this approach adds an additional level of abstraction, which affects all engineers working on the Elastic Agent code (Elasticians or not), some of them possibly not knowing anything about OTel Collector or the OTel Collector Builder. It creates new problems like "do we maintain a separate go.mod file for the OTel dependencies" or "how do we keep the OTel dependencies up to date".

The big advantage of the current approach is its simplicity. It is based on regular Go imports and nothing else. This makes it simpler to integrate with tools like Dependabot for dependency upgrades.

My recommendation is to leave the current approach unchanged for now for the sake of simplicity and revisit this decision when circumstances change.

@ycombinator
Copy link
Contributor

Thanks for weighing in, @andrzej-stencel. You raise a good point about the added complexity and additional level of abstraction that may not be obvious to all contributors. Unless others have strong opinions for favoring the approach in this PR, I'm OK with sticking with our current approach which is not as declarative as the one in this PR but is simpler to understand.

@mauri870 mauri870 marked this pull request as draft September 5, 2024 19:18
@mauri870
Copy link
Member Author

mauri870 commented Sep 9, 2024

Just an update: I ended up opening an issue upstream to suggest adding support for OCB library code generation. I don't expect this to be considered before the 1.0 release of the builder, but it is a valid feature request.

The changes proposed here aren't worth implementing, as they add unnecessary complexity compared to the current approach and require workarounds to bypass OCB's limitations.

With that in mind, I’m closing this for now.

@mauri870 mauri870 closed this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip enhancement New feature or request opentelemetry Related to the Elastic Distribution of the OpenTelemetry Collector skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants