-
Notifications
You must be signed in to change notification settings - Fork 65
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
Inconsistent logs formats #295
Comments
Hey @ikvmw, this "E0201" message is from the controller runtime, or somwhere deep inside k8's. I deployed the messaging topology operator on a GKE cluster and saw some similar formatted log lines with different messages e.g:
After conferring with @ChunyiLyu, I don't think we can capture these events and wrap them in the json format simillar to logs from the logger in our operators. I think we can close this issue, let me know. |
This issue is present in all of our operators that use controller-runtime. The problem is because controller-runtime's logger is a separate logger to the one used in client-go. Kubebuilder scaffolds the controller-runtime logger with Zap logger config, that can also be passed in on the command line of the operator, but client-go uses the klog logger. See this issue: kubernetes-sigs/controller-runtime#1420 (comment) With a fairly simple diff, you can set the LogSink of the klog logger in the operator to match the controller-runtime logger: diff --git a/main.go b/main.go
index a86b114..644aacf 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ package main
import (
"flag"
"fmt"
+ "k8s.io/klog/v2"
"os"
"regexp"
"strings"
@@ -73,7 +74,9 @@ func main() {
flag.Parse()
- ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
+ logger := zap.New(zap.UseFlagOptions(&opts))
+ ctrl.SetLogger(logger)
+ // https://github.com/kubernetes-sigs/controller-runtime/issues/1420#issuecomment-794525248
+ klog.SetLogger(logger.WithName("messaging-topology-operator")) leading to output like:
This would change any klog logging done by our dependencies (which I think is just client-go) to be output in this format, which I think is worth it for consistency. What do you think? |
Hey Connor, thanks for this context! I was struggling to find this when I had a look at this issue. This is super useful, thanks! |
Describe the bug
I was debugging my kubernetes installation the other day. I wanted to correlate a resource status that waited on queue with topology operator logs. I noticed that topology operator emits logs in at least two different formats which makes it harder to comprehend and process automatically.
To Reproduce
Just use topology operator I guess.
Expected behavior
All log entries follow the same format.
Screenshots
Version and environment information
Additional context
Text examples:
The text was updated successfully, but these errors were encountered: