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

Fix webhook error when metrics service address uses env var expansion #3531

Merged

Conversation

douglascamata
Copy link
Contributor

Description:

Use a naive port parsing in the operator's webhook to ensure it doesn't error out when the metrics service address uses environment variable expansion for the host part.

Link to tracking Issue(s):

Testing:

Added a unit test covering the IPv4 case.

Documentation:

None.

@douglascamata douglascamata requested a review from a team as a code owner December 10, 2024 11:41
Copy link

linux-foundation-easycla bot commented Dec 10, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

apis/v1beta1/config.go Fixed Show fixed Hide fixed
@swiatekm
Copy link
Contributor

This change looks good to me (minus the gosec warning), but it doesn't fully address #3513. What we should do in addition is emit a warning when failing to parse the port instead of returning an error.

@douglascamata
Copy link
Contributor Author

douglascamata commented Dec 10, 2024

@swiatekm will add the warning and fix the gosec issue in a few mins. Thanks!

Now, when there would be an error it gets logged and the default values
are returned. With this refactor the method encapsulates all defaulting
logic that was slightly spread around different places.
@douglascamata
Copy link
Contributor Author

@swiatekm @yuriolisa: I just updated the PR with the changes you suggested:

  • If we fail to parse the port (due to invalid port or env var usage), an error is returned.
  • Env var for the host part is still accepted.
  • Documented the points above in the README, close to where there was already some explanation regarding how the Operator examines the Collector's configuration.

On top of this, I could modify the code to support IPv6 and added a bunch of tests to ensure we don't have regressions.

Thank you for your review. 🙇

@yuriolisa
Copy link
Contributor

@swiatekm @yuriolisa: I just updated the PR with the changes you suggested:

  • If we fail to parse the port (due to invalid port or env var usage), an error is returned.
  • Env var for the host part is still accepted.
  • Documented the points above in the README, close to where there was already some explanation regarding how the Operator examines the Collector's configuration.

On top of this, I could modify the code to support IPv6 and added a bunch of tests to ensure we don't have regressions.

Thank you for your review. 🙇

Although I see the IPv6 support as valid, I suggest putting it in another PR to avoid any misleading debugging.

README.md Outdated Show resolved Hide resolved
apis/v1beta1/config.go Outdated Show resolved Hide resolved
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This should allow the metrics service address to have the host portion expanded from an environment variable,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please inform that you enabled the IPv6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yuriolisa I didn’t necessarily enable ipv6. I only refactored that ‘Service.MetricsEndpoint’ method in a way that it also works with ipv6 addresses. I do not know if the project has everything else that is needed for full ipv6 support. Do you know about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's a need to specifically call out IPv6. We only care about the port to begin with.

@swiatekm swiatekm added the discuss-at-sig This issue or PR should be discussed at the next SIG meeting label Dec 12, 2024
@swiatekm swiatekm self-requested a review December 12, 2024 11:31
Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

Your changes look good to me overall @douglascamata, and thank you for being patient with the review process! I'm blocking this from being merged for now, because I'd like to get wider consensus on how we should deal with this issue. I'll do a proper review once we have clarity on that.

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

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

This all makes sense to me and I appreciate the thought put in here :) I agree with Mikolaj's original comment (and thus this implementation).

README.md Show resolved Hide resolved
apis/v1beta1/config.go Outdated Show resolved Hide resolved
apis/v1beta1/config.go Outdated Show resolved Hide resolved
apis/v1beta1/config.go Outdated Show resolved Hide resolved
apis/v1beta1/config.go Outdated Show resolved Hide resolved
@douglascamata
Copy link
Contributor Author

@jaronoff97: I took care of your feedback (plus another small pending change) in a batch on a6744fd

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

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

Thank you :)

Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you for the contribution!

@swiatekm swiatekm merged commit 0fdf105 into open-telemetry:main Dec 13, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss-at-sig This issue or PR should be discussed at the next SIG meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment variable expansion in spec.config.service.telemetry.metrics.address doesn't work
4 participants