Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logfile] Clean up state folder on init #1114

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/inputs/logfile/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ func (t *LogFile) Start(acc telegraf.Accumulator) error {
return fmt.Errorf("failed to create state file directory %s: %v", t.FileStateFolder, err)
}

// Clean state file regularly
// Clean state file on init and regularly
go func() {
t.cleanupStateFolder()
Copy link
Contributor

@adam-mateen adam-mateen Apr 11, 2024

Choose a reason for hiding this comment

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

Can you add a unit test or integ test which creates some files monitored by the agent, write 1 MiB of logs to them, verify the state files point to the EOF, then kill the agent, then write more data, then start the agent back up and make sure they report logs events from the 1 MiB point onwards? (i.e. state file is used correectly)

Maybe we already have a test like this, if so great.

My concern is that you are deleting the state files before the agent has a chance to start up and read them. (I think Zhihong has the same concern).

ticker := time.NewTicker(1 * time.Hour)
defer ticker.Stop()
for {
Expand Down
Loading