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 extra fields based on label and env for gelf/fluentd/json-file/journald log drivers #15975

Closed
wants to merge 5 commits into from

Conversation

dqminh
Copy link
Contributor

@dqminh dqminh commented Sep 1, 2015

Fix #15816

This adds container env and labels to log context, and use the data in gelf and fluentd log driver to expose more logging data.

Usage:

  • gelf: --log-opt gelf-labels=label1,label2 --log-opt gelf-env=env1,env2
  • fluentd: --log-opt fluentd-labels=label1,label2 --log-opt fluentd-env=env1,env2

The above instructions add label1, label2, env1, env2 key-value pair to log.

cc @LK4D4 @tagomoris @mariussturm

@cpuguy83
Copy link
Member

cpuguy83 commented Sep 1, 2015

I think any changes here would need to depend on #15384

@mariussturm
Copy link
Contributor

@dqminh extra fields in a GELF message have to start with a _. In the current PR you can pick any name, right?

@dqminh
Copy link
Contributor Author

dqminh commented Sep 1, 2015

@mariussturm ah yes, i forgot about that specification ( seems like the log servers still happily accept it though ). I think user can pick names, but we can force that the fields we sent is prefixed with _. wdyt ?

@mariussturm
Copy link
Contributor

Yes, I would force the prefix. Thanks!

@tagomoris
Copy link
Contributor

LGTM 👍

@mariussturm
Copy link
Contributor

Another thing, since the fluentd-labels/env and the gelf-labels/env behave in the same way, there is no need for different option names. I think it's more important to point out that the label/env options hook into the Docker metadata system. Maybe a generic name like --log-opt append-labels would be clearer for the user?

@dqminh
Copy link
Contributor Author

dqminh commented Sep 1, 2015

@mariussturm however not all log drivers can support this though. I think journald can with the same changes, but json file and syslog cannot. Not sure if we can apply a global log opt here.

@mariussturm
Copy link
Contributor

It's the same with gelf-tag and fluentd-tag option, both will be deprecated in favour of tag: #15384

@dqminh
Copy link
Contributor Author

dqminh commented Sep 1, 2015

@mariussturm tag can be applied universally though, this is not applicable to syslog / json-file afaik.

@dqminh
Copy link
Contributor Author

dqminh commented Sep 3, 2015

@mariussturm added support for _ prefix in additional field names.

@dqminh
Copy link
Contributor Author

dqminh commented Sep 10, 2015

Obligatory ping @mariussturm @cpuguy83 😄

Not sure which order we want to merge this vs #15384 . IMO this is much more simpler and useful than #15384 for ingesters want to consume structured log with injected metadata ( i.e. not applicable to syslog )

@mariussturm
Copy link
Contributor

The GELF part LGTM. But as I said parameter name feels inconsistent to me. Especially when you combine it with the tag option: --log-opt tag vs. --log-opt gelf-labels
As a user: why one with protocol prefix and the other without?
But this is something @calavera or @cpuguy83 has to decide.

@calavera
Copy link
Contributor

I'd say that if an option is used by more than one driver, it should not have a prefix. I agree with @mariussturm that it feels inconsistent. I think this should be --log-opt labels= and --log-opt env=.

@dqminh
Copy link
Contributor Author

dqminh commented Sep 10, 2015

Hmm i dont mind changing it. I jus think that it can be confusing when not all drivers can support this, for example syslog and json-file, also journald but that can be fixed.
Do you think that is only a doc issue now ?

@calavera
Copy link
Contributor

@dqminh maybe it would be even easier to add these options to all drivers rather than just two of them 😸

@dqminh
Copy link
Contributor Author

dqminh commented Sep 10, 2015

@calavera we can probably extend json-file, but syslog is problematic though unless we want RFC5424. Feels like that a big change.

@calavera
Copy link
Contributor

@dqminh let's go with json-file only then. We can always iterate on syslog if we need to.

@calavera
Copy link
Contributor

I added this PR to the 1.9 milestone. I think it would be a nice feature to have in systems like Amazon ECS #15153.

@dqminh feel free to reach me if you need help with this.

@calavera
Copy link
Contributor

@dqminh is there any progress on this?

@dqminh dqminh changed the title Add extra fields based on label and env for gelf/fluentd log drivers Add extra fields based on label and env for gelf/fluentd/json-file/journald log drivers Sep 24, 2015
@dqminh dqminh force-pushed the log-driver-extra-fields branch 2 times, most recently from ba30b64 to 40470d1 Compare September 25, 2015 00:03
@dqminh
Copy link
Contributor Author

dqminh commented Sep 25, 2015

@calavera updated to labels/env log options and add it to journald and json-file too.

var extra []byte
if attrs := ctx.ExtraAttributes(nil); len(attrs) > 0 {
var err error
extra, err = json.Marshal(extra)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be extra, err = json.Marshal(attrs) ?

@calavera
Copy link
Contributor

Is there a way we can have tests and documentation for this? I just found an issue that would have been quickly detected with some unit tests.

@dqminh
Copy link
Contributor Author

dqminh commented Sep 30, 2015

@calavera fixed and added some tests last week ( sorry forgot to ping :( )

This doesnt have any documentation yet, but I dont have much cycle on this for this week, so feel free to take over if you want. Otherwise let me know and i will try to find some time for it.

@calavera
Copy link
Contributor

code LGTM, but I'm not going to be able to carry it in, because I'm going to be offline for a couple of weeks.

envMapping[kv[0]] = kv[1]
}
}
for _, l := range strings.Split(env, ",") {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe could factorize this in a function as it's the same is few lines upwards.

@vdemeester
Copy link
Member

Except from the small comments, code LGTM too.
@calavera @dqminh I could carry it, but wondering if the commits should be squashed or not ?

@cpuguy83
Copy link
Member

cpuguy83 commented Oct 1, 2015

Yes, @dqminh Do you have time to squash commits before someone carries?

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
this allows gelf logger to collect extra metadata from containers with
`--log-opt labels=label1,label2 --log-opt env=env1,env2`

Additional log field will be prefixed with `_` as per gelf protocol
https://www.graylog.org/resources/gelf/

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
this allows fluentd logger to collect extra metadata from containers with
`--log-opt labels=label1,label2 --log-opt env=env1,env2`

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
this allows journald logger to collect extra metadata from containers with
`--log-opt labels=label1,label2 --log-opt env=env1,env2`

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
this allows jsonfile logger to collect extra metadata from containers with
`--log-opt labels=label1,label2 --log-opt env=env1,env2`.

Extra attributes are saved into `attrs` attributes for each log data.

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
@dqminh
Copy link
Contributor Author

dqminh commented Oct 4, 2015

Squashed and rebased.

@icecrime
Copy link
Contributor

Moving to docs review, thanks @dqminh!

@thaJeztah
Copy link
Member

@dqminh I don't see any docs yet; can you add a description of the new options to
https://github.com/docker/docker/blob/master/docs/reference/logging/overview.md, also, IIUC, env and label can now be used in --log-opt tag, so they need to be added to the table, and here; https://github.com/docker/docker/blob/master/docs/reference/logging/log_tags.md

@jessfraz
Copy link
Contributor

@dqminh if you get this done by today we can try and get it in 1.9 before code freeze

@vdemeester
Copy link
Member

@jfrazelle @dqminh I'm gonna carry it for the docs ; to make sure it makes it 😉.

@jessfraz
Copy link
Contributor

thanks @vdemeester

@jessfraz
Copy link
Contributor

closing because #16961 is updated thanks @dqminh

@jessfraz jessfraz closed this Oct 12, 2015
thaJeztah added a commit that referenced this pull request Oct 13, 2015
Carry #15975 - Add extra fields based on label and env for gelf/fluentd/json-file/journald log drivers
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.

None yet

10 participants