Skip to content

Commit

Permalink
handle EOF on single line content
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Spacca committed Nov 2, 2022
1 parent 6c01bc6 commit 26eb38f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions x-pack/filebeat/input/awss3/s3_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,21 @@ func (p *s3ObjectProcessor) readFile(r io.Reader) error {
var offset int64
for {
message, err := reader.Next()
if errors.Is(err, io.EOF) {
// No more lines
break
}
if err != nil {
isEOF := errors.Is(err, io.EOF)
if err != nil && !isEOF {
return fmt.Errorf("error reading message: %w", err)
}

event := p.createEvent(string(message.Content), offset)
event.Fields.DeepUpdate(message.Fields)
offset += int64(message.Bytes)
p.publish(p.acker, &event)

if isEOF {
// No more lines
break
}

}

return nil
Expand Down
4 changes: 4 additions & 0 deletions x-pack/filebeat/input/awss3/s3_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func TestS3ObjectProcessor(t *testing.T) {
err := s3ObjProc.Create(ctx, logp.NewLogger(inputName), ack, s3Event).ProcessS3Object()
require.NoError(t, err)
})

t.Run("text file without end of line marker", func(t *testing.T) {
testProcessS3Object(t, "testdata/no-eol.txt", "text/plain", 1)
})
}

func testProcessS3Object(t testing.TB, file, contentType string, numEvents int, selectors ...fileSelectorConfig) []beat.Event {
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/input/awss3/testdata/no-eol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file does contain a final EOL.

0 comments on commit 26eb38f

Please sign in to comment.