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

Add support for CRI-O format #80

Merged
merged 2 commits into from
Nov 10, 2019
Merged

Conversation

jonasrutishauser
Copy link
Contributor

Support container logs from nodes running with docker or with crio (https://cri-o.io/).

Support container logs from nodes running with docker or with crio (https://cri-o.io/).

Signed-off-by: Jonas Rutishauser <jonas.rutishauser@css.ch>
@jvassev
Copy link
Contributor

jvassev commented Nov 10, 2019

Hi @jonasrosland, I have not environment with cri-o to test this. Is your change compatible with docker AND crio? Would Docker container logs still be processed correctly?

@jonasrutishauser
Copy link
Contributor Author

Yes it is compatible with docker and cri-o. The docker container logs should still be parsed the same way.

The multiline parser contains 2 patterns which are tried one after the other:

The next filter is only for cri-o logs and it will concatenate all partials.

<filter kubernetes.**>
@type record_transformer
@id filter_crio_container_logs
enable_ruby true
remove_keys partials
<record>
log ${record["partials"]&.gsub(/.+ (stdout|stderr) P (.+)\n/, '\\2')}${record["log"]}
</record>
</filter>

Then there is a filter which parses the json of docker logs.

<filter kubernetes.**>
@type parser
@id filter_docker_container_logs
key_name log
reserve_data true
emit_invalid_record_to_error false
<parse>
@type json
time_format %Y-%m-%dT%H:%M:%S.%NZ
</parse>
</source>

The only small issue with this solution is in cri-o logs.
If the log line is a json object it will be parsed too.

Signed-off-by: Jonas Rutishauser <jonas.rutishauser@css.ch>
@jonasrutishauser
Copy link
Contributor Author

I have tested with the following input:

2016-10-06T00:17:09.669794202Z stdout F The content of the log entry 1
{"log":"Log line is here\n","stream":"stdout","time":"2019-01-01T11:11:11.111111111Z"}
2016-10-06T00:17:09.669794202Z stderr P First line of log entry 2
2016-10-06T00:17:09.669794202Z stderr P Second line of the log entry 2
2016-10-06T00:17:10.113242941Z stderr F Last line of the log entry 2
2016-10-06T00:18:12.123456743Z stdout F {"foo":"some","bar":"other"}

The output just after the second filter was the following:

2016-10-06 00:17:09.669794202 +0000 kubernetes.var.log.containers.container.log: {"stream":"stdout","log":"The content of the log entry 1"}
2019-01-01 11:11:11.111111111 +0000 kubernetes.var.log.containers.container.log: {"log":"Log line is here\n","stream":"stdout"}
2016-10-06 00:17:10.113242941 +0000 kubernetes.var.log.containers.container.log: {"stream":"stderr","log":"First line of log entry 2Second line of the log entry 2Last line of the log entry 2"}
2016-10-06 00:18:12.123456743 +0000 kubernetes.var.log.containers.container.log: {"stream":"stdout","log":"{\"foo\":\"some\",\"bar\":\"other\"}"}

@jvassev jvassev merged commit 02715cd into vmware:master Nov 10, 2019
@jvassev
Copy link
Contributor

jvassev commented Nov 10, 2019

Thank you for your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants