mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add labels/env log option for fluentd
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 commit is contained in:
parent
5794a0190d
commit
4cc8490283
1 changed files with 9 additions and 3 deletions
|
@ -20,6 +20,7 @@ type fluentd struct {
|
||||||
containerID string
|
containerID string
|
||||||
containerName string
|
containerName string
|
||||||
writer *fluent.Fluent
|
writer *fluent.Fluent
|
||||||
|
extra map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -51,9 +52,8 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
extra := ctx.ExtraAttributes(nil)
|
||||||
logrus.Debugf("logging driver fluentd configured for container:%s, host:%s, port:%d, tag:%s.", ctx.ContainerID, host, port, tag)
|
logrus.Debugf("logging driver fluentd configured for container:%s, host:%s, port:%d, tag:%s, extra:%v.", ctx.ContainerID, host, port, tag, extra)
|
||||||
|
|
||||||
// logger tries to recoonect 2**32 - 1 times
|
// logger tries to recoonect 2**32 - 1 times
|
||||||
// failed (and panic) after 204 years [ 1.5 ** (2**32 - 1) - 1 seconds]
|
// failed (and panic) after 204 years [ 1.5 ** (2**32 - 1) - 1 seconds]
|
||||||
log, err := fluent.New(fluent.Config{FluentPort: port, FluentHost: host, RetryWait: 1000, MaxRetry: math.MaxInt32})
|
log, err := fluent.New(fluent.Config{FluentPort: port, FluentHost: host, RetryWait: 1000, MaxRetry: math.MaxInt32})
|
||||||
|
@ -65,6 +65,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
||||||
containerID: ctx.ContainerID,
|
containerID: ctx.ContainerID,
|
||||||
containerName: ctx.ContainerName,
|
containerName: ctx.ContainerName,
|
||||||
writer: log,
|
writer: log,
|
||||||
|
extra: extra,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +76,9 @@ func (f *fluentd) Log(msg *logger.Message) error {
|
||||||
"source": msg.Source,
|
"source": msg.Source,
|
||||||
"log": string(msg.Line),
|
"log": string(msg.Line),
|
||||||
}
|
}
|
||||||
|
for k, v := range f.extra {
|
||||||
|
data[k] = v
|
||||||
|
}
|
||||||
// fluent-logger-golang buffers logs from failures and disconnections,
|
// fluent-logger-golang buffers logs from failures and disconnections,
|
||||||
// and these are transferred again automatically.
|
// and these are transferred again automatically.
|
||||||
return f.writer.PostWithTime(f.tag, msg.Timestamp, data)
|
return f.writer.PostWithTime(f.tag, msg.Timestamp, data)
|
||||||
|
@ -95,6 +99,8 @@ func ValidateLogOpt(cfg map[string]string) error {
|
||||||
case "fluentd-address":
|
case "fluentd-address":
|
||||||
case "fluentd-tag":
|
case "fluentd-tag":
|
||||||
case "tag":
|
case "tag":
|
||||||
|
case "labels":
|
||||||
|
case "env":
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown log opt '%s' for fluentd log driver", key)
|
return fmt.Errorf("unknown log opt '%s' for fluentd log driver", key)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue