-
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.
Fix clean_inactive for Filestream input (#38632)
* Add tests for store GC * Add changelog * Run mage check and update all necessary files * Improve changelog entry * Fix `clean_inactive` for Filestream input The `clean_inactive` parameter was being parsed with the wrong key. It is parsed/used by an anonymous struct on `input-logfile/manager.go`, there it was parsed and used as `CleanTimeout` (`clean_timeout`). This `CleanTimeout` setting has got exactly the same effect as the `clean_inactive` described in our documentation. This commit fixes this bug by renaming `clean_timeout` to `clean_inactive` so the configuration value can have effect. * Add tests for `clean_inactive` and fix documentation * Add changelog * Update test config * Add licence headers and build tags * PR improvements - Rename `CleanTimeout` to `CleanInactive` - Remove commented out code * Fix rebase conflicts * Fix lint errors * Jenkins test this PR
- Loading branch information
Showing
7 changed files
with
126 additions
and
15 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
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,107 @@ | ||
// 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. | ||
|
||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/beats/v7/libbeat/tests/integration" | ||
) | ||
|
||
var filestreamCleanInactiveCfg = ` | ||
filebeat.inputs: | ||
- type: filestream | ||
id: "test-clean-inactive" | ||
paths: | ||
- %s | ||
clean_inactive: 3s | ||
ignore_older: 2s | ||
close.on_state_change.inactive: 1s | ||
prospector.scanner.check_interval: 1s | ||
filebeat.registry: | ||
cleanup_interval: 5s | ||
flush: 1s | ||
queue.mem: | ||
events: 32 | ||
flush.min_events: 8 | ||
flush.timeout: 0.1s | ||
path.home: %s | ||
output.file: | ||
path: ${path.home} | ||
filename: "output-file" | ||
rotate_every_kb: 10000 | ||
logging: | ||
level: debug | ||
selectors: | ||
- input | ||
- input.filestream | ||
metrics: | ||
enabled: false | ||
` | ||
|
||
func TestFilestreamCleanInactive(t *testing.T) { | ||
filebeat := integration.NewBeat( | ||
t, | ||
"filebeat", | ||
"../../filebeat.test", | ||
) | ||
tempDir := filebeat.TempDir() | ||
|
||
// 1. Generate the log file path, but do not write data to it | ||
logFilePath := path.Join(tempDir, "log.log") | ||
|
||
// 2. Write configuration file ans start Filebeat | ||
filebeat.WriteConfigFile(fmt.Sprintf(filestreamCleanInactiveCfg, logFilePath, tempDir)) | ||
filebeat.Start() | ||
|
||
// 3. Create the log file | ||
integration.GenerateLogFile(t, logFilePath, 10, false) | ||
|
||
// 4. Wait for Filebeat to start scanning for files | ||
// | ||
filebeat.WaitForLogs( | ||
fmt.Sprintf("A new file %s has been found", logFilePath), | ||
10*time.Second, | ||
"Filebeat did not start looking for files to ingest") | ||
|
||
filebeat.WaitForLogs( | ||
fmt.Sprintf("Reader was closed. Closing. Path='%s", logFilePath), | ||
10*time.Second, "Filebeat did not close the file") | ||
|
||
// 5. Now that the reader has been closed, nothing is holding the state | ||
// of the file, so once the TTL of its state expires and the store GC runs, | ||
// it will be removed from the registry. | ||
// Wait for the log message stating 1 entry has been removed from the registry | ||
filebeat.WaitForLogs("1 entries removed", 20*time.Second, "entry was not removed from registtry") | ||
|
||
// 6. Then assess it has been removed in the registry | ||
registryFile := filepath.Join(filebeat.TempDir(), "data", "registry", "filebeat", "log.json") | ||
filebeat.WaitFileContains(registryFile, `"op":"remove"`, time.Second) | ||
} |