Skip to content

Proposal: New logging driver that logs to tcp, udp and unix domain sockets#18001

Closed
adamtulinius wants to merge 4 commits intomoby:masterfrom
adamtulinius:proposal-logging-to-tcp,udp,unix-socket
Closed

Proposal: New logging driver that logs to tcp, udp and unix domain sockets#18001
adamtulinius wants to merge 4 commits intomoby:masterfrom
adamtulinius:proposal-logging-to-tcp,udp,unix-socket

Conversation

@adamtulinius
Copy link
Copy Markdown

I'm proposing to add a new logging driver, that can log to a tcp, udp or unix domain socket.

The purpose is to make it easy to do custom processing of logs: Instead of writing yet another logging driver for Docker, this feature would make it easy to write a separate daemon to process logs.

A range of formats could be supported, but I suggest starting with a json-based format, where each logentry is delimited with \n, inspired by the Logstash json_lines codec and the Logstash json format.
The resulting log entires will thus end up looking like:

{"@timestamp":"2015-11-16T01:23:00.233368446Z","@version":1,"hostname":"foo.example.com","containerID":"fe6bf90dcde1420588fded941fc4ed0122640723d893af53aa2449deeb4d1a73","message":"Hello from Docker.","source":"stdout"}

The reason for suggesting this particular format, is that I assume more people are familiar with JSON than many of the alternatives (such as MessagePack), and that this format is already used by Logstash.

I would like to give implementing it a shot on my own. I already made a proof-of-concept implementation of the current proposal.

ping @cpuguy83

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Nov 16, 2015

However I think it's good, I'm not sure that we should use format with @ for this. But it's just my opinion. I think we can start work on code. WDYT @cpuguy83 ?

@cpuguy83
Copy link
Copy Markdown
Member

Also thinking msgpack or protobuf.

@dqminh
Copy link
Copy Markdown
Contributor

dqminh commented Nov 17, 2015

I'm not too fond of yet another (JSON) log format. We already have many log drivers that outputs processable logs, why do we want to have another one ?

@cpuguy83
Copy link
Copy Markdown
Member

@dqminh it's basically to make this "pluggable" so we don't have to keep adding more and more drivers to the codebase.

@dqminh
Copy link
Copy Markdown
Contributor

dqminh commented Nov 17, 2015

@cpuguy83 i would argue that any of the current structured-based log driver ( gelf / fluentd / even journald ) is already pluggable, although each having pros/cons of their own.

If we decide to have another pluggable one, i would like to see its benefits outweighs the rests.

@cpuguy83
Copy link
Copy Markdown
Member

@dqminh I think there is value in being able to blast out the logs in the "native" structure we have, (logging) service providers can implement their own adapters without being bound by shortcomings in the currently supported formats.

Most logging services implements one (or likely multiple) formats (like syslog and journald) so that they can consume logs from just about any system that exists, but these are lowest common denominator, which is really icky.

@adamtulinius
Copy link
Copy Markdown
Author

However I think it's good, I'm not sure that we should use format with @ for this. But it's just my opinion. I think we can start work on code. WDYT @cpuguy83 ?

Actually it would probably be better to not emulate how logstash does it, especially if we're also going to support other output formats, such as msgpack/protobufs. That way we could try to make the structure of the data similar.

Also thinking msgpack or protobuf.

Would be pretty trivial to support different formats. Personally I think it's worth supporting JSON because the barrier to entry is really low.

@dqminh I think there is value in being able to blast out the logs in the "native" structure we have, (logging) service providers can implement their own adapters without being bound by shortcomings in the currently supported formats.

Exactly. I feel something like this should just dump as much data as possible, with the least amount of processing, and basically not be very opinionated about how the data should be used.

Thanks for the input so far.

@thaJeztah
Copy link
Copy Markdown
Member

Looks like we're okay implementing this, @cpuguy83 @LK4D4?

@adamtulinius are you already working on the code for this?

@LK4D4 LK4D4 mentioned this pull request Dec 11, 2015
@adamtulinius
Copy link
Copy Markdown
Author

@adamtulinius are you already working on the code for this?

Yes, I have quite a lot of it implemented, I just chose not to push it before reaching some sort of consensus about what to do.

I should be able to get it rebased on current master and add it to the PR during this weekend.

@thaJeztah
Copy link
Copy Markdown
Member

Thanks @adamtulinius, we can continue discussing the details when the code is there

@thaJeztah
Copy link
Copy Markdown
Member

Also note this proposal btw; #18604

@thaJeztah
Copy link
Copy Markdown
Member

ping @adamtulinius, have you had time to look at this?

@adamtulinius
Copy link
Copy Markdown
Author

Sorry about the delay. Had managed to break my dev environment.
Anyways, i've pushed an implementation that is basically working, but I'm going to clean up the code the following days, and make golint happy.
Also, I'm in the process of implementing tests for delivering messages to tcp, udp and unix domain sockets.

Signed-off-by: Adam Finn Tulinius <[email protected]>
@adamtulinius
Copy link
Copy Markdown
Author

I thought about something, though:
When log messages can't be delievered, what should the driver do?

  1. drop messages and print an error
  2. attempt delivery later on, either storing messages for X minutes, or storing up to Y messages for later delivery

Thoughts?

Signed-off-by: Adam Finn Tulinius <[email protected]>
@thaJeztah
Copy link
Copy Markdown
Member

Thanks @adamtulinius !

@thaJeztah
Copy link
Copy Markdown
Member

ping @LK4D4 @cpuguy83 can you have a look at this, perhaps some thoughts on #18001 (comment) ?

@thaJeztah
Copy link
Copy Markdown
Member

ping @cpuguy83 @LK4D4 can you have a look please?

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Jan 4, 2016

Looks good.

I would also want to make sure we can customize the fields that get sent much like we do with a couple of the other drivers. If not right away, at least in a way that we don't have to make a breaking change to the outgoing message format.

I still think we need to look at either using msgpack or protobuf to encode the messages... and of course json can be benched as well.
We need to make sure we can get these messages out of docker as quickly and w/ as low impact to the host as possible.

@tiborvass
Copy link
Copy Markdown
Contributor

overall +1 on the design, but am wondering what are the drawbacks? how would performance be impacted? /cc @adamtulinius

@icecrime
Copy link
Copy Markdown
Contributor

Ping @adamtulinius @LK4D4: shall we move to code review?

@cpuguy83
Copy link
Copy Markdown
Member

I've created some (naive) benchmarks for encoding log messages for reference:

BenchmarkJSON-8      1000000          2254 ns/op         568 B/op          8 allocs/op
BenchmarkProtobuf-8  2000000           602 ns/op         336 B/op          5 allocs/op
BenchmarkMsgpack-8   1000000          2037 ns/op         384 B/op          6 allocs/op
BenchmarkFlatbuf-8   5000000           303 ns/op           0 B/op          0 allocs/op

https://gist.github.com/cpuguy83/ac5d8f87bce9c37c0009

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Jan 28, 2016

@cpuguy83 hell, flatbuffers is pretty cool :)

@tiborvass
Copy link
Copy Markdown
Contributor

<3 flatbuffers

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Jan 28, 2016

Let's move to code-review, it seems pretty easy to extend later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't see why it should work only on linux.

@cpuguy83
Copy link
Copy Markdown
Member

And was able to get protbuf a bit better than flatbuff with some tweaks to use an encoder instead of calling Marshal directly:

BenchmarkProtobuf-8  5000000           244 ns/op           0 B/op          0 allocs/op
BenchmarkFlatbuf-8   5000000           312 ns/op           0 B/op          0 allocs/op

@aaronlehmann
Copy link
Copy Markdown

@thaJeztah
Copy link
Copy Markdown
Member

ping @adamtulinius looks like this needs a rebase; also my can you address the comments so far?

@thaJeztah
Copy link
Copy Markdown
Member

ping @adamtulinius can you rebase and address the comments?

@thaJeztah
Copy link
Copy Markdown
Member

ping @cpuguy83 @LK4D4 should we carry this?

@thaJeztah
Copy link
Copy Markdown
Member

Maintainers meeting today;

Although we like this feature, we should look at this together with the general "logging plugin" proposal #18604. There's really an overlap in the two, and we should decide what kind of mechanism we want to use to have external plugins. We should be careful developing our own protocols, unless there are no other options.

It's possible that we arrive at the solution in this PR, but moving this forward without having a decision on the general logging plugin system would be bad, as we may end up with two things doing exactly the same.

In addition, we have the GELF driver, which is a standard solution and already can be used for many purposes that this PR tries to resolve https://docs.docker.com/engine/admin/logging/overview/#gelf-options

For now, I'm going to close this PR until we have agreement on the plugin design. Thanks so much for starting the work on this.

@thaJeztah thaJeztah closed this Mar 3, 2016
@subfuzion
Copy link
Copy Markdown

I've proposed a solution that lets docker stream the logs to a container you specify with the image option for a "custom" logging driver here. The container can implement whatever logic it wants to forward the logs to another destination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants