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: register k8s metrics #6525

Merged

Conversation

simonpasquier
Copy link
Contributor

@simonpasquier simonpasquier commented Apr 18, 2024

Description

controller-runtime also calls metrics.Register() during init and this function can be called only once. To ensure that the k8s client metrics get updated, the global variables need to be set again by the operator.

https://github.com/kubernetes-sigs/controller-runtime/blob/67b27f27e514bd9ac4cf9a2d84dec089ece95bf7/pkg/metrics/client_go_adapter.go#L42-L55 https://github.com/kubernetes/client-go/blob/aa7909e7d7c0661792ba21b9e882f3cd6ad0ce53/tools/metrics/metrics.go#L129-L170

Closes #6513

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

fix missing `prometheus_operator_kubernetes_client_http_requests_total` metric.

controller-runtime also calls `metrics.Register()` during init and this
function can be called only once. To ensure that the k8s client metrics
get updated, the global variables need to be set again by the operator.

https://github.com/kubernetes-sigs/controller-runtime/blob/67b27f27e514bd9ac4cf9a2d84dec089ece95bf7/pkg/metrics/client_go_adapter.go#L42-L55
https://github.com/kubernetes/client-go/blob/aa7909e7d7c0661792ba21b9e882f3cd6ad0ce53/tools/metrics/metrics.go#L129-L170

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@simonpasquier
Copy link
Contributor Author

I've tested locally and it seems to work. To avoid future regressions, I'll file an issue to add e2e tests on prometheus-operator metrics.

@simonpasquier simonpasquier merged commit 21b32c5 into prometheus-operator:release-0.73 Apr 18, 2024
17 checks passed
@simonpasquier simonpasquier deleted the fix-6513 branch April 18, 2024 12:20
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.

None yet

2 participants