Skip to content

Commit

Permalink
Make docker input check if container strings are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Aug 15, 2018
1 parent 87b9f32 commit b4b8c06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- Make inputsource generic taking bufio.SplitFunc as input {pull}7746[7746]
- Add custom unpack to log hints config to avoid env resolution {pull}7710[7710]
- Keep raw user agent information after parsing as user_agent_raw in Filebeat modules. {pull}7823[7832]
- Make docker input check if container strings are empty {pull}7960[7960]

*Heartbeat*

Expand Down
21 changes: 18 additions & 3 deletions filebeat/input/docker/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/elastic/beats/filebeat/input/log"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/libbeat/logp"

"github.com/pkg/errors"
)
Expand All @@ -44,18 +45,32 @@ func NewInput(
context input.Context,
) (input.Input, error) {
cfgwarn.Experimental("Docker input is enabled.")
logger := logp.NewLogger("docker")

// Wrap log input with custom docker settings
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return nil, errors.Wrap(err, "reading docker input config")
}

// Wrap log input with custom docker settings
if len(config.Containers.IDs) == 0 {
// Docker input should make sure that no callers should ever pass empty strings as container IDs
// Hence we explicitly make sure that we catch such things and print stack traces in the event of
// an invocation so that it can be fixed.
var ids []string
for _, containerID := range config.Containers.IDs {
if containerID != "" {
ids = append(ids, containerID)
} else {
logger.Error("Docker container ID can't be empty for Docker input config")
logger.Debugw("Empty docker container ID was received", logp.Stack("stacktrace"))
}
}

if len(ids) == 0 {
return nil, errors.New("Docker input requires at least one entry under 'containers.ids'")
}

for idx, containerID := range config.Containers.IDs {
for idx, containerID := range ids {
cfg.SetString("paths", idx, path.Join(config.Containers.Path, containerID, "*.log"))
}

Expand Down

0 comments on commit b4b8c06

Please sign in to comment.