Skip to content

Commit

Permalink
Set the fileProspector's ignoreInactiveSince value (#34770)
Browse files Browse the repository at this point in the history
Set the fileProspector's ignoreInactiveSince value based on the ignore_active config option

---------

Co-authored-by: Denis <[email protected]>
  • Loading branch information
2 people authored and chrisberkhout committed Jun 1, 2023
1 parent 47b8be6 commit 596fb94
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
19 changes: 10 additions & 9 deletions filebeat/input/filestream/prospector_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -82,7 +83,7 @@ func newProspector(config config) (loginp.Prospector, error) {
cpCfg := &copyTruncateConfig{}
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 {
Expand Down
51 changes: 51 additions & 0 deletions filebeat/input/filestream/prospector_creator_test.go
Original file line number Diff line number Diff line change
@@ -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])
})
}
}

0 comments on commit 596fb94

Please sign in to comment.