-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨ logging: allow override default logger for compatibility #1971
✨ logging: allow override default logger for compatibility #1971
Conversation
Signed-off-by: Tianpeng Wang <[email protected]>
Welcome @timonwong! |
Hi @timonwong. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: timonwong 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 |
Can you elaborate why that is hard and easier with this? From what I can tell the only thing it does is putting a logger into a closure |
Previously, we just construct multiple loggers (our logging facility is similar to istio's, which registers each business "scope", and their levels can be changed at runtime separately), pseudo-code : var genericControlPlaneLogger = logging.RegisterScope("control-plane")
var istioUpdateLogger = logging.RegisterScope("istio-update")
var domainLogger = logging.RegisterScope("domain")
var wasmLogger = logging.RegisterScope("wasm")
// etc, etc
// and there are multiple controllers, each controller setup with the builder:
ctrl1.WithLogger(genericControlPlaneLogger).Build()
ctrl2.WithLogger(istioUpdateLogger).Build()
ctrl3.WithLogger(domainLogger).Build()
ctrl4.WithLogger(wasmLogger).Build()
// etc, etc And previously, logger keys "controller", "controllerGroup", "controllerKind" are auto-generated (after #1827, when customized logger with var genericControlPlaneLogger = logging.RegisterScope("control-plane")
var istioUpdateLogger = logging.RegisterScope("istio-update")
var domainLogger = logging.RegisterScope("domain")
var wasmLogger = logging.RegisterScope("wasm")
// etc, etc
func logConstructorFunc(logger logr.Logger, controllerName string, gvk schema.GroupVersionKind) func(*reconcile.Request) logr.Logger {
return func(req *reconcile.Request) logr.Logger {
logger = logger.WithValues("controller", controller, "controllerGroup", gvk.Group, "controllerKind", gvk.Kind)
if req != nil {
logger = logger.WithValues(gvk.Kind, klog.KRef(req.Namespace, req.Name), "namespace", req.Namespace, "name", req.Name)
}
return logger
}
}
ctrl1.WithLogConstructor(logConstructorFunc(genericControlPlaneLogger, ...)).Build()
ctrl2.WithLogConstructor(logConstructorFunc(istioUpdateLogger, ...)).Build()
ctrl3.WithLogConstructor(logConstructorFunc(domainLogger, ...)).Build()
ctrl4.WithLogConstructor(logConstructorFunc(wasmLogger, ...)).Build() You can see it (func logConstructorFunc) requires more work to archive same functionality as |
} else { | ||
log = blder.mgr.GetLogger() | ||
} | ||
|
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.
IHMO we should have only one log approach and ideally follow the k8s standards.
Why?
- That helps those that are looking for Oberservaility, many tools will try to check the logs centralized. So that we can ensure that any project built with controller-runtime will follow up the same approach/standard
- Maintainability. We do not increase the burn to have more implementation for logs
- Encourage standards and good practices
In this way, I'd like to raise a question: What is the k8s format? Is k8s doing the logs using the format of WithLogConstructor or of the removed WithLogger?
/hold
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.
k8s uses klog, which is derived from good-old glog.
In that case, I think it's better to avoid the use of logr, which backend is configurable (zap, logrus, zerolog, go-kit, klog, etc... leads users to choose their fav logger library), we can stick to klog instead.
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.
Hi @timonwong,
I think that what matters, in this case, is more the output/format of the logs. According to the description of #1827 the goal was: align to Kubernetes structured logging, add reconcileID
However, I think would be nice if we could check how the format is outputted by k8s as the dep (which you already checked) and if we can or do not follow the same standards. if not, why not? Also, have we any Kubernetes good practices definition about it? If so, I think we should also follow up on that. By last, I think also would be nice to understand why we are using Logger
and not klog. What was the motivation for this adoption instead of klog?
(IMHO) the above assessment needs to be done before we propose changes. If we figure out that we need to change then, maybe open an issue describing the proposal and motivations for that can help out in the discussion. Also, a PR proposing the changes based on the motivations can be helpful for sure too.
WDYT?
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.
@camilamacedo86 I think a lot of what you are asking here is orthogonal to this change. This changes goal is to have the same fields that get set when a logger comes from the mgr when a custom logger is used.
I agree that it is not great to have two ways to set a custom logger that are different in a very subtle way.
@timonwong how about instead just adding the fields unconditionally, regardless of logConstructor being set or not? The new api this introduces is IMHO not great, from a users POV it is very difficult to understand what the difference between |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
#1827 introduces
WithLogConstructor
and removedWithLogger
but in practical it's very hard to useWithLogConstructor
to inject fields like:This PR proposes we can keep
WithLogger
for backward-compat.