Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Dec 13, 2024
1 parent 9758447 commit 68c4a64
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 58 deletions.
1 change: 1 addition & 0 deletions filebeat/input/filestream/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ func getIDFromPath(filepath, inputID string, fi os.FileInfo) string {

// waitUntilEventCount waits until total count events arrive to the client.
func (e *inputTestingEnvironment) waitUntilEventCount(count int) {
e.t.Helper()
msg := &strings.Builder{}
require.Eventuallyf(e.t, func() bool {
msg.Reset()
Expand Down
24 changes: 14 additions & 10 deletions filebeat/input/filestream/input_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func TestFilestreamCloseRenamed(t *testing.T) {
"id": id,
"paths": []string{env.abspath(testlogName) + "*"},
"prospector.scanner.check_interval": "10ms",
"prospector.scanner.fingerprint.enabled": false,
"close.on_state_change.check_interval": "1ms",
"close.on_state_change.renamed": "true",
"prospector.scanner.fingerprint.enabled": false,
"file_identity.native": map[string]any{},
})

Expand Down Expand Up @@ -540,11 +540,13 @@ func TestFilestreamCloseAfterIntervalRotatedAndNewRemoved(t *testing.T) {
testlogName := "test.log"
id := "fake-ID-" + uuid.Must(uuid.NewV4()).String()
inp := env.mustCreateInput(map[string]interface{}{
"id": id,
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"close.on_state_change.check_interval": "10ms",
"close.on_state_change.inactive": "100ms",
"id": id,
"paths": []string{env.abspath(testlogName)},
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": "false",
"prospector.scanner.check_interval": "1ms",
"close.on_state_change.check_interval": "10ms",
"close.on_state_change.inactive": "100ms",
// reader is not stopped when file is removed to see if the reader can still detect
// if the file has been inactive even if it have been removed in the meantime
"close.on_state_change.removed": "false",
Expand Down Expand Up @@ -707,10 +709,12 @@ func TestFilestreamTruncateBigScannerInterval(t *testing.T) {
testlogName := "test.log"
id := "fake-ID-" + uuid.Must(uuid.NewV4()).String()
inp := env.mustCreateInput(map[string]interface{}{
"id": id,
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "5s",
"prospector.scanner.resend_on_touch": "true",
"id": id,
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "5s",
"prospector.scanner.resend_on_touch": "true",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
})

ctx, cancelInput := context.WithCancel(context.Background())
Expand Down
8 changes: 7 additions & 1 deletion filebeat/input/filestream/legacy_metrics_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ filebeat.inputs:
enabled: true
close.reader.after_interval: 1s
prospector.scanner.check_interval: 500ms
file_identity.native: ~
prospector.scanner.fingerprint.enabled: false
paths:
- %s/*.filestream
- type: log
id: my-log-input
enabled: true
close_timeout: 1s
scan_frequency: 500ms
file_identity.native: ~
prospector.scanner.fingerprint.enabled: false
paths:
- %s/*.log
Expand All @@ -71,7 +75,9 @@ func TestLegacyMetrics(t *testing.T) {
filebeat.WriteConfigFile(cfg)
filebeat.Start()

filebeat.WaitForLogs("Metrics endpoint listening on:", 10*time.Second)
filebeat.WaitForLogs("Metrics endpoint listening on:",
10*time.Second,
"metrics endpoint did not start")

// After starting Filebeat all counters must be zero
waitForMetrics(t,
Expand Down
12 changes: 7 additions & 5 deletions filebeat/input/filestream/metrics_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ func TestFilestreamMetrics(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "24h",
"close.on_state_change.check_interval": "100ms",
"close.on_state_change.inactive": "2s",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "24h",
"close.on_state_change.check_interval": "100ms",
"close.on_state_change.inactive": "2s",
"prospector.scanner.fingerprint.enabled": false,
"file_identity.native": map[string]any{},
})

testlines := []byte("first line\nsecond line\nthird line\n")
Expand Down
110 changes: 68 additions & 42 deletions filebeat/input/filestream/parsers_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func TestParsersAgentLogs(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"ndjson": map[string]interface{}{
Expand Down Expand Up @@ -65,9 +67,11 @@ func TestParsersIncludeMessage(t *testing.T) {
testlogName := "test.log"
readLine := "include this"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "100ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "100ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"include_message": map[string]interface{}{
Expand Down Expand Up @@ -98,9 +102,11 @@ func TestParsersDockerLogsFiltering(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"ndjson": map[string]interface{}{
Expand Down Expand Up @@ -137,9 +143,11 @@ func TestParsersSimpleJSONOverwrite(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"ndjson": map[string]interface{}{
Expand Down Expand Up @@ -173,9 +181,11 @@ func TestParsersTimestampInJSONMessage(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"ndjson": map[string]interface{}{
Expand Down Expand Up @@ -214,9 +224,11 @@ func TestParsersJavaElasticsearchLogs(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -249,9 +261,11 @@ func TestParsersCStyleLog(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -290,9 +304,11 @@ func TestParsersRabbitMQMultilineLog(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -335,9 +351,11 @@ func TestParsersMultilineMaxLines(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -379,9 +397,11 @@ func TestParsersMultilineTimeout(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -444,10 +464,12 @@ func TestParsersMultilineMaxBytes(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"message_max_bytes": 50,
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"message_max_bytes": 50,
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -486,10 +508,12 @@ func TestParsersCloseTimeoutWithMultiline(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"close.reader.after_interval": "1s",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"close.reader.after_interval": "1s",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down Expand Up @@ -551,10 +575,12 @@ func TestParsersConsecutiveNewline(t *testing.T) {

testlogName := "test.log"
inp := env.mustCreateInput(map[string]interface{}{
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"close.reader.after_interval": "1s",
"id": "fake-ID",
"paths": []string{env.abspath(testlogName)},
"prospector.scanner.check_interval": "1ms",
"close.reader.after_interval": "1s",
"file_identity.native": map[string]any{},
"prospector.scanner.fingerprint.enabled": false,
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
Expand Down

0 comments on commit 68c4a64

Please sign in to comment.