diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a166cef96fc6..d7b634384357 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -99,6 +99,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff] - Fix for httpjson first_response object throwing false positive errors by making it a flag based object {issue}34747[34747] {pull}34748[34748] - Fix errors and panics due to re-used processors {pull}34761[34761] - Add missing Basic Authentication support to CEL input {issue}34609[34609] {pull}34689[34689] +- Fix the ignore_inactive option being ignored in Filebeat's filestream input {pull}34770[34770] *Heartbeat* diff --git a/filebeat/input/filestream/prospector_creator.go b/filebeat/input/filestream/prospector_creator.go index 9457af104cf9..75a5e8dc3aad 100644 --- a/filebeat/input/filestream/prospector_creator.go +++ b/filebeat/input/filestream/prospector_creator.go @@ -38,20 +38,21 @@ var experimentalWarning sync.Once func newProspector(config config) (loginp.Prospector, error) { filewatcher, err := newFileWatcher(config.Paths, config.FileWatcher) if err != nil { - return nil, fmt.Errorf("error while creating filewatcher %v", err) + return nil, fmt.Errorf("error while creating filewatcher %w", err) } identifier, err := newFileIdentifier(config.FileIdentity, getIdentifierSuffix(config)) if err != nil { - return nil, fmt.Errorf("error while creating file identifier: %v", err) + return nil, fmt.Errorf("error while creating file identifier: %w", err) } fileprospector := fileProspector{ - filewatcher: filewatcher, - identifier: identifier, - ignoreOlder: config.IgnoreOlder, - cleanRemoved: config.CleanRemoved, - stateChangeCloser: config.Close.OnStateChange, + filewatcher: filewatcher, + identifier: identifier, + ignoreOlder: config.IgnoreOlder, + ignoreInactiveSince: config.IgnoreInactive, + cleanRemoved: config.CleanRemoved, + stateChangeCloser: config.Close.OnStateChange, } if config.Rotation == nil { return &fileprospector, nil @@ -70,7 +71,7 @@ func newProspector(config config) (loginp.Prospector, error) { cfg := rotationConfig{} err := externalConfig.Unpack(&cfg) if err != nil { - return nil, fmt.Errorf("failed to unpack configuration of external rotation: %+v", err) + return nil, fmt.Errorf("failed to unpack configuration of external rotation: %w", err) } strategy := cfg.Strategy.Name() switch strategy { @@ -82,7 +83,7 @@ func newProspector(config config) (loginp.Prospector, error) { cpCfg := ©TruncateConfig{} err = cfg.Strategy.Config().Unpack(&cpCfg) if err != nil { - return nil, fmt.Errorf("failed to unpack configuration of external copytruncate rotation: %+v", err) + return nil, fmt.Errorf("failed to unpack configuration of external copytruncate rotation: %w", err) } suffix, err := regexp.Compile(cpCfg.SuffixRegex) if err != nil { diff --git a/filebeat/input/filestream/prospector_creator_test.go b/filebeat/input/filestream/prospector_creator_test.go new file mode 100644 index 000000000000..bb87cc7118d1 --- /dev/null +++ b/filebeat/input/filestream/prospector_creator_test.go @@ -0,0 +1,51 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package filestream + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCreateProspector_SetIgnoreInactiveSince(t *testing.T) { + testCases := map[string]struct { + ignore_inactive_since string + }{ + "ignore_inactive_since set to since_last_start": { + ignore_inactive_since: "since_last_start", + }, + "ignore_inactive_since set to since_first_start": { + ignore_inactive_since: "since_first_start", + }, + "ignore_inactive_since not set": { + ignore_inactive_since: "", + }, + } + for name, test := range testCases { + test := test + t.Run(name, func(t *testing.T) { + c := config{ + IgnoreInactive: ignoreInactiveSettings[test.ignore_inactive_since], + } + p, _ := newProspector(c) + fileProspector := p.(*fileProspector) + assert.Equal(t, fileProspector.ignoreInactiveSince, ignoreInactiveSettings[test.ignore_inactive_since]) + }) + } +}