Skip to content

Commit

Permalink
[Filebeat] keep track of bytes read when max_bytes exceeded
Browse files Browse the repository at this point in the history
Closes #28317
  • Loading branch information
leehinman committed Oct 12, 2021
1 parent 058c405 commit b44be24
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ for a few releases. Please use other tools provided by Elastic to fetch data fro
- Tolerate faults when Windows Event Log session is interrupted {issue}27947[27947] {pull}28191[28191]
- Add support for username in cisco asa security negotiation logs {pull}26975[26975]
- Relax time parsing and capture group and session type in Cisco ASA module {issue}24710[24710] {pull}28325[28325]
- Correctly track bytes read when max_bytes is exceeded. {issue}28317[28317] {pull}28352[28352]

*Heartbeat*

Expand Down
2 changes: 2 additions & 0 deletions libbeat/reader/readfile/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (r *LineReader) advance() error {
for idx != -1 && idx > r.maxBytes {
r.logger.Warnf("Exceeded %d max bytes in line limit, skipped %d bytes line", r.maxBytes, idx)
err = r.inBuffer.Advance(idx + len(r.nl))
r.byteCount += idx + len(r.nl)
r.inBuffer.Reset()
r.inOffset = 0
idx = r.inBuffer.IndexFrom(r.inOffset, r.nl)
Expand All @@ -175,6 +176,7 @@ func (r *LineReader) advance() error {
return err
}
r.logger.Warnf("Exceeded %d max bytes in line limit, skipped %d bytes line", r.maxBytes, skipped)
r.byteCount += skipped
idx = r.inBuffer.IndexFrom(r.inOffset, r.nl)
}
}
Expand Down
7 changes: 1 addition & 6 deletions libbeat/reader/readfile/line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestMaxBytesLimit(t *testing.T) {
// Read decodec lines and test
var idx int
for i := 0; ; i++ {
b, n, err := reader.Next()
b, _, err := reader.Next()
if err != nil {
if err == io.EOF {
break
Expand All @@ -387,12 +387,7 @@ func TestMaxBytesLimit(t *testing.T) {
break
}

gotLen := n - len(nl)
s := string(b[:len(b)-len(nl)])
if len(line) != gotLen {
t.Fatalf("invalid line length, expected: %d got: %d", len(line), gotLen)
}

if line != s {
t.Fatalf("lines do not match, expected: %s got: %s", line, s)
}
Expand Down

0 comments on commit b44be24

Please sign in to comment.