-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add state for ignore_older files (#2859)
Previously if a file was falling under ignore_older on startup and no previous state was found, also no state was persisted. This was important in 1.x releases to prevent the registry file to contain too many files as no cleanup was possible. With the new clean_* options the registry file can now be cleaned up. For consistency all files that fall under ignore_older should have a state, even if they are not crawled before. This change is also required to move tail_files under the prospector (#2613). Otherwise files which fall under `ignore_older` the state could not be set to the end of the file.
- Loading branch information
Showing
6 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// +build !integration | ||
|
||
package prospector | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/beats/filebeat/input/file" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var cleanInactiveTests = []struct { | ||
cleanInactive time.Duration | ||
fileTime time.Time | ||
result bool | ||
}{ | ||
{ | ||
cleanInactive: 0, | ||
fileTime: time.Now(), | ||
result: false, | ||
}, | ||
{ | ||
cleanInactive: 1 * time.Second, | ||
fileTime: time.Now().Add(-5 * time.Second), | ||
result: true, | ||
}, | ||
{ | ||
cleanInactive: 10 * time.Second, | ||
fileTime: time.Now().Add(-5 * time.Second), | ||
result: false, | ||
}, | ||
} | ||
|
||
func TestIsCleanInactive(t *testing.T) { | ||
|
||
for _, test := range cleanInactiveTests { | ||
|
||
prospector := ProspectorLog{ | ||
config: prospectorConfig{ | ||
CleanInactive: test.cleanInactive, | ||
}, | ||
} | ||
state := file.State{ | ||
Fileinfo: TestFileInfo{ | ||
time: test.fileTime, | ||
}, | ||
} | ||
|
||
assert.Equal(t, test.result, prospector.isCleanInactive(state)) | ||
} | ||
} | ||
|
||
type TestFileInfo struct { | ||
time time.Time | ||
} | ||
|
||
func (t TestFileInfo) Name() string { return "" } | ||
func (t TestFileInfo) Size() int64 { return 0 } | ||
func (t TestFileInfo) Mode() os.FileMode { return 0 } | ||
func (t TestFileInfo) ModTime() time.Time { return t.time } | ||
func (t TestFileInfo) IsDir() bool { return false } | ||
func (t TestFileInfo) Sys() interface{} { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters