Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate config before init NewInput to avoid uneccessory cleanup and kubernetes watcher leak #18630

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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