-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Document Structured Logging Enhancement #21202
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
content/en/docs/concepts/cluster-administration/system-logs.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| --- | ||
| reviewers: | ||
| - dims | ||
| - 44past4 | ||
| title: System Logs | ||
| content_type: concept | ||
| weight: 60 | ||
| --- | ||
|
|
||
| <!-- overview --> | ||
|
|
||
| System component logs record events happening in cluster, which can be very useful for debugging. | ||
| You can configure log verbosity to see more or less detail. | ||
| Logs can be as coarse-grained as showing errors within a component, or as fine-grained as showing step-by-step traces of events (like HTTP access logs, pod state changes, controller actions, or scheduler decisions). | ||
|
|
||
| <!-- body --> | ||
|
|
||
| ## Klog | ||
|
|
||
| klog is the Kubernetes logging library. [klog](https://github.com/kubernetes/klog) | ||
| generates log messages for the Kubernetes system components. | ||
|
|
||
| For more information about klog configuration, see the [Command line tool reference](/docs/reference/command-line-tools-reference/). | ||
|
|
||
| An example of the klog native format: | ||
| ``` | ||
| I1025 00:15:15.525108 1 httplog.go:79] GET /api/v1/namespaces/kube-system/pods/metrics-server-v0.3.1-57c75779f-9p8wg: (1.512ms) 200 [pod_nanny/v0.0.0 (linux/amd64) kubernetes/$Format 10.56.1.19:51756] | ||
| ``` | ||
|
|
||
| ### Structured Logging | ||
|
|
||
| {{< feature-state for_k8s_version="v1.19" state="alpha" >}} | ||
|
|
||
| {{<warning>}} | ||
| Migration to structured log messages is an ongoing process. Not all log messages are structured in this version. When parsing log files, you must also handle unstructured log messages. | ||
|
|
||
| Log formatting and value serialization are subject to change. | ||
| {{< /warning>}} | ||
|
|
||
| Structured logging is a effort to introduce a uniform structure in log messages allowing for easy extraction of information, making logs easier and cheaper to store and process. | ||
| New message format is backward compatible and enabled by default. | ||
|
|
||
| Format of structured logs: | ||
| ``` | ||
| <klog header> "<message>" <key1>="<value1>" <key2>="<value2>" ... | ||
| ``` | ||
|
|
||
| Example: | ||
| ``` | ||
| I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kube-system/kubedns" status="ready" | ||
| ``` | ||
|
|
||
|
|
||
| ### JSON log format | ||
|
|
||
| {{< feature-state for_k8s_version="v1.19" state="alpha" >}} | ||
|
|
||
| {{<warning >}} | ||
| JSON output does not support many standard klog flags. For list of unsupported klog flags, see the [Command line tool reference](/docs/reference/command-line-tools-reference/). | ||
|
|
||
| Not all logs are guaranteed to be written in JSON format (for example, during process start). If you intend to parse logs, make sure you can handle log lines that are not JSON as well. | ||
|
|
||
| Field names and JSON serialization are subject to change. | ||
| {{< /warning >}} | ||
|
|
||
| The `--logging-format=json` flag changes the format of logs from klog native format to JSON format. | ||
| Example of JSON log format (pretty printed): | ||
| ```json | ||
| { | ||
| "ts": 1580306777.04728, | ||
| "v": 4, | ||
| "msg": "Pod status updated", | ||
| "pod":{ | ||
| "name": "nginx-1", | ||
| "namespace": "default" | ||
| }, | ||
| "status": "ready" | ||
| } | ||
| ``` | ||
|
|
||
| Keys with special meaning: | ||
| * `ts` - timestamp as Unix time (required, float) | ||
| * `v` - verbosity (required, int, default 0) | ||
| * `err` - error string (optional, string) | ||
| * `msg` - message (required, string) | ||
|
|
||
|
|
||
| List of components currently supporting JSON format: | ||
| * {{< glossary_tooltip term_id="kube-controller-manager" text="kube-controller-manager" >}} | ||
| * {{< glossary_tooltip term_id="kube-apiserver" text="kube-apiserver" >}} | ||
| * {{< glossary_tooltip term_id="kube-scheduler" text="kube-scheduler" >}} | ||
| * {{< glossary_tooltip term_id="kubelet" text="kubelet" >}} | ||
|
|
||
| ### Log verbosity level | ||
|
|
||
| The `-v` flag controls log verbosity. Increasing the value increases the number of logged events. Decreasing the value decreases the number of logged events. | ||
| Increasing verbosity settings logs increasingly less severe events. A verbosity setting of 0 logs only critical events. | ||
|
|
||
| ### Log location | ||
|
|
||
| There are two types of system components: those that run in a container and those | ||
| that do not run in a container. For example: | ||
|
|
||
| * The Kubernetes scheduler and kube-proxy run in a container. | ||
| * The kubelet and container runtime, for example Docker, do not run in containers. | ||
|
|
||
| On machines with systemd, the kubelet and container runtime write to journald. | ||
| Otherwise, they write to `.log` files in the `/var/log` directory. | ||
| System components inside containers always write to `.log` files in the `/var/log` directory, | ||
| bypassing the default logging mechanism. | ||
| Similar to the container logs, you should rotate system component logs in the `/var/log` directory. | ||
| In Kubernetes clusters created by the `kube-up.sh` script, log rotation is configured by the `logrotate` tool. | ||
| The `logrotate` tool rotates logs daily, or once the log size is greater than 100MB. | ||
|
|
||
| ## {{% heading "whatsnext" %}} | ||
|
|
||
| * Read about the [Kubernetes Logging Architecture](/docs/concepts/cluster-administration/logging/) | ||
| * Read about [Structured Logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging) | ||
| * Read about the [Conventions for logging severity](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since we are already here, can you help address issue #21404 by adding a few lines?
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.
Like explained in comment above, there is no real limit. Currently in k/k/ codebase is between 0-12.
Outside of guide https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md (which looks outdated) there is no other documented meaning between verbosity levels. Guide only accounts for 0-5, but there are still around 200 log calls with verbosity between 6-12.
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 for the detailed info. I'm copying your comment to that issue.