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
Improve logging #1826
Comments
+1 from me to standardize and be consistent with upstream Kubernetes |
I am not a fan of the nested namespace and name, that makes querying harder. What is the advantage of that? |
To be honest, I'm not sure. I just saw in the Kubernetes structured logging KEP that they are rendering it like that in the JSON log format (and thus they codified it accordingly in klog). I don't really have a strong opinion on having the nested object, the only argument from my side is "consistency would be nice". @pohly If you have some time to chime in, do you know by any chance why that decision was made? |
Maybe the reason is to allow finding all logs related to a given object, which might not necesarily come from the controller that owns it. For example, a deployment controller will create a replicaset and the replicaset controller pods and if you want to find all logs related to a given replicaset, you can filter for Maybe we can simply do both the nested/typed namespace+name and a top-level namespace+name? |
The decision to use |
@pohly the question was why the namespace and name are in a subobject for the type, i.E.
rather than a toplevel |
Because the |
Oh I misunderstood the question. I thought it was about having namespace and name separately. But as you said, having them in a nested object has the advantage that we can filter them across controller logs. By having namespace/name for all of them nested we can simply filter with
It is possible, we currently do this in controller-runtime, but we don't use klog.Obj to do it. We just simple add one top-level
Sounds like a good compromise if we don't mind the duplicate information. For me it would be fine. |
That's a bit different because you now add two different key/value pairs instead of a single one. The downside is that plain-text output becomes a bit more verbose. Passing the result of KObj has the advantage that the logging backend can pick a suitable representation for the value. |
I've updated the issue description to also align reconciler group/kind. |
I would like to propose to adjust CR logging.
Today, controller-runtime logs have the following format: (when JSON logging is used)
I would like to propose the following format instead:
The delta is:
The ideas behind that are:
Drop the message prefix
Log
"<kind>": "<namespace>/<name>"
instead of"namespace"
and"name"
Add a reconcileID
With a reconcileID it is very easy to identify logs belong to the same reconcile operation.
Change reconciler kind/ group to controllerKind and controllerGroup
Given that Reconciler only seems to be the "inner" reconciler provided by the user, I think we should rather use controller (e.g. we're setting the name and object on the
NewControllerManagedBy
Builder )Also to align with "casing" best practices outlined here: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments
I've opened a PR to show how a potential solution would look like: ⚠ logging: align to Kubernetes structured logging, add reconcileID
P.S.
The text was updated successfully, but these errors were encountered: