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
Conversation
I think any changes here would need to depend on #15384 |
8a0b7da
to
0aecddc
Compare
@dqminh extra fields in a GELF message have to start with a |
@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 |
Yes, I would force the prefix. Thanks! |
LGTM 👍 |
Another thing, since the |
@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. |
It's the same with |
@mariussturm tag can be applied universally though, this is not applicable to syslog / json-file afaik. |
23d9a10
to
470da99
Compare
@mariussturm added support for |
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 ) |
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 |
Hmm i dont mind changing it. I jus think that it can be confusing when not all drivers can support this, for example |
@dqminh maybe it would be even easier to add these options to all drivers rather than just two of them 😸 |
@calavera we can probably extend json-file, but syslog is problematic though unless we want RFC5424. Feels like that a big change. |
@dqminh let's go with json-file only then. We can always iterate on syslog if we need to. |
@dqminh is there any progress on this? |
ba30b64
to
40470d1
Compare
@calavera updated to |
var extra []byte | ||
if attrs := ctx.ExtraAttributes(nil); len(attrs) > 0 { | ||
var err error | ||
extra, err = json.Marshal(extra) |
There was a problem hiding this comment.
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)
?
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. |
40470d1
to
4b8ab62
Compare
@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. |
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, ",") { |
There was a problem hiding this comment.
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.
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>
4b8ab62
to
056dfb0
Compare
Squashed and rebased. |
Moving to docs review, thanks @dqminh! |
@dqminh I don't see any docs yet; can you add a description of the new options to |
@dqminh if you get this done by today we can try and get it in 1.9 before code freeze |
@jfrazelle @dqminh I'm gonna carry it for the docs ; to make sure it makes it 😉. |
thanks @vdemeester |
Carry #15975 - Add extra fields based on label and env for gelf/fluentd/json-file/journald log drivers
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:
--log-opt gelf-labels=label1,label2 --log-opt gelf-env=env1,env2
--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