Skip to content

Add support for json logging format - #5828

Merged
jetstack-bot merged 7 commits into
cert-manager:masterfrom
malovme:structured-logs
May 5, 2023
Merged

jetstack-bot merged 7 commits into
cert-manager:masterfrom
malovme:structured-logs

Conversation

@malovme

@malovme malovme commented Feb 24, 2023 •

Copy link
Copy Markdown
Contributor

Pull Request Motivation

Structured logging (JSON format) can be enabled.
Related issue: #2605

Kind

feature

Release Note

Added support for JSON logging (using --logging-format=json)

@jetstack-bot jetstack-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Feb 24, 2023
@jetstack-bot

Copy link
Copy Markdown
Contributor

Hi @malovme. Thanks for your PR.

I'm waiting for a cert-manager 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.

Details

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.

@jetstack-bot jetstack-bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 24, 2023
Comment thread cmd/cainjector/main.go Resolved
@inteon

inteon commented Feb 24, 2023 •

Copy link
Copy Markdown
Member

@malovme I think what we want to do is update our github.com/cert-manager/cert-manager/pkg/logs wrapper and use k8s.io/component-base/logs or k8s.io/component-base/logs/api/v1 in that wrapper (see https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md and https://pkg.go.dev/k8s.io/component-base/logs for more info).

BTW: feel free to ask any remaining small questions via Slack

@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 1, 2023
@jetstack-bot jetstack-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 2, 2023
@malovme malovme changed the title WIP: Enable structured logging Add support for json logging format Mar 2, 2023
@jetstack-bot jetstack-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 2, 2023
@malovme malovme changed the title Add support for json logging format WIP: Add support for json logging format Mar 2, 2023
@jetstack-bot jetstack-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 2, 2023
@inteon

inteon commented Mar 2, 2023

Copy link
Copy Markdown
Member

/ok-to-test

@jetstack-bot jetstack-bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 2, 2023
@malovme
malovme force-pushed the structured-logs branch 2 times, most recently from 5c83360 to 3496651 Compare March 3, 2023 11:53
@malovme malovme changed the title WIP: Add support for json logging format Add support for json logging format Mar 3, 2023
@jetstack-bot jetstack-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 3, 2023
@malovme

malovme commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

/kind feature

@jetstack-bot jetstack-bot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Mar 3, 2023
@malovme

malovme commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

/test pull-cert-manager-master-make-test

@inteon

inteon commented Mar 7, 2023 •

Copy link
Copy Markdown
Member

Wonderful! I now have these options:
image

I think we have to use InfoS/ ErrorS everywhere (see https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md) to make sure the json is better structured (see last line in example below).

$ _bin/server/controller-linux-amd64 --logging-format=json
{"ts":1678180968324.884,"caller":"clientcmd/client_config.go:618","msg":"Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.\n","v":0}
{"ts":1678180968324.9226,"caller":"clientcmd/client_config.go:623","msg":"error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined\n","v":0}
{"ts":1678180968325.4653,"caller":"./main.go:39","msg":"cert-manager \"msg\"=\"error while executing\" \"error\"=\"error creating rest config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\" \n"}

UPDATE: the wrong structure was not caused by not using InfoS/ ErrorS. We are already using the new API which uses the function names Info and Error for structured logging. The incorrect JSON structure was caused by this: https://github.com/kubernetes/klog/blob/main/klogr/klogr.go#L42-L43. In c84212e, I fixed the issue.

@jetstack-bot jetstack-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 2, 2023
@inteon
inteon force-pushed the structured-logs branch 3 times, most recently from 37be0d3 to 4fa2641 Compare May 4, 2023 10:36
@inteon

inteon commented May 4, 2023

Copy link
Copy Markdown
Member

@maelvls I updated the PR with the requested changes, could you take a look?

@maelvls

maelvls commented May 5, 2023

Copy link
Copy Markdown
Member

Why do need to add all those new flags to acmesolver? I understand that adding -v to the acmesolver makes things more consistant, but I don't see the use-case. I can't see why someone would like to use -v in the first place. IMO, acmesolver should log in debug mode at all times since the only thing it logs is the incoming HTTP requests.

Furthermore, people have no way to configure the acmesolver with the new flags. It makes little sense to add all these new flags when people can't use them.

Could you move the acmesolver changes to a new PR?

@inteon

inteon commented May 5, 2023

Copy link
Copy Markdown
Member

Why do need to add all those new flags to acmesolver? I understand that adding -v to the acmesolver makes things more consistant, but I don't see the use-case. I can't see why someone would like to use -v in the first place. IMO, acmesolver should log in debug mode at all times since the only thing it logs is the incoming HTTP requests.

Furthermore, people have no way to configure the acmesolver with the new flags. It makes little sense to add all these new flags when people can't use them.

Could you move the acmesolver changes to a new PR?

I removed the flags from acmesolver.

Comment thread cmd/acmesolver/app/app.go Resolved
Comment thread cmd/acmesolver/app/app.go Resolved
Comment thread cmd/cainjector/app/start.go Resolved
Comment thread cmd/cainjector/app/start.go Resolved
Comment thread pkg/logs/logs.go Resolved
Comment thread pkg/logs/logs.go Resolved
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: inteon, malovme

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

Comment thread pkg/logs/logs.go Resolved
Comment thread cmd/cainjector/app/start.go Resolved
Comment thread cmd/webhook/main.go Resolved
Comment thread pkg/controller/test/context_builder.go Resolved
Comment thread pkg/logs/logs.go Resolved
@maelvls

maelvls commented May 5, 2023

Copy link
Copy Markdown
Member

Thanks for the improvements, Tim. The acmesolver should now output consistent klog-style logs instead of fmt.Fprint.

It looks good to me now.

/lgtm

@jetstack-bot

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

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/acme Indicates a PR directly modifies the ACME Issuer code area/testing Issues relating to testing dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants