-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
pkg/kubelet/server: migrate to structured logs #98643
pkg/kubelet/server: migrate to structured logs #98643
Conversation
/retest |
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.
This looks pretty good to me, I had a few small suggestions.
/assign @serathius
/triage accepted
/priority important-longterm
I'm not sure if structured logging is targeted for 1.21 so leaving as important-longterm as opposed to soon.
pkg/kubelet/server/server.go
Outdated
@@ -145,7 +145,7 @@ func ListenAndServeKubeletServer( | |||
enableDebuggingHandlers, | |||
enableContentionProfiling, | |||
enableSystemLogHandler bool) { | |||
klog.Infof("Starting to listen on %s:%d", address, port) | |||
klog.InfoS("Starting to listen server", "address", address, "port", port) |
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.
klog.InfoS("Starting to listen server", "address", address, "port", port) | |
klog.InfoS("Starting to listen", "address", address, "port", port) |
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.
Thanks for the advice, I have fixed it.
pkg/kubelet/server/server.go
Outdated
@@ -167,7 +167,7 @@ func ListenAndServeKubeletServer( | |||
|
|||
// ListenAndServeKubeletReadOnlyServer initializes a server to respond to HTTP network requests on the Kubelet. | |||
func ListenAndServeKubeletReadOnlyServer(host HostInterface, resourceAnalyzer stats.ResourceAnalyzer, address net.IP, port uint, enableCAdvisorJSONEndpoints bool) { | |||
klog.V(1).Infof("Starting to listen read-only on %s:%d", address, port) | |||
klog.V(1).InfoS("Starting to listen read-only server", "address", address, "port", port) |
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.
klog.V(1).InfoS("Starting to listen read-only server", "address", address, "port", port) | |
klog.V(1).InfoS("Starting to listen read-only", "address", address, "port", port) |
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.
Does it make any sense that this is V(1) and the previous server is always logged? Maybe we should just always log both...
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.
Thanks for the advice, I have fixed it. I also think V(1) is redundant, I've deleted it.
f53424b
to
cd3385c
Compare
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.
/lgtm
pkg/kubelet/server/server.go
Outdated
msg := fmt.Sprintf("Authorization error (user=%s, verb=%s, resource=%s, subresource=%s)", attrs.GetUser().GetName(), attrs.GetVerb(), attrs.GetResource(), attrs.GetSubresource()) | ||
klog.Errorf(msg, err) | ||
klog.ErrorS(err, msg) |
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.
Please pass all arguments directly to call
klog.ErrorS(err, "Authorization error", "user" attrs.GetUser().GetName(), "verb", attrs.GetVerb(), "resource", attrs.GetResouce(), "subresource", attrs.GetSubresource())
pkg/kubelet/server/auth.go
Outdated
@@ -109,7 +109,7 @@ func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *htt | |||
attrs.Subresource = "spec" | |||
} | |||
|
|||
klog.V(5).Infof("Node request attributes: user=%#v attrs=%#v", attrs.GetUser(), attrs) | |||
klog.V(5).InfoS("Node request attributes", "user", attrs.GetUser(), "attrs", attrs) |
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.
Should attrs be replaced with something like
klog.V(5).InfoS("Node request attributes"", "user", attrs.GetUser().GetName(), "verb", attrs.GetVerb(), "resource", attrs.GetResource(), "subresource", attrs.GetSubresource())
?
pkg/kubelet/server/stats/handler.go
Outdated
@@ -295,7 +295,7 @@ func (h *handler) handlePodContainer(request *restful.Request, response *restful | |||
|
|||
pod, ok := h.provider.GetPodByName(params["namespace"], params["podName"]) | |||
if !ok { | |||
klog.V(4).Infof("Container not found: %v", params) | |||
klog.V(4).InfoS("Container not found", "params", params) |
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.
klog.V(4).InfoS("Container not found", "params", params) | |
klog.V(4).InfoS("Container not found", "pod", klog.KRef(params["namespace"], params["podName"])) |
@@ -109,7 +109,7 @@ func (s *volumeStatCalculator) calcAndStoreStats() { | |||
if err != nil { | |||
// Expected for Volumes that don't support Metrics | |||
if !volume.IsNotSupported(err) { | |||
klog.V(4).Infof("Failed to calculate volume metrics for pod %s volume %s: %+v", format.Pod(s.pod), name, err) | |||
klog.V(4).InfoS("Failed to calculate volume metrics", "pod", format.Pod(s.pod), "volumeName", name, "err", err) |
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 don't know what format.Pod does but we should use:
klog.KObj
ifs.pod
is an objectklog.KRef
otherwise if we have access to pod name and pod namespace
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.
format.Pod returns a string of the format pod.Name, pod.Namespace, pod.UID
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/util/format/pod.go#L32.
I guess then in this case it is right to go with klog.KObj
?
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.
yes
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.
Left some comments
cd3385c
to
924bace
Compare
Looks good, please fix test failures. |
/retest |
924bace
to
db5de91
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chenyw1990, mrunalp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
/retest Review the full test history for this PR. Silence the bot with an |
1 similar comment
/retest Review the full test history for this PR. Silence the bot with an |
/test pull-kubernetes-e2e-kind |
/retest Review the full test history for this PR. Silence the bot with an |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: