Skip to content

Commit

Permalink
check config before init NewInput to avoid uneccessory cleanup when I…
Browse files Browse the repository at this point in the history
…t's misconfigured(elastic#18629) (elastic#18630)

fix log format missing in libbeat/common/kubernetes/util.go

Signed-off-by: 屈骏 <[email protected]>
  • Loading branch information
DanielQujun authored May 28, 2020
1 parent d37b598 commit 74d81c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Fix a rate limit related issue in httpjson input for Okta module. {issue}18530[18530] {pull}18534[18534]
- Fix `googlecloud.audit` pipeline to only take in fields that are explicitly defined by the dataset. {issue}18465[18465] {pull}18472[18472]
- Fix `o365.audit` failing to ingest events when ip address is surrounded by square brackets. {issue}18587[18587] {pull}18591[18591]
- Fix Kubernetes Watcher goroutine leaks when input config is invalid and `input.reload` is enabled. {issue}18629[18629] {pull}18630[18630]

*Heartbeat*

Expand Down
32 changes: 17 additions & 15 deletions filebeat/input/log/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ func NewInput(
}
}

inputConfig := defaultConfig

if err := cfg.Unpack(&inputConfig); err != nil {
return nil, err
}
if err := inputConfig.resolveRecursiveGlobs(); err != nil {
return nil, fmt.Errorf("Failed to resolve recursive globs in config: %v", err)
}
if err := inputConfig.normalizeGlobPatterns(); err != nil {
return nil, fmt.Errorf("Failed to normalize globs patterns: %v", err)
}

if len(inputConfig.Paths) == 0 {
return nil, fmt.Errorf("each input must have at least one path defined")
}

// Note: underlying output.
// The input and harvester do have different requirements
// on the timings the outlets must be closed/unblocked.
Expand Down Expand Up @@ -113,7 +129,7 @@ func NewInput(
}

p := &Input{
config: defaultConfig,
config: inputConfig,
cfg: cfg,
harvesters: harvester.NewRegistry(),
outlet: out,
Expand All @@ -123,27 +139,13 @@ func NewInput(
meta: meta,
}

if err := cfg.Unpack(&p.config); err != nil {
return nil, err
}
if err := p.config.resolveRecursiveGlobs(); err != nil {
return nil, fmt.Errorf("Failed to resolve recursive globs in config: %v", err)
}
if err := p.config.normalizeGlobPatterns(); err != nil {
return nil, fmt.Errorf("Failed to normalize globs patterns: %v", err)
}

// Create empty harvester to check if configs are fine
// TODO: Do config validation instead
_, err = p.createHarvester(file.State{}, nil)
if err != nil {
return nil, err
}

if len(p.config.Paths) == 0 {
return nil, fmt.Errorf("each input must have at least one path defined")
}

err = p.loadStates(context.States)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func DiscoverKubernetesNode(log *logp.Logger, host string, inCluster bool, clien
log.Errorf("kubernetes: Querying for pod failed with error: %+v", err)
return defaultNode
}
log.Info("kubernetes: Using node %s discovered by in cluster pod node query", pod.Spec.NodeName)
log.Infof("kubernetes: Using node %s discovered by in cluster pod node query", pod.Spec.NodeName)
return pod.Spec.NodeName
}

Expand Down

0 comments on commit 74d81c2

Please sign in to comment.