Skip to content
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

Merged

Conversation

chenyw1990
Copy link
Contributor

@chenyw1990 chenyw1990 commented Feb 1, 2021

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?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 1, 2021
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 1, 2021
@chenyw1990
Copy link
Contributor Author

/retest

Copy link
Member

@ehashman ehashman left a 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.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
klog.InfoS("Starting to listen server", "address", address, "port", port)
klog.InfoS("Starting to listen", "address", address, "port", port)

Copy link
Contributor Author

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.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Member

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...

Copy link
Contributor Author

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.

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 1, 2021
@chenyw1990 chenyw1990 force-pushed the structuredLogsOfKubeletServer branch from f53424b to cd3385c Compare February 2, 2021 01:18
Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 3, 2021
Comment on lines 274 to 275
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)
Copy link
Contributor

@serathius serathius Feb 5, 2021

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())

@@ -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)
Copy link
Contributor

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())

?

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

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 if s.pod is an object
  • klog.KRef otherwise if we have access to pod name and pod namespace

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor

@serathius serathius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

@chenyw1990 chenyw1990 force-pushed the structuredLogsOfKubeletServer branch from cd3385c to 924bace Compare February 8, 2021 11:47
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 8, 2021
@serathius
Copy link
Contributor

Looks good, please fix test failures.

@chenyw1990
Copy link
Contributor Author

/retest

@chenyw1990 chenyw1990 force-pushed the structuredLogsOfKubeletServer branch from 924bace to db5de91 Compare February 9, 2021 07:38
@mrunalp
Copy link
Contributor

mrunalp commented Feb 9, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 9, 2021
@serathius
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2021
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@chenyw1990
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 071bdc3 into kubernetes:master Feb 10, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Feb 10, 2021
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

7 participants