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

add --logging-format flag to kubelet #91532

Merged
merged 4 commits into from
Jul 2, 2020

Conversation

AfrouzMashayekhi
Copy link
Contributor

@AfrouzMashayekhi AfrouzMashayekhi commented May 28, 2020

What type of PR is this?

/kind feature

What this PR does / why we need it:
Ref kubernetes/enhancements#1602

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

kubelet: add '--logging-format' flag to support structured logging

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 28, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @afrouzMashaykhi!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 28, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @afrouzMashaykhi. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 28, 2020
@AfrouzMashayekhi
Copy link
Contributor Author

/cc @serathius

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 28, 2020
@serathius
Copy link
Contributor

Hey @afrouzMashaykhi Thanks for contributing!
Adding flag to Kubelet is more complicated due support to dynamic configuration. We need to add LoggingFormat field to KubeletConfig object and update all API generation.
Exmple. #85282

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 28, 2020
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. labels May 28, 2020
}

errs = append(errs, f.Logs.Validate()...)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the validation passes here, would this append a nil error to the slice, and result in a validation failure further up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed validation of logformat

@@ -500,6 +500,8 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate f
if err != nil {
klog.Errorf("unable to register KubeletConfiguration with configz, error: %v", err)
}
// set klog of kubelet
s.Logs.Apply()
Copy link
Contributor

Choose a reason for hiding this comment

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

Applying the config to global settings should probably happen super-early in the bootstrap.
We can start writing logs almost immediately:

Run: func(cmd *cobra.Command, args []string) {
// initial flag parse, since we disable cobra's flag parsing
if err := cleanFlagSet.Parse(args); err != nil {
cmd.Usage()
klog.Fatal(err)
}
// check if there are non-flag arguments in the command line
cmds := cleanFlagSet.Args()
if len(cmds) > 0 {
cmd.Usage()
klog.Fatalf("unknown command: %s", cmds[0])
}

Also, are any additional changes required wrt the InitLogs call in https://github.com/kubernetes/kubernetes/blob/master/cmd/kubelet/kubelet.go#L38?

Copy link
Contributor Author

@AfrouzMashayekhi AfrouzMashayekhi May 31, 2020

Choose a reason for hiding this comment

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

Based on KEP the logging format flag just sets the format of logging and I think, changing log messages handled by new klog methods. @serathius please correct me if I am wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Michael are you proposing then that we move this --logging-format flag init/setup/apply to InitLogs? This would mean that we would need to make this flag global.
In #89683 we have implemented it as standard flag initialized with component. Like you mentioned that it has problem that we invoke klog before we initialize components.

Pros of global flag:

  • Consistent logging configuration (as initialization happens before component bootstrap)

Cons:

  • All logging flags will need to be kept as global flag
  • LoggerConfig cannot be added to Components (no dynamic config, no control for component owner about this flag)

I think that having consistent log format is important so we should go with global flag. This would mean that all PRs adding LoggingConfig are no longer needed :(. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily into InitLogs - just that logging config should probably be set before any log messages are written?

@mtaufen
Copy link
Contributor

mtaufen commented May 28, 2020

And as @serathius mentioned, there are a few additional changes required to support the kubelet config file. You can find details in our contributor guide for migrating flags to config: https://docs.google.com/document/d/10Kz__miCWEOekC6WnsUdxYWSLrf-t1AkHHpZN57ei5c/edit

@serathius
Copy link
Contributor

/ok-to-test

@serathius
Copy link
Contributor

/milestone v1.19

@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jul 1, 2020
@liggitt
Copy link
Member

liggitt commented Jul 1, 2020

to fix the fuzzer test, update pkg/kubelet/apis/config/fuzzer/fuzzer.go to match the default logging format:

--- a/pkg/kubelet/apis/config/fuzzer/fuzzer.go
+++ b/pkg/kubelet/apis/config/fuzzer/fuzzer.go
@@ -99,6 +99,9 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
 			obj.ConfigMapAndSecretChangeDetectionStrategy = "Watch"
 			obj.AllowedUnsafeSysctls = []string{}
 			obj.VolumePluginDir = kubeletconfigv1beta1.DefaultVolumePluginDir
+			if obj.Logging.Format == "" {
+				obj.Logging.Format = "text"
+			}
 		},
 	}
 }

@liggitt
Copy link
Member

liggitt commented Jul 1, 2020

/approve

lgtm once the fuzzer test is fixed

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrouzMashaykhi, liggitt, mtaufen, wojtek-t

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 Jul 1, 2020
@serathius
Copy link
Contributor

/retest

1 similar comment
@serathius
Copy link
Contributor

/retest

@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 Jul 1, 2020
@AfrouzMashayekhi
Copy link
Contributor Author

/retest

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

@serathius
Copy link
Contributor

/retest

1 similar comment
@AfrouzMashayekhi
Copy link
Contributor Author

/retest

@serathius
Copy link
Contributor

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 2, 2020
@AfrouzMashayekhi
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

@afrouzMashaykhi: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-e2e-kind b92b04e link /test pull-kubernetes-e2e-kind

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@serathius
Copy link
Contributor

/retest

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/dependency Issues or PRs related to dependency changes area/kubeadm area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants