-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
metrics: fix potential conflict on metrics registration #27007
metrics: fix potential conflict on metrics registration #27007
Conversation
context: #26412 (review) |
453cdf7
to
891e79b
Compare
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice fix, I think this makes sense but I had a few questions
pkg/k8s/watchers/watcher.go
Outdated
@@ -93,13 +93,27 @@ func init() { | |||
k8s.K8sErrorHandler, | |||
} | |||
|
|||
k8s_metrics.Register(k8s_metrics.RegisterOpts{ | |||
// The client-go Register function can be called only once, | |||
// but controller-runtime also calls it in its init function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can maybe generalize that any in case of transitive imports can cause this condition to happen (while also mentioning the specific controller-runtime scenario that was the motivation here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rephrased it. Please take a look.
891e79b
to
a0d56f3
Compare
/test |
ginkgo build cache seems broken |
/test |
a0d56f3
to
f4c4ebc
Compare
In Cilium v1.13, K8s rest client metrics, such as cilium_k8s_client_api_latency_time_seconds and cilium_k8s_client_api_calls_total, are missing because of a conflict with controller-runtime on the metrics registration. controller-runtime(sigs.k8s.io/controller-runtime/pkg/metrics) also registers the client-go rest client metrics on its registry using metrics.Register method in its init function. The metrics.Register can be called only once, and subsequent calls will be ignored. cilium-agent doesn't use controller-runtime, but there's an indirect dependency from github.com/cilium/cilium/daemon to github.com/cilium/cilium/operator/metrics package. (operator uses controller-runtime in its Gateway API implementation) For example, github.com/cilium/cilium/daemon/cmd -> github.com/cilium/cilium/pkg/ipam -> github.com/cilium/cilium/pkg/ipam/metrics -> github.com/cilium/cilium/operator/metrics The init function of sigs.k8s.io/controller-runtime/pkg/metrics will be called because of this indirect dependency. The issue(missing client-go metrics) doesn't happen with v1.14 and later, but it can happen if the order of imports changes again. This commit is to prevent the issue from happning. This commit is a forward port of cilium@e4ff641 Signed-off-by: Yusuke Suzuki <yusuke-suzuki@cybozu.co.jp>
/test |
@tommyp1ckles Do you have any other feedback or question? |
@tommyp1ckles do we need backport labels? |
@borkmann 👍 This fixues a bug in 1.13, but this sounds like it may prevent future issues in 1.14 as well. |
In Cilium v1.13, K8s rest client metrics, such as cilium_k8s_client_api_latency_time_seconds and cilium_k8s_client_api_calls_total, are missing because of a conflict with controller-runtime on the metrics registration.
controller-runtime(sigs.k8s.io/controller-runtime/pkg/metrics) also registers the client-go rest client metrics on its registry using metrics.Register method in its init function. The metrics.Register can be called only once, and subsequent calls will be ignored.
cilium-agent doesn't use controller-runtime, but there's an indirect dependency from github.com/cilium/cilium/daemon to github.com/cilium/cilium/operator/metrics package. (operator uses controller-runtime in its Gateway API implementation) For example,
github.com/cilium/cilium/daemon/cmd
-> github.com/cilium/cilium/pkg/ipam
-> github.com/cilium/cilium/pkg/ipam/metrics
-> github.com/cilium/cilium/operator/metrics
The init function of sigs.k8s.io/controller-runtime/pkg/metrics will be called because of this indirect dependency.
The issue(missing client-go metrics) doesn't happen with v1.14 and later, but it can happen if the order of imports changes again. This commit is to prevent the issue from happning.
This commit is a forward port of e4ff641
fixes: #25610
Please ensure your pull request adheres to the following guidelines:
description and a
Fixes: #XXX
line if the commit addresses a particularGitHub issue.
Fixes: <commit-id>
tag, thenplease add the commit author[s] as reviewer[s] to this issue.