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

feat(logging): migration to structure logging for main.go, pkg/ & internal/ folders #1807

Merged
merged 5 commits into from
Aug 16, 2022

Conversation

dmpe
Copy link
Contributor

@dmpe dmpe commented Aug 13, 2022

What this PR does / why we need it:

/wg structured-logging
/area logging
/priority important-longterm
/kind cleanup
/cc @kubernetes/wg-structured-logging-reviews

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)

does not change cardinality

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

part 1 of adding JSON support #1485, i.e. with this PR we introduce structure logging, by following the associated KEP https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md

@k8s-ci-robot k8s-ci-robot added wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. labels Aug 13, 2022
@k8s-ci-robot
Copy link
Contributor

@dmpe: The label(s) area/logging cannot be applied, because the repository doesn't have them.

In response to this:

What this PR does / why we need it:

/wg structured-logging
/area logging
/priority important-longterm
/kind cleanup
/cc @kubernetes/wg-structured-logging-reviews

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)

does not change cardinality

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

part 1 of adding JSON support #1485, i.e. with this PR we introduce structure logging, by following the associated KEP https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md

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 kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 13, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @dmpe!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. 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/kube-state-metrics 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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 13, 2022
@dmpe dmpe changed the title draft: Migration to Structure logging WIP: Migration to Structure logging Aug 13, 2022
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 13, 2022
@dmpe
Copy link
Contributor Author

dmpe commented Aug 13, 2022

I have tested this locally via e2e tests and it did not fail :)

When starting kube state metrics before my PR:

 ./kube-state-metrics 
I0813 14:05:15.320475   51084 server.go:93] Using default resources
I0813 14:05:15.322843   51084 types.go:136] Using all namespace
I0813 14:05:15.322881   51084 server.go:122] Metric allow-denylisting: Excluding the following lists that were on denylist: 
W0813 14:05:15.322905   51084 client_config.go:617] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0813 14:05:15.322917   51084 client_config.go:622] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
F0813 14:05:15.324143   51084 main.go:65] Failed to run kube-state-metrics: failed to create client: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
goroutine 1 [running]:
k8s.io/klog/v2.stacks(0x1)
	/home/jm/go/pkg/mod/k8s.io/klog/v2@v2.60.1/klog.go:860 +0x8a
k8s.io/klog/v2.(*loggingT).output(0x265b260, 0x3, 0x0, 0xc000421960, 0x1, {0x1e675c7?, 0x1?}, 0x265c460?, 0x0)
	/home/jm/go/pkg/mod/k8s.io/klog/v2@v2.60.1/klog.go:825 +0x686
k8s.io/klog/v2.(*loggingT).printfDepth(0x265b260, 0x0?, 0x0, {0x0, 0x0}, 0x7ffa5af073c0?, {0x18a8a12, 0x24}, {0xc0003ba8c0, 0x1, ...})
	/home/jm/go/pkg/mod/k8s.io/klog/v2@v2.60.1/klog.go:630 +0x1f2
k8s.io/klog/v2.(*loggingT).printf(...)
	/home/jm/go/pkg/mod/k8s.io/klog/v2@v2.60.1/klog.go:612
k8s.io/klog/v2.Fatalf(...)
	/home/jm/go/pkg/mod/k8s.io/klog/v2@v2.60.1/klog.go:1516
main.main()
	/home/jm/Documents/kube-state-metrics/main.go:65 +0x514

And after my proposed changes.

./kube-state-metrics 
I0813 14:08:53.765129   51528 server.go:93] "Used default resources"
I0813 14:08:53.765297   51528 types.go:136] "Using all namespace"
I0813 14:08:53.765314   51528 server.go:122] "Metric allow-denylisting" allowDenyStatus="Excluding the following lists that were on denylist: "
W0813 14:08:53.765342   51528 client_config.go:617] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0813 14:08:53.765351   51528 client_config.go:622] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
E0813 14:08:53.765443   51528 main.go:67] "Failed to run kube-state-metrics" err="failed to create client: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable"

@dmpe dmpe changed the title WIP: Migration to Structure logging feat(logging): migration to structure logging for main.go, and pkg/ & internal/ folders Aug 13, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 13, 2022
@dmpe dmpe changed the title feat(logging): migration to structure logging for main.go, and pkg/ & internal/ folders feat(logging): migration to structure logging for main.go, pkg/ & internal/ folders Aug 13, 2022
Signed-off-by: dmpe <John Malc> <cincenko@outlook.com>
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
pkg/options/types.go Outdated Show resolved Hide resolved
pkg/options/types.go Outdated Show resolved Hide resolved
pkg/options/types.go Outdated Show resolved Hide resolved
dmpe and others added 3 commits August 13, 2022 21:44
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
Co-authored-by: JUN YANG <yang.jun22@zte.com.cn>
Copy link
Member

@mrueg mrueg left a comment

Choose a reason for hiding this comment

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

Thanks!
/lgtm

/hold
for @dgrisonnet @fpetkovski to review.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 15, 2022
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 15, 2022
@@ -178,7 +178,7 @@ func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.Registry
for i := range fs {
f := fs[i]
if _, ok := availableStores[f.Name()]; ok {
klog.Warningf("The internal resource store named %s already exists and is overridden by a custom resource store with the same name, please make sure it meets your expectation", f.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because we don't have a way to log warn messages with structure logging?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that does not exist there. See also: kubernetes/klog#184

@fpetkovski
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dmpe, fpetkovski, mrueg

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

@mrueg
Copy link
Member

mrueg commented Aug 16, 2022

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 16, 2022
@k8s-ci-robot k8s-ci-robot merged commit 4bb1b38 into kubernetes:master Aug 16, 2022
@dmpe dmpe deleted the strcuturedlogging_part1 branch August 20, 2022 10:49
@mrueg mrueg mentioned this pull request Aug 24, 2022
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. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants