Skip to content

Commit

Permalink
[chore][pkg/stanza] Unexport reader's eof flag (open-telemetry#27432)
Browse files Browse the repository at this point in the history
Incremental step towards decoupling the Reader struct.
  • Loading branch information
djaglowski committed Oct 4, 2023
1 parent f0c2cf4 commit 90b801d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (m *Manager) consume(ctx context.Context, paths []string) {
defer wg.Done()
r.ReadToEnd(ctx)
// Delete a file if deleteAfterRead is enabled and we reached the end of the file
if m.deleteAfterRead && r.EOF {
if m.deleteAfterRead && r.AtEOF() {
r.Delete()
}
}(r)
Expand Down
10 changes: 7 additions & 3 deletions pkg/stanza/fileconsumer/internal/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ type Reader struct {
*Config
*Metadata
FileName string
EOF bool
logger *zap.SugaredLogger
file *os.File
lineSplitFunc bufio.SplitFunc
splitFunc bufio.SplitFunc
decoder *decode.Decoder
headerReader *header.Reader
processFunc emit.Callback
eof bool
}

// offsetToEnd sets the starting offset
Expand Down Expand Up @@ -87,10 +87,10 @@ func (r *Reader) ReadToEnd(ctx context.Context) {

ok := s.Scan()
if !ok {
r.EOF = true
r.eof = true
if err := s.Error(); err != nil {
// If Scan returned an error then we are not guaranteed to be at the end of the file
r.EOF = false
r.eof = false
r.logger.Errorw("Failed during scan", zap.Error(err))
}
break
Expand Down Expand Up @@ -206,3 +206,7 @@ func (r *Reader) ValidateFingerprint() bool {
}
return refreshedFingerprint.StartsWith(r.Fingerprint)
}

func (r *Reader) AtEOF() bool {
return r.eof
}
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestTokenizationTooLongWithLineStartPattern(t *testing.T) {
require.NoError(t, err)

r.ReadToEnd(context.Background())
require.True(t, r.EOF)
require.True(t, r.AtEOF())

for _, expected := range expected {
require.Equal(t, expected, readToken(t, emitChan))
Expand Down

0 comments on commit 90b801d

Please sign in to comment.