Skip to content

Commit

Permalink
add individual tests for message_max_bytes and multiline max_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mauri870 committed Dec 17, 2024
1 parent 87a9ba0 commit 37720bf
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions filebeat/input/filestream/metrics_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,93 @@ func TestFilestreamMetrics(t *testing.T) {
env.waitUntilInputStops()
}

func TestFilestreamMessageMaxBytesTruncatedMetric(t *testing.T) {
env := newInputTestingEnvironment(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",
"message_max_bytes": 20,
})

testlines := []byte("first line\nsecond line\nthird line\nthis is a long line exceeding message_max_bytes\n")
env.mustWriteToFile(testlogName, testlines)

ctx, cancelInput := context.WithCancel(context.Background())
env.startInput(ctx, inp)

env.waitUntilEventCount(4)
env.requireOffsetInRegistry(testlogName, "fake-ID", len(testlines))
env.waitUntilHarvesterIsDone()

checkMetrics(t, "fake-ID", expectedMetrics{
FilesOpened: 1,
FilesClosed: 1,
FilesActive: 0,
MessagesRead: 4,
MessagesTruncated: 1,
BytesProcessed: 82,
EventsProcessed: 4,
ProcessingErrors: 0,
})

cancelInput()
env.waitUntilInputStops()
}

func TestFilestreamMultilineMaxLinesTruncatedMetric(t *testing.T) {
env := newInputTestingEnvironment(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",
"parsers": []map[string]interface{}{
{
"multiline": map[string]interface{}{
"type": "pattern",
"pattern": "^multiline",
"negate": true,
"match": "after",
"max_lines": 1,
"timeout": "1s",
},
},
},
})

testlines := []byte("first line\nsecond line\nmultiline first line\nmultiline second line\n")
env.mustWriteToFile(testlogName, testlines)

ctx, cancelInput := context.WithCancel(context.Background())
env.startInput(ctx, inp)

env.waitUntilEventCount(3)
env.requireOffsetInRegistry(testlogName, "fake-ID", len(testlines))
env.waitUntilHarvesterIsDone()

checkMetrics(t, "fake-ID", expectedMetrics{
FilesOpened: 1,
FilesClosed: 1,
FilesActive: 0,
MessagesRead: 3,
MessagesTruncated: 1,
BytesProcessed: 66,
EventsProcessed: 3,
ProcessingErrors: 0,
})

cancelInput()
env.waitUntilInputStops()
}

type expectedMetrics struct {
FilesOpened uint64
FilesClosed uint64
Expand Down

0 comments on commit 37720bf

Please sign in to comment.