[8.19] (backport #10240) Use a random port for otel collector monitoring endpoint #10520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Uses a random port for the otel collector's Prometheus endpoint. Right now this is hardcoded at the default.
Normally, this port needs to be known during config generation (so we can add the right self-monitoring configuration), so it needs to be determined before the coordinator starts. In this PR, we instead put it into an environment variable and use the otel collector's ability to load configuration values from the variable. As a result, we can defer determining the actual port as late as possible, and even use a different port on each configuration reload, allowing us to recover from port binding conflicts.
This becomes a bit awkward with the embedded collector, where we need to call
SetEnv
, always an anti-pattern. But we eventually expect to retire that mode of execution, and it's not the default anymore, so it should be fine.In the process, I'm also allowing both the metrics port and the healthcheck port to be passed into the otel manager as parameters. This is preparation for making them configurable in a follow-up.
Why is it important?
The port shouldn't be hardcoded. In the event of a conflict, the otel collector can't start.
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added an entry in./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testHow to test this PR locally
Build the agent locally, run it with otel self-monitoring, generate diagnostics, then check the configuration.
Related issues
This is an automatic backport of pull request #10240 done by [Mergify](https://mergify.com).