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
Conversation
57c07c9
to
e688dcd
Compare
@kubernetes/sig-instrumentation-feature-requests |
I guess @kubernetes/sig-architecture-feature-requests should be involved. |
PTAL @bogdandrutu |
/wg component-standard |
There was a problem hiding this 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
/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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Addressed feedback:
Added a section that explicitly mentions how logger implementation can be overridden. |
There was a problem hiding this 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.
There was a problem hiding this 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:
- Add structured functions to klog and document the output format
- Add a JSON output format to klog
- 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` |
There was a problem hiding this comment.
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"
?
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. |
There was a problem hiding this comment.
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".
-
What you propose ("shallow"). Arguably wrong for many types. Would need a hint (e.g.
klog.Deep(foo)
) to allow full expansion. -
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. -
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 |
There was a problem hiding this comment.
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?
7ab9358
to
18edf4c
Compare
18edf4c
to
afb1e23
Compare
…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
afb1e23
to
55d56e4
Compare
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document string as %q ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
[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 |
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. |
Review progress:
Please let me know if you think you should be added to this list.
Proposal was presented on:
PR will be merged when all reviewers give their lgtm.