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

[KEP][sig-instrumentation] Structured logging #1367

Merged
merged 9 commits into from Mar 13, 2020

Conversation

serathius
Copy link
Contributor

@serathius serathius commented Nov 15, 2019

Review progress:

  • @thockin (SIG Architecture, klog owner, Google)
  • @dims (SIG Architecture Chair, klog owner, VMware)
  • @brancz (SIG Instrumentation TL, Red Hat)
  • @mtaufen (component-base owner, Google)
  • @derekwaynecarr (SIG Architecture Chair, SIG Node Chair, Red Hat)

Please let me know if you think you should be added to this list.

Proposal was presented on:

  • sig-instrumentation meeting 2019-12-12
  • sig-architecture meeting 2020-01-16
  • wg-component-standard meeting 2020-02-11

PR will be merged when all reviewers give their lgtm.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. labels Nov 15, 2019
@piosz
Copy link
Member

piosz commented Nov 15, 2019

@piosz
Copy link
Member

piosz commented Nov 15, 2019

@kubernetes/sig-instrumentation-feature-requests

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 15, 2019
@RainbowMango
Copy link
Member

I guess @kubernetes/sig-architecture-feature-requests should be involved.

@k8s-ci-robot k8s-ci-robot added the sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. label Nov 18, 2019
@serathius
Copy link
Contributor Author

PTAL @bogdandrutu

@mtaufen
Copy link
Contributor

mtaufen commented Nov 20, 2019

/wg component-standard
/assign

@k8s-ci-robot k8s-ci-robot added the wg/component-standard Categorizes an issue or PR as relevant to WG Component Standard. label Nov 20, 2019
Copy link
Contributor

@mtaufen mtaufen left a comment

Choose a reason for hiding this comment

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

Thanks @serathius, IMO this would be a significant improvement to our existing logging capability.

Other folks who may be interested:
/cc @dashpole @liggitt @stealthybox @derekwaynecarr @vishh

keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
@ehashman
Copy link
Member

/assign

Won't be able to review before the US Thanksgiving holiday but I'll give this a look next week.

* Only for log lines generated by klog (e.g. prefix `I0129 03:26:19.857798 1 garbagecollector.go:517]`)
* Identified by code line that generated log (e.g. `garbagecollector.go:517`)

We assume that exact details of taking measurements can be improved, but overall methodology is solid. With those criteria we concluded that covering 99.9% of logs on master node are generated by 22 log messages. Exact list of those logs is provided in the detail design section.
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this is just telling you where the noise is, not where the value is. Why assume that today's noise is where the value lies.

Copy link
Contributor

Choose a reason for hiding this comment

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

The volume of logs produced by each klog call is just a proxy for the importance of those logs but indeed it does not mean that those logs are the most valuable.
If you can provide any other criteria to select logs which should be migrated first we might include it in this proposal.

Copy link
Member

Choose a reason for hiding this comment

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

What I like most about this retooled KEP is that it is incremental. Do the "obvious" ones now. As we find more that are valuable, convert them.

Example:

```go
klog.InfoS("Pod status updated", "pod", "kubedns", "status", "ready")
Copy link
Contributor

Choose a reason for hiding this comment

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

most systems I've seen like this desire a message key so that minor changes between versions (line numbers for instance) don't make it impossible to see that the same message (or a new one) is appearing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With log message now not including arguments we can normalize it and use it as a key.

```


### Logging configuration
Copy link
Contributor

@deads2k deads2k Mar 5, 2020

Choose a reason for hiding this comment

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

This appears to be missing filtering per sink. If we're going to introduce new logging configure APIs, that one seems like a big win. Also, the old glog vmodule for loglevel has pretty significant limitations.

Copy link
Contributor

Choose a reason for hiding this comment

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

What kind of filtering would you like to have?
The existing glog vmodule for loglevel will be still available.

Copy link
Member

Choose a reason for hiding this comment

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

I think of this KEP as pretty surgical WRT klog - 2 new functions, 1 new flag. Going beyond that is possible, but a different KEP?

@serathius serathius mentioned this pull request Mar 6, 2020
39 tasks
@serathius
Copy link
Contributor Author

Addressed feedback:

  • Support changing serialization (@deads2k )

Added a section that explicitly mentions how logger implementation can be overridden.

Copy link
Member

@derekwaynecarr derekwaynecarr left a comment

Choose a reason for hiding this comment

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

I agree this is an improvement. I would prefer we could address objects across time and space and not just space which I why I desired uid. If I look at a log for a problem, it may often deal with the same named resource, but maybe I’m uncommon.

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

This KEP is really 3 things, kind of specc'ed at the same time:

  1. Add structured functions to klog and document the output format
  2. Add a JSON output format to klog
  3. Convert kubernetes to use the structured mechanism in a few places
    3a) Add some convenience for logging kubernetes objects

The KEP kind of mixes them up. I'm not proposing to rewrite it, just saying for clarity.

A couple of my comments here are hard blockers, most just need to be discussed and resolved.


To address problem of inconsistency in referencing of Kubernetes objects, new klog methods will include additional logic for handling their formatting. Kubernetes objects will be recognized by checking for `ObjectMeta` structure.

Namespaced objects will be represented by joining their name and namespace with `/` character. Pattern: `<namespace>/<name>`, example for pod: `kube-system/kubedns`
Copy link
Member

Choose a reason for hiding this comment

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

The Go way to do this would be to implement an interface, e.g. a .Log() []struct{k,v string} method. But we don't have methods on our API definitions, generally.

KEP blocker:

Can you explain how this will actually work? Is this something that will be auto-detected? e.g. I pass in an arbitrary pointer and you test if it has metadata via reflection? Is that for any pointer? Any value? How much will that impact runtime of logging?

Do we need a klog.KObj() function which is the "hint" to expand ..., "pod", klog.Kobj(pod), ... into pod/name="foo", pod/namespace="bar" ?

keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
Proposed serialization of Kubernetes objects will not include additional fields beside those proposed available in `text` format.
Discussion for additional fields needed in representation of Kubernetes objects is out of scope of this KEP.

Serialization of arbitrary structures will ignore pointers to avoid hard to predict performance hits caused by deep nested structures or cycles.
Copy link
Member

Choose a reason for hiding this comment

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

This is a challenge. On one hand, it's close to compatible with %v. On the other hand, if we're incrementally converting, we should consider what is "right".

  1. What you propose ("shallow"). Arguably wrong for many types. Would need a hint (e.g. klog.Deep(foo)) to allow full expansion.

  2. Default to "deep". Arguably dangerous. Would maybe need a hint (e.g. klog.Shallow(foo)) to allow alternative, though you could push that onto callers.

  3. Respect stringer interface and call .String() on objects passed in. klog (and glogr) do not surrently respect stringer. stdlib log does: https://play.golang.org/p/p0_pRZlWciH

I lean towards deep, but am open to discuss.

Not a KEP blocker, but DOES need to be resolved.

```


### Logging configuration
Copy link
Member

Choose a reason for hiding this comment

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

I think of this KEP as pretty surgical WRT klog - 2 new functions, 1 new flag. Going beyond that is possible, but a different KEP?

keps/sig-instrumentation/20191115-structured-logging.md Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 13, 2020
@serathius serathius force-pushed the structured-logging branch 2 times, most recently from 7ab9358 to 18edf4c Compare March 13, 2020 11:33
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 13, 2020
@serathius
Copy link
Contributor Author

Pushing update to KEP, addressing feedback:

  • Move json implementation to Alpha (@thockin)
  • Change default verbosity to 0 (@thockin)
  • Reintroduce helper functions for referencing K8s objects as intermediary step (@thockin)

…ogging

* Move JSON implementation to Alpha phase
* Change default verbosity to 0
* Clean up effort phases
* Detail serialization strategy and it's motivation
* Change strategy for serializing time.Time to be consistent with `ts`
field
* Reintroduce helper functions for k8s references
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Really minor points from me.

/lgtm
/approve

* Namespaced objects will be represented by joining their name and namespace with `/` character. Pattern: `<namespace>/<name>`, example for pod: `kube-system/kubedns`
* Non-namespaced objects will be represented by their name. Pattern: `<name>`, example for node: `cluster1-vm-72x33b8p-34jz`

Object UID in logs is much less popular, but still useful in some situation. In situation caller should consider adding a separate field with object UID.
Copy link
Member

Choose a reason for hiding this comment

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

No edit needed, but I do think we should consider (after this lands) adding UID to the normal format. It will need its own evaluation and testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will consider tackling UID after Alpha.


Proposed serialization of Kubernetes objects will not include additional fields beside those proposed available in `text` format.
Discussion for additional fields needed in representation of Kubernetes objects is out of scope of this KEP.
Proposed Serialization of types (we will expand list of special cases if needed):
Copy link
Member

Choose a reason for hiding this comment

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

Document string as %q ?

Copy link
Member

Choose a reason for hiding this comment

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

We also should define whether we intend to respect stringer (method .String() string) or not. Both klog and zap do, so we probably should spec that.

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.
Will check how klog and zap do it and update KEP based on that.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brancz, dims, serathius, thockin

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

@serathius
Copy link
Contributor Author

serathius commented Mar 13, 2020

All reviewers gave their "/lgtm". Merging KEP as "provisional". I will start adding tasks to #1602 and start working on moving KEP to "implementable" state.
/unhold

@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 Mar 13, 2020
@k8s-ci-robot k8s-ci-robot merged commit eba1491 into kubernetes:master Mar 13, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Mar 13, 2020
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/feature Categorizes issue or PR as related to a new feature. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. wg/component-standard Categorizes an issue or PR as relevant to WG Component Standard.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet