Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

cmd: Add log parser #98

Merged
merged 2 commits into from
Mar 3, 2018
Merged

Conversation

jodh-intel
Copy link
Contributor

Add a log parsing tool (kata-log-parser) that reads multiple logfmt
[*] logfiles and writes their output in time order showing time
differences between log entries.

The tool can also check logs for validity and convert the logs to
various alternative formats.

For full details:

$ kata-log-parser --help

Fixes #93.

[*] - https://brandur.org/logfmt

Signed-off-by: James O. D. Hunt james.o.hunt@intel.com

@jodh-intel
Copy link
Contributor Author

@grahamwhaley
Copy link
Contributor

I'm guessing the CI fail is due to the pending deps:

ERROR: kata-log-parser: failed to parse time for value 2018-02-28T13:06:08Z (entry: &{Count:0 TimeDelta:0 

So, I'll mark this as DNM to stop the CI trying until we have those deps merged then.

@jodh-intel
Copy link
Contributor Author

Yes - we really need those 3 other PRs merged...

Copy link
Contributor

@grahamwhaley grahamwhaley left a comment

Choose a reason for hiding this comment

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

hands up - I didn't scrutinise the code - but, for the general overview and intention,
lgtm
few minor queries...

.ci/run.sh Outdated
eval "$cmd"
done

dir="."
Copy link
Contributor

Choose a reason for hiding this comment

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

just a note: the dir feels strangely redundant (just *.log would match in . anyhow, no?). And, I'd probably have put a $(pwd) maybe, but that is probably just personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
Copy link
Contributor

Choose a reason for hiding this comment

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

we could nuke the example comments if you fancy.

default: install

check:
go test .
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we are relying on the global CI scripts to do any static analysis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - when any PR is raised on this repo, the .ci/static-checks.sh will be run on all packages. In fact, that script is currently checking a leeeetle too much - see #100 :)

them, adding a time delta showing how much time has elapsed between each log
entry.

It is checks the logs for validity and can re-format the logs and output them in a different format.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/It is/It/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


## Component logfiles

The primary logfiles the tool reads are:
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume the tool itself is component neutral? It will work with any set of appropriately formatted log files I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a new section to the doc explaining the tools expectations.

@@ -0,0 +1,94 @@
// Copyright (c) 2017-2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
Copy link
Contributor

Choose a reason for hiding this comment

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

SPDX headers here?

)

// HexByteReader is an I/O Reader type.
type HexByteReader struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, this is not something we could use package "encoding/hex" for is it?
(which I've used, but had some fun with before, as it only handles a single case (lower iirc), and I needed it to handle upper :-) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that package handles escaped hex values?

@jodh-intel
Copy link
Contributor Author

Hi @klynnrif - please could you take a look at the new cmd/log-parser/README.md on this PR?

@jodh-intel jodh-intel force-pushed the add-log-parser branch 5 times, most recently from 209edce to 45db9f0 Compare February 28, 2018 17:43
@jodh-intel
Copy link
Contributor Author

Removing label now dependent PRs have landed...

@jodh-intel jodh-intel force-pushed the add-log-parser branch 2 times, most recently from 32589ab to 635a7ab Compare February 28, 2018 18:06
Copy link

@klynnrif klynnrif left a comment

Choose a reason for hiding this comment

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

Edited cmd/log-parser/README.md for grammar, format, and text flow. I might have changed the meaning with some edits - apologies in advance :). Thanks!

* [Usage](#usage)

`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,

Choose a reason for hiding this comment

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

Lines 8-9 suggested rewrite: system components, sorts them by timestamp, and re-displays the log entries. A time delta is added to shows how much time has elapsed between each log entry.

system components, sorts them by timestamp and re-displays the log entries,
adding a time delta showing how much time has elapsed between each log entry.

The tool also checks the validity of all log records and can re-format the

Choose a reason for hiding this comment

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

Lines 11-12 suggested rewrite: The tool also checks the validity of all log records, can re-format the logs, and output them in a different format.

The tool also checks the validity of all log records and can re-format the
logs and output them in a different format.

For full details,

Choose a reason for hiding this comment

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

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

## Logfile requirements

The tool reads logfiles in the [logfmt](https://brandur.org/logfmt) structured
logging format, for example as created by the golang

Choose a reason for hiding this comment

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

Lines 23-24 suggested rewrite: logging format. For example, a logfile created by the golang logrus package.

logging format, for example as created by the golang
[logrus](https://godoc.org/github.com/sirupsen/logrus) package.

The tool requires the following fields to be defined for each log record:

Choose a reason for hiding this comment

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

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

format and including a nanosecond value.

- Source field (`source`): a single word that specifies the name of a unique
part of the system (for example, `proxy`, `runtime`, `shim`).

Choose a reason for hiding this comment

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

part of the system (e.g. proxy, runtime, shim).

part of the system (for example, `proxy`, `runtime`, `shim`).

- Name field (`name`): a single word that specifies the name of the
application that generated the log record (for example, `kata-runtime`).

Choose a reason for hiding this comment

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

application that generates the log record (e.g. kata-runtime).


This log also includes embedded log entries from the
[agent](https://github.com/katacontainers/agent). `kata-log-parser`
automatically unpacks and displays these, discarding the proxies encapsulating

Choose a reason for hiding this comment

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

automatically unpacks and displays the entries. During this process, the encapsulating proxy log messages are discarded.


## Usage

To merge together all logs:

Choose a reason for hiding this comment

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

To merge all logs:

```
1. Create a container.
1. Collect the logs.
1. Save the proxy log (which also includes agent log details):

Choose a reason for hiding this comment

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

Save the proxy log, which includes agent log details:

@jodh-intel jodh-intel force-pushed the add-log-parser branch 5 times, most recently from bab5322 to 3d3d916 Compare March 1, 2018 09:35
@jodh-intel
Copy link
Contributor Author

Hi @klynnrif - thanks for reviewing. Doc updated.

@jodh-intel jodh-intel force-pushed the add-log-parser branch 4 times, most recently from 94a06ed to 5e07fb4 Compare March 1, 2018 12:15
@jodh-intel
Copy link
Contributor Author

Hi @chavafg, @devimc - could you take a look please?

@jodh-intel
Copy link
Contributor Author

The CI is correctly detecting that the runtime logs are invalid:

ERROR: kata-log-parser: missing pid: {Count:0 TimeDelta:0 Filename:/home/jenkins/jenkins_slave/workspace/kata-containers-tests-ubuntu-16-04-PR/go/src/github.com/kata-containers/tests/kata-runtime-cc.log Line:1 Time:2018-03-01 13:38:29.691863391 +0000 UTC Pid:0 Level:debug Msg:loaded configuration Source:runtime Name: Data:map[format:TOML]}

This is because the version of cc-runtime in kata is too old. Therefore, blocked on:

@jodh-intel
Copy link
Contributor Author

Hi @klynnrif - thanks for re-reviewing. Could you add a "lgtm" comment as, alas, pullapprove doesn't honour the "thumbs-ups" 😄

@klynnrif
Copy link

klynnrif commented Mar 1, 2018

lgtm

Approved with PullApprove

@klynnrif
Copy link

klynnrif commented Mar 1, 2018

@jodh-intel that is unfortunate :) "thumbs-ups" should always be honored. haha! Thanks!

@jodh-intel
Copy link
Contributor Author

kata-containers/runtime#43 is now merged so re-started CI...

Hi again @klynnrif - actually, I think you've got to use the approve button as the top right is still showing a red cross against your review.

Copy link

@klynnrif klynnrif left a comment

Choose a reason for hiding this comment

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

lgtm

@klynnrif
Copy link

klynnrif commented Mar 1, 2018

@jodh-intel Okay, I think I'm set now :) let me know if not. Thanks!

@jodh-intel jodh-intel force-pushed the add-log-parser branch 3 times, most recently from f84a8a1 to 26438aa Compare March 2, 2018 09:19
Add a log parsing tool (`kata-log-parser`) that reads multiple logfmt
[*] logfiles and writes their output in time order showing time
differences between log entries.

The tool can also check logs for validity and convert the logs to
various alternative formats.

For full details:

```
$ kata-log-parser --help
```

Fixes kata-containers#93.

[*] - https://brandur.org/logfmt

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
Call the log parser at the end of the test run. It will check all
component log files and display a detailed error message if any issues
are found.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
@jodh-intel
Copy link
Contributor Author

CI is now failing due to an agent issue: kata-containers/agent#159.

@jodh-intel
Copy link
Contributor Author

Blocked on kata-containers/agent#159.

@sboeuf
Copy link

sboeuf commented Mar 2, 2018

LGTM

@sboeuf
Copy link

sboeuf commented Mar 2, 2018

@jodh-intel I don't think you should bother with the CI failing right now. Kata is moving a lot and everything is not stable yet. This should not gate your PR from being merged.

@jodh-intel
Copy link
Contributor Author

@jodh-intel
Copy link
Contributor Author

@sboeuf - wfm :)

WDYT @grahamwhaley? We have 3 acks on this PR already... ;)

@grahamwhaley
Copy link
Contributor

Welllll - this works two ways - if we make the CI stable now, then we may abate major breakage as we 'move fast', which is a good thing. On the other hand, if we know we are fixing CI things that are going to be thrown in the bin (which I'm not convinced of...), then fine.

I'd prefer we got CI running to stop us shooting our own feet off in the next couple of weeks.

@jodh-intel
Copy link
Contributor Author

I agree that we want a stable CI.

It's worth stating that this PR does not add any new tests - it adds a new (unused) tool. We also can see from the CI logs that the static checks pass for this PR.

@sboeuf
Copy link

sboeuf commented Mar 2, 2018

As explained by @jodh-intel, this PR cannot make the build worst as it is not introducing new tests. I think we should go ahead and merge it.

@chavafg
Copy link
Contributor

chavafg commented Mar 3, 2018

lgtm

Approved with PullApprove

@chavafg
Copy link
Contributor

chavafg commented Mar 3, 2018

Agree to merge this one..

@chavafg chavafg merged commit 5981afd into kata-containers:master Mar 3, 2018
@chavafg chavafg removed the review label Mar 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants