Skip to content

Commit

Permalink
Add cleanup_timeout option to docker autodiscover
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Feb 27, 2019
1 parent bd8922f commit c48d688
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 13 additions & 9 deletions libbeat/autodiscover/providers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@
package docker

import (
"time"

"github.com/elastic/beats/libbeat/autodiscover/template"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/docker"
)

// 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,
}
}

Expand Down
6 changes: 5 additions & 1 deletion libbeat/autodiscover/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
})
}
}
}()
Expand Down

0 comments on commit c48d688

Please sign in to comment.