Skip to content

Commit

Permalink
[Filebeat] keep track of bytes read when max_bytes exceeded (#31824)
Browse files Browse the repository at this point in the history
Keep track of bytes read when max_bytes exceeded
Add test code for exceeding max bytes in filebeat
  • Loading branch information
liuwenping authored and chrisberkhout committed Jun 1, 2023
1 parent 97768b9 commit 0d5596f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libbeat/reader/readfile/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (r *LineReader) skipUntilNewLine() (int, error) {

if idx != -1 {
r.inBuffer.Write(r.tempBuffer[idx+len(r.nl) : n])
skipped += idx
skipped += idx + len(r.nl)
} else {
skipped += n
}
Expand Down
13 changes: 11 additions & 2 deletions libbeat/reader/readfile/line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ func TestMaxBytesLimit(t *testing.T) {
}

// Read decodec lines and test
var idx int
var (
idx int
readLen int
)

for i := 0; ; i++ {
b, _, err := reader.Next()
b, n, err := reader.Next()
if err != nil {
if err == io.EOF {
break
Expand All @@ -387,11 +391,16 @@ func TestMaxBytesLimit(t *testing.T) {
break
}

readLen += n
s := string(b[:len(b)-len(nl)])
if line != s {
t.Fatalf("lines do not match, expected: %s got: %s", line, s)
}
}

if len(input) != readLen {
t.Fatalf("the bytes read are not equal to the bytes input, expected: %d got: %d", len(input), readLen)
}
}

// test_exceed_buffer from test_harvester.py
Expand Down

0 comments on commit 0d5596f

Please sign in to comment.