kata-containers/src/tools/log-parser
Aurélien Bombo 33d08a8417
Merge pull request #9825 from microsoft/mahuber/main
osbuilder: allow rootfs builds w/o git or version file deps
2024-07-02 09:38:13 -07:00
..
vendor build(deps): bump the go_modules group across 5 directories with 8 updates 2024-04-30 09:46:13 +01:00
agent_test.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
agent.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
check_test.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
check.go runtime: Fix gofmt issues 2022-11-17 14:16:12 +01:00
display_csv.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_json.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_test.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_text.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_toml.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_xml.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display_yaml.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
display.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
go.mod build(deps): bump the go_modules group across 5 directories with 8 updates 2024-04-30 09:46:13 +01:00
go.sum build(deps): bump the go_modules group across 5 directories with 8 updates 2024-04-30 09:46:13 +01:00
hexbytes_test.go golang: Stop using io/ioutils 2022-11-17 13:43:25 +01:00
hexbytes.go golang: Stop using io/ioutils 2022-11-17 13:43:25 +01:00
logentry_test.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
logentry.go runtime: Fix gofmt issues 2022-11-17 14:16:12 +01:00
main_test.go golang: Stop using io/ioutils 2022-11-17 13:43:25 +01:00
main.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
Makefile build: allow rootfs builds w/o git or VERSION file deps 2024-06-13 22:46:52 +00:00
parse_test.go golang: Stop using io/ioutils 2022-11-17 13:43:25 +01:00
parse.go log-parser: Simplify check 2022-11-17 14:17:29 +01:00
README.md log-parser: fix some of the documentation 2022-05-10 13:23:25 +03:00
utils_test.go golang: Stop using io/ioutils 2022-11-17 13:43:25 +01:00
utils.go log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00
VERSION log-parser: move the kata-log-parser from the tests repo 2022-05-10 13:23:25 +03:00

kata-log-parser

Introduction

kata-log-parser is a tool that combines logfiles generated by the various system components, sorts them by timestamp, and re-displays the log entries. A time delta is added to show how much time has elapsed between each log entry.

The tool is also able to check the validity of all log records, can re-format the logs, and output them in a different format.

For more information on the kata-log-parser tool, use the help command:

$ kata-log-parser --help

Logfile requirements

The tool reads logfiles in the logfmt structured logging format. For example, a logfile created by the golang Logrus package.

By default the tool requires that the following fields are defined for each log record:

  • Log level field (level): must be one of the Logrus LogLevel values in string format (e.g. debug, info, error).

  • Name field (name): a single word that specifies the name of the application that generates the log record (e.g. kata-runtime).

  • Process ID field (pid): the numeric process identifier for the process that generates the log record.

  • Source field (source): a single word that specifies the name of a unique part of the system (e.g. runtime).

  • Timestamp field (time): in RFC3339 format and including a nanosecond value.

Additional to the fields above, the tool also expects the following field:

  • Message field (msg): a textual message allowing log records to be disambiguated.

Note: These requirements can be ignored by using the --ignore-missing-fields flag

Component logfiles

The primary logfiles the tool reads are:

  • The runtime log.

    This log also includes virtcontainers log entries and agent best effort logs unpacking (unless --no-agent-unpack is specified).

Usage

To merge all logs:

  1. Enable full debug.
  2. Clear the systemd journal (optional):
    $ sudo systemctl stop systemd-journald
    $ sudo rm -f /var/log/journal/*/* /run/log/journal/*/*
    $ sudo systemctl start systemd-journald   
    
  3. Create a Kata container.
  4. Collect the logs (alternatively to journal clearing you may consider constraining collected logs by adding --since=<container creation time>).
    $ sudo journalctl -q -o cat -a -t kata > ./kata.log
    
  5. Ensure the logs are readable:
    $ sudo chown $USER *.log
    
  6. To install the program:
    $ go get -d github.com/kata-containers/kata-containers
    $ pushd $GOPATH/src/github.com/kata-containers/kata-containers/src/tools/log-parser && make install && popd
    
  7. To run the program:
    $ kata-log-parser kata.log
    

Advanced processing using jq

jq is a command-line JSON processor which can be combined with kata-log-parser to filter and fetch specific log entries.

Examples

Get only the raw guest console output
$ kata-log-parser --ignore-missing-fields --output-format json --no-agent-unpack kata.log | jq '.Entries[] | select(.Msg=="reading guest console") | .Data.vmconsole'
Get only the agent's unpacked log entries

This example also demonstrates how to get logs from the journal directly to the parser.

$ journalctl -q -o cat -a -t kata | kata-log-parser --ignore-missing-fields --output-format json - | jq '.Entries[] | select(.Source=="agent")'
Get only certain Sandbox ID logs

These logs sourced from containerd-kata-shim-v2 and being printed along with their Msg content, Time and Container ID.

$ kata-log-parser --ignore-missing-fields --output-format json kata.log  | jq '.Entries[] | select(.Source=="containerd-kata-shim-v2" and .Sandbox=="2fa50251ccc3b9a85350e8fe6836d1875023714153b503b548360946fcec3829") | "\(.Msg) \(.Time) \(.Container)"'