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

Support JSON log format #5571

Closed
sbueringer opened this issue Nov 2, 2021 · 6 comments · Fixed by #6072
Closed

Support JSON log format #5571

sbueringer opened this issue Nov 2, 2021 · 6 comments · Fixed by #6072
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Milestone

Comments

@sbueringer
Copy link
Member

User Story

As a user I would like to be able to run the CAPI controllers with JSON log format as it's easier to parse (e.g. could be easily parsed in Loki LogQL queries).

Detailed Description

We're already using structured logging in our code (on the logger with k/v pairs), but it's currently not possible to actually configure our controllers to log in JSON format.

Anything else you would like to add:

This issue came up here: #5336 (comment)

/kind feature
(couldn't find a better area)
/area health

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. area/health labels Nov 2, 2021
@sbueringer
Copy link
Member Author

sbueringer commented Nov 2, 2021

@randomvariable Can you maybe please add some additional context. It sounded like there is more history / related issues on this (#5336 (comment) and #5336 (comment)).

@vincepri
Copy link
Member

vincepri commented Nov 3, 2021

Let's make this an opt-in flag

/milestone v1.1

@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 3, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 1, 2022
@fabriziopandini
Copy link
Member

/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 1, 2022
@fabriziopandini fabriziopandini modified the milestones: v1.1, v1.2 Feb 3, 2022
@sbueringer
Copy link
Member Author

sbueringer commented Feb 9, 2022

Update from the exploration on PR #6072:

  • klog does not support the JSON log format
  • components-base/logs supports the JSON log format

I think we should consider using components-base/logs as it provides us a lot of useful features:

  • support for JSON log format via --logging-format (default is "text" as "json" is currently alpha: doc)
    • Some pros of JSON log format (from the KEP):
      • Broadly adopted by logging libraries with very efficient implementations (zap, zerolog).
      • Out of the box support by many logging backends (Elasticsearch, Stackdriver, BigQuery, Splunk)
      • Easily parsable and transformable
      • Existing tools for ad-hoc analysis (jq)
  • --experimental-logging-sanitization flag which enables the klog SanitizingFilter. This sanitizes logging of types like crypto/x509.Certificate automatically and also allows as to flag fields on structs for sanitation.
  • klog flags are deprecated in sync with core Kubernetes components (kep)
    • flags are deprecated as soon was use component-base/logs
    • k/k is planning to drop the flags in 1.26 (we could drop them earlier or support them longer if we want)
    • Note: those flags are not deprecated in klog itself, only in k/k through component-base/logs (more details in the KEP)

My opinion:

I think it makes sense to deprecate the klog flags in ClusterAPI too for the same reasons mentioned in the KEP (tl;dr mainly 12 factor apps => drop flags for file logging).
I also think it makes sense to use component-base/logs as we get JSON logging for free, without having to implement a JSON logger ourselves. Downside is that we depend on upstream k/component-base, but I think this should be fine or even an advantage when we want to align with upstream components.

Related issues:

References:

@sbueringer
Copy link
Member Author

sbueringer commented Feb 16, 2022

Just fyi. The klog version we currently use has an issue that it doesn't propagate verbosity correctly, i.e. with JSON log format the v key is always 0. This issue has been just fixed in klog: kubernetes/klog#294.

I expect that there will be a new klog version that we can pick up with the next Kubernetes / controller-runtime release before our release.

Independent of that, I don't think it should block us as the JSON log format is currently alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants