mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: introducing docker-syslog driver as default logger (#1189)
* fn: introducing docker-syslog driver as default logger With this change, fn-agent prefers RFC2454 docker-syslog driver for logging stdout/stderr from containers. The advantage of this is to offload it to docker itself instead of streaming stderr along with stdout, which gets multiplexed through single connection via docker-API. The change will need support from FDKs in order to log correct call-id and supress '\n' that splits syslog lines.
This commit is contained in:
@@ -25,6 +25,34 @@ type cookie struct {
|
||||
drv *DockerDriver
|
||||
}
|
||||
|
||||
func (c *cookie) configureLogger(log logrus.FieldLogger) {
|
||||
|
||||
conf := c.task.LoggerConfig()
|
||||
if conf.URL == "" {
|
||||
c.opts.HostConfig.LogConfig = docker.LogConfig{
|
||||
Type: "none",
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
c.opts.HostConfig.LogConfig = docker.LogConfig{
|
||||
Type: "syslog",
|
||||
Config: map[string]string{
|
||||
"syslog-address": conf.URL,
|
||||
"syslog-facility": "user",
|
||||
"syslog-format": "rfc5424",
|
||||
},
|
||||
}
|
||||
|
||||
tags := make([]string, 0, len(conf.Tags))
|
||||
for _, pair := range conf.Tags {
|
||||
tags = append(tags, fmt.Sprintf("%s=%s", pair.Name, pair.Value))
|
||||
}
|
||||
if len(tags) > 0 {
|
||||
c.opts.HostConfig.LogConfig.Config["tag"] = strings.Join(tags, ",")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cookie) configureMem(log logrus.FieldLogger) {
|
||||
if c.task.Memory() == 0 {
|
||||
return
|
||||
|
||||
@@ -217,15 +217,11 @@ func (drv *DockerDriver) CreateCookie(ctx context.Context, task drivers.Containe
|
||||
Image: task.Image(),
|
||||
OpenStdin: true,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
AttachStdin: true,
|
||||
AttachStderr: true,
|
||||
StdinOnce: true,
|
||||
},
|
||||
// turn off logs since we're collecting them from attach
|
||||
HostConfig: &docker.HostConfig{
|
||||
LogConfig: docker.LogConfig{
|
||||
Type: "none",
|
||||
},
|
||||
ReadonlyRootfs: drv.conf.EnableReadOnlyRootFs,
|
||||
},
|
||||
Context: ctx,
|
||||
@@ -237,6 +233,7 @@ func (drv *DockerDriver) CreateCookie(ctx context.Context, task drivers.Containe
|
||||
drv: drv,
|
||||
}
|
||||
|
||||
cookie.configureLogger(log)
|
||||
cookie.configureMem(log)
|
||||
cookie.configureCmd(log)
|
||||
cookie.configureEnv(log)
|
||||
|
||||
@@ -71,6 +71,7 @@ func (c *poolTask) CPUs() uint64 { return 0
|
||||
func (c *poolTask) FsSize() uint64 { return 0 }
|
||||
func (c *poolTask) TmpFsSize() uint64 { return 0 }
|
||||
func (c *poolTask) Extensions() map[string]string { return nil }
|
||||
func (c *poolTask) LoggerConfig() drivers.LoggerConfig { return drivers.LoggerConfig{} }
|
||||
func (c *poolTask) WriteStat(ctx context.Context, stat drivers.Stat) {}
|
||||
|
||||
type dockerPoolItem struct {
|
||||
|
||||
@@ -37,6 +37,7 @@ func (f *taskDockerTest) WorkDir() string { return "" }
|
||||
func (f *taskDockerTest) Close() {}
|
||||
func (f *taskDockerTest) Input() io.Reader { return f.input }
|
||||
func (f *taskDockerTest) Extensions() map[string]string { return nil }
|
||||
func (f *taskDockerTest) LoggerConfig() drivers.LoggerConfig { return drivers.LoggerConfig{} }
|
||||
|
||||
func TestRunnerDocker(t *testing.T) {
|
||||
dkr := NewDocker(drivers.Config{})
|
||||
|
||||
Reference in New Issue
Block a user