From c48d688bace1049296d592e245a14bacf56946fb Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Fri, 22 Feb 2019 18:32:27 +0100 Subject: [PATCH] Add cleanup_timeout option to docker autodiscover --- .../autodiscover/providers/docker/config.go | 22 +++++++++++-------- .../autodiscover/providers/docker/docker.go | 6 ++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libbeat/autodiscover/providers/docker/config.go b/libbeat/autodiscover/providers/docker/config.go index 0b76887a10f..f7f83f91777 100644 --- a/libbeat/autodiscover/providers/docker/config.go +++ b/libbeat/autodiscover/providers/docker/config.go @@ -18,6 +18,8 @@ package docker import ( + "time" + "github.com/elastic/beats/libbeat/autodiscover/template" "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/common/docker" @@ -25,19 +27,21 @@ import ( // Config for docker autodiscover provider type Config struct { - Host string `config:"host"` - TLS *docker.TLSConfig `config:"ssl"` - Prefix string `config:"prefix"` - HintsEnabled bool `config:"hints.enabled"` - Builders []*common.Config `config:"builders"` - Appenders []*common.Config `config:"appenders"` - Templates template.MapperSettings `config:"templates"` + Host string `config:"host"` + TLS *docker.TLSConfig `config:"ssl"` + Prefix string `config:"prefix"` + HintsEnabled bool `config:"hints.enabled"` + Builders []*common.Config `config:"builders"` + Appenders []*common.Config `config:"appenders"` + Templates template.MapperSettings `config:"templates"` + CleanupTimeout time.Duration `config:"cleanup_timeout"` } func defaultConfig() *Config { return &Config{ - Host: "unix:///var/run/docker.sock", - Prefix: "co.elastic", + Host: "unix:///var/run/docker.sock", + Prefix: "co.elastic", + CleanupTimeout: 60 * time.Second, } } diff --git a/libbeat/autodiscover/providers/docker/docker.go b/libbeat/autodiscover/providers/docker/docker.go index 4f9478c4652..9d14672969a 100644 --- a/libbeat/autodiscover/providers/docker/docker.go +++ b/libbeat/autodiscover/providers/docker/docker.go @@ -18,6 +18,8 @@ package docker import ( + "time" + "github.com/elastic/beats/libbeat/autodiscover" "github.com/elastic/beats/libbeat/autodiscover/builder" "github.com/elastic/beats/libbeat/autodiscover/template" @@ -109,7 +111,9 @@ func (d *Provider) Start() { d.emitContainer(event, "start") case event := <-d.stopListener.Events(): - d.emitContainer(event, "stop") + time.AfterFunc(d.config.CleanupTimeout, func() { + d.emitContainer(event, "stop") + }) } } }()