-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🌱 Allows to redefine ETCD client logger #12271
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/area provider/control-plane-kubeadm |
Wondering if kubernetes has a similar use case and how are they handling it (e.g. in the kube-apiserver) |
This is a very good point. It doesn't work in kube-apiserver at the moment, because community copied/pasted (https://github.com/kubernetes/kubernetes/blob/b35c5c0a301d326fdfa353943fca077778544ac6/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go#L97-L111) the I requested an export of this function in the PR etcd-io/etcd#20006. But as far as I understand, there are no plans to backport it to etcd 3.5. The only downside to this approach is that it won't work natively. We can have both approaches at the same time to get a universal solution. That is, set the logger via a function and change the logging level via ETCD_CLIENT_DEBUG variable. The only thing is that at the moment we will also have to copy/paste the function until the release of etcd 3.6 with this fix is released and we will not switch to it. I could create and track this issue. |
I was wondering if there is a way to "reuse" our regular log level for the etcd logger |
Seems to with some trick like that, it could be possible, but should be validated func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
logger, _ := logutil.CreateDefaultZapLogger(zapcore.Level(ctrl.LoggerFrom(ctx).GetV()))
etcd.SetLogger(logger) But in this case, it would be nice to redefine log destination also in advance to log level. |
@@ -174,6 +175,11 @@ func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) | |||
return client, nil | |||
} | |||
|
|||
// SetLogger allows to redefine ETCD client logger. |
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: can we move this right after etcdClientLogger is defined
controlplane/kubeadm/etcd/alias.go
Outdated
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.
What about moving SetLogger to controllers/alias.go (I would prefer to avoid adding a new package for this)
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.
To be honest I don't think we should address this issue this way at all. 99% of our users can't use this
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.
Generally, I agree with you, it's a very rare case, but if someone to change controller log level to minimal or want to disable it, will see these warnings always in the logs.
I will try to inherit log level from controller-runtime logger.
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 have to take closer look and currently not much time due to urgent v1beta2 work, but what do you think about introducing an additional command line flag in KCP that allows to set the etcd logger log level?
This way everyone can use it and not just the very few folks that consume the exported KCP controller code
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.
Ok, not a problem. In this case, do you mean, that we need separate log levels for controller and etcd client. Now, I converted logr -> zapcore levels and both users (embedded and non embedded) could change it globally for controller and etcd client logging.
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 have two problems with the current implementation:
- I don't want to export a public func that allows setting a different etcd logger. I would like to keep this an implementation detail as much as possible
- I think the --v log levels don't map well to the zap log levels. They seem to follow a different philosophy (--v=0-10 vs debug,info, ...)
So I would suggest:
- Let's introduce a new command line flag for the KCP controller. Something like "etcd-client-log-level"
- Create the etcd logger in main.go and pass it through the KubeadmControlPlaneReconciler structs down all the way to where we use it
The flag should have (at least) the following possible values: 'debug', 'info', 'error', 'panic'. (of course we have to map the strings to the zap log level types)
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.
Ok, it's not a problem to implement additional option, i.e. etcd-client-log-level
. I will do it.
But please have a look at this description, it seems to there is a logic to convert logr level to zapcore
https://github.com/go-logr/zapr/blob/6a622587cb9d0540da5cd87a37621cb08eaf8e67/zapr.go#L50-L53
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.
Interesting. I thought zap has the following log levels:
- Debug -1
- Info 0
- Warn 1
- Error 2
- DPanic 3
- Panic 4
- Fatal 5
https://github.com/uber-go/zap/blob/master/zapcore/level.go#L35-L52
What am I misinterpreting? :)
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.
Yeah, description and code are bit confusing. Now I understand that your original approach is more suitable for our case, without SetLogger exporting.
Will implement it soon.
f287221
to
9bbad37
Compare
9bbad37
to
35ee04e
Compare
d82f0f3
to
2e898fa
Compare
/test pull-cluster-api-test-main |
/retest |
# Conflicts: # controlplane/kubeadm/internal/controllers/controller.go
8734a21
to
a64e1a1
Compare
What this PR does / why we need it:
For some reasons, we need to adjust ECTD client logger level to avoid have an unpredictable number of warnings in the log, like
But now, ETCD log level is hardcoded to the
zapcore.InfoLevel
. This PR allows to redefine it on init in the embedded controllers. If we need to redefine it globally with env variable or run option for any deployment, please let me know.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #