Skip to content

add input file tail#645

Merged
jem-davies merged 10 commits intowarpstreamlabs:mainfrom
jem-davies:add-input-file-tail
Feb 3, 2026
Merged

add input file tail#645
jem-davies merged 10 commits intowarpstreamlabs:mainfrom
jem-davies:add-input-file-tail

Conversation

@jem-davies
Copy link
Copy Markdown
Collaborator

@jem-davies jem-davies commented Jan 8, 2026

Some context: I had decided to implement this as a simpler alternative to #514.

Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Comment thread internal/impl/io/input_file_tail.go Outdated
Comment thread internal/impl/io/input_file_tail.go Outdated
Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Replace errChan draining with doneChan synchronization to ensure
watch() goroutine exits before closing file handle.

Also fix file handle leaks in newTail() error paths.
Signed-off-by: Jem Davies <jemsot@gmail.com>
Comment thread internal/impl/io/input_file_tail.go Outdated

if !os.SameFile(t.fileInfo, tempInfo) {
if t.logger != nil {
t.logger.Info(fmt.Sprintf("Handling rotation for %v", t.path))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we downgrade these rotation logs to the debug level?

Comment thread internal/impl/io/input_file_tail.go Outdated

pos, err := t.file.Seek(0, io.SeekCurrent)
if err != nil {
return fmt.Errorf("seek file: %w", err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps some of these errors should have more info added:

Suggested change
return fmt.Errorf("seek file: %w", err)
return fmt.Errorf("failed to set seek on %s: %w", t.file.Name(). , err)

Comment on lines +291 to +292
line, err := t.reader.ReadBytes('\n')
line = bytes.TrimRight(line, "\r\n")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why we're exclusively using \n as a delimiter here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes could have a config option for that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the component description to say "Reads lines from a file continuously with handling of log rotation." -- we could add it as a config option I suppose - but then would be interested too see why / what else people would want to use as a delimiter.

If there is an issue raised it should be ok to add a new config option with a default of "\n" for backwards comp.

So thinking to leave this as-is

Comment on lines +188 to +189
file *os.File
fileInfo os.FileInfo
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on using the *service.FS from the mgr *service.Resources instead for file reading?

i.e

mgr.FS().OpenFile()

This way we're relying on our FS fixtures instead of the os package

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done this 👍

Comment thread internal/impl/io/input_file_tail.go
@jem-davies
Copy link
Copy Markdown
Collaborator Author

@gregfurman - thanks for review 🙏 - I have either altered the code / responded to each comment 😄

Signed-off-by: Jem Davies <jemsot@gmail.com>
Copy link
Copy Markdown
Collaborator

@gregfurman gregfurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing ym feedback :shipit:

Comment thread internal/impl/io/input_file_tail.go
jem-davies and others added 2 commits February 3, 2026 17:57
Signed-off-by: Jem Davies <jemsot@gmail.com>
@jem-davies jem-davies merged commit 14e9e39 into warpstreamlabs:main Feb 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants