-
Notifications
You must be signed in to change notification settings - Fork 593
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
Spike: dual logging implementations in Controller Manager #1893
Comments
I need a clarification whether we want to continue using |
At this point it would seem best that we simply use sigs.k8s.io/controller-runtime/pkg/log which is a relevant go-logr implementation that is in use elsewhere in our ecosystem, and then ultimately drop logrus. Here's the simplest entrypoint for creating these loggers: https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/log#FromContext |
I've done some research and it seems sigs.k8s.io/controller-runtime/pkg/log actually is just an utility. That package delegates logging to the other implementation of That means we still need to setup some kind of logger. There is klog in kubernetes, but it has different log format that logrus:
klog:
zap
We might as well consider other packages, like zap The other thing I've noticed is that I initially planned to replace |
Perhaps I've missed something, but it also provides
I appreciate the explanation of some of the various drawbacks with different options. At this point are you simply reporting where you're at so far and there's more investigation to be done, do you have a preferred direction from here, or are you looking for input to move forward? |
I don't think it should be implemented before 3.0. Numeric Changing logging semantics or format (as a result of using a new library) can be considered a breaking change for log consumers. I propose we create a document describing current logging state in kic, desired logging state, possible solutions. Then we review it and implement for 3.0. |
I agree, this is going to get messy if we're not allowed to make some backwards incompatible changes. Let's hold for |
This item requires understanding of the cost-to-benefit trade-off. Therefore, repurposed it as a spike. The desired output of a spike is a recommendation "yes, this will pay off" vs "no, too much work for unclear gain or clear but small gain" |
Idle since July so I'm stealing it. https://gist.github.com/rainest/4d82f944416903f448d49c52ac4ff5cb is a spike on the status quo and cost estimation. Major takeaways:
I recommend working on conversion to logr for a day or so to see how far we get. It's probably not that hard once we actually start doing it. We should see if we can address the level printing issue with logrusr modifications or alternate logr backends first. If alternate backends fix it, the benefit of going all logr is greater. |
2 cents from my side:
Having said that I do realize those are all different than proposed or rather already used logging packages but while at it we might just do it right and at least think about those. |
logr is an interface that supports multiple backends. Our problem is that not everything uses it, and that we keep adding new things that don't use it, and just use logrus directly. We may as well use it rather than rolling our own insofar as controller-runtime uses it and we don't have known things we want that it cannot handle. The zapr wrapper does apparently fix the level problem out of the box. With our current logrusr:
with the laziest possible zap replacement
we get:
from So it at least solves that problem. We have some KIC-specific glue that apparently approximates the shared-go level int constants, but the main task is to migrate the exclusively logrus stuff anyway. |
From attempting to actually do the conversion, starting "somewhere in the parser" was probably a poor choice since its logger gets shared to basically everything under This is a good example since it tests its log output. It does fail on the log level due to the "everything converts to info" problem:
Log testing isn't that common, but requires using the underlying test library. logr does have a testing implementation, but it looks like that's for outputting to the test log rather than testing log content. If we want to convert to something other than logrus (for zap, using https://pkg.go.dev/go.uber.org/[email protected]/zaptest/observer), we should probably do it in one go. Our shared-go is currently private, so I don't think we can use it unless we intend to open-source it. Maybe we can? It looks like it mostly adds the ability to handle both logging and tracing spans from the context, and uses zap for the logging portion. I don't think that we have any requests for tracing, and it's not obviously useful for KIC's role (we aren't in the middle of a request handling pipeline), so we could probably live without that. Istio does provide an Apache-licensed klog shim that shunts it to zap if we want to try and deal with the client-go logs. Between that, the existing logr log level fix, and it being actively maintained and fairly ubiquitous, I'd say go with zap under go-logr. |
zap's default encoders don't support anything that's exactly like the logrus text format with logrus text:
zap text:
There is an inactive PR that's asked to add this, but it looks like it likely won't make it into the core. I suspect that we could pull that in with https://pkg.go.dev/go.uber.org/zap#RegisterEncoder if we wanted. If not, the zap argument is that anyone that wants to actually parse the logs should be using JSON (or some other computer-readable format), which isn't really wrong--logrus default is maybe more computer readable, though I don't know if it's a proper format. logrus JSON:
zap JSON:
|
Level handling actually seems a bit off in zapr. Regular zap levels start at -1 (debug), and then go up through 0 (info), 1 (warn), 2 (error), and so on. logr's zapr The negative levels also don't work great with the basic custom check function I had to add for custom output since an zapr had a request to allow mapping V levels to arbitrary zap levels, but did not fulfill it. The recommendation there is sorta to actually drop the native zap level field, since it doesn't really correspond to the expectations of V levels. controller-runtime has no expectations around semantic levels, so any added mapper wouldn't really work there. We weren't using WARN that often (there were some existing logr calls using it, but those were already getting squashed to INFO), so converting to logging the actual V level instead shouldn't be too much of a break:
controller-runtime mostly logs at either 0 (info) or 1 (debug), though there are a smattering of V4 and V5 lines. |
Is there an existing issue for this?
Problem Statement
As an interim fix to bridge the gap between our previous use of logrus and controller manager's requirements on using go-logr we implemented using both to reduce the changes for the 2.0 release.
We ended up using logrusr as middleware to allow us to allow for both implementations, but this leaves something to be desired in terms of code maintenance.
Proposed Solution
--log-level
controller manager flagAdditional information
It's theoretically reasonable to do the opposite of the proposed solution, as long as we end up with one clear and documented method and we establish all of our implementation requirements and ensure they are met.
Acceptance Criteria
The text was updated successfully, but these errors were encountered: