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

Cherry-pick #18630 to 7.x: Validate config before init NewInput to avoid uneccessory cleanup and kubernetes watcher leak #18810

Merged
merged 1 commit into from
May 28, 2020

Conversation

exekias
Copy link
Contributor

@exekias exekias commented May 28, 2020

Cherry-pick of PR #18630 to 7.x branch. Original message:

An alternative Fix #18629

When Filebeat using add_kubernetes_metadata processor and enabled input.reload, It will cause Kubernetes watcher goroutine leaks when the input config is wrong.

I looked through the code in filebeat/input/log/input.go, notice that there is a defer function to cleanup when executing NewInput failed.

func NewInput(

// NewInput instantiates a new Log
func NewInput(
	cfg *common.Config,
	outlet channel.Connector,
	context input.Context,
) (input.Input, error) {
	cleanupNeeded := true
	cleanupIfNeeded := func(f func() error) {
		if cleanupNeeded {
			f()
		}
	}

But it seems not easy to add Kubernetes watcher stopping function here, So I move the validate section to the top, then NewInput will return directly if the config not qualified.

// NewInput instantiates a new Log
func NewInput(
	cfg *common.Config,
	outlet channel.Connector,
	context input.Context,
) (input.Input, error) {
	cleanupNeeded := true
	cleanupIfNeeded := func(f func() error) {
		if cleanupNeeded {
			f()
		}
	}

	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")
	}

…t's misconfigured(elastic#18629) (elastic#18630)

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

Signed-off-by: 屈骏 <qujun@tiduyun.com>
(cherry picked from commit 74d81c2)
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 28, 2020
@exekias exekias added the Team:Integrations Label for the Integrations team label May 28, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 28, 2020
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #18810 opened]

  • Start Time: 2020-05-28T07:27:06.691+0000

  • Duration: 79 min 4 sec

Test stats 🧪

Test Results
Failed 0
Passed 6639
Skipped 1053
Total 7692

Steps errors

Expand to view the steps failures

  • Name: Report to Codecov

    • Description: curl -sSLo codecov https://codecov.io/bash for i in auditbeat filebeat heartbeat libbeat metricbeat packetbeat winlogbeat journalbeat do FILE="${i}/build/coverage/full.cov" if [ -f "${FILE}" ]; then bash codecov -f "${FILE}" fi done

    • Duration: 2 min 22 sec

    • Start Time: 2020-05-28T07:52:19.263+0000

    • log

  • Name: Install Go 1.13.10

    • Description: .ci/scripts/install-go.sh

    • Duration: 1 min 10 sec

    • Start Time: 2020-05-28T07:49:48.871+0000

    • log

  • Name: Report to Codecov

    • Description: curl -sSLo codecov https://codecov.io/bash for i in auditbeat filebeat heartbeat libbeat metricbeat packetbeat winlogbeat journalbeat do FILE="${i}/build/coverage/full.cov" if [ -f "${FILE}" ]; then bash codecov -f "${FILE}" fi done

    • Duration: 2 min 22 sec

    • Start Time: 2020-05-28T08:40:21.016+0000

    • log

@exekias exekias merged commit 998e5e8 into elastic:7.x May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport review Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants