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

Write Promtail position file atomically. #5266

Merged
merged 11 commits into from
Feb 1, 2022

Conversation

jeschkies
Copy link
Contributor

@jeschkies jeschkies commented Jan 28, 2022

What this PR does / why we need it:
This uses renameio that supports writing files atomically.

Which issue(s) this PR fixes:
Fixes #5218

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@jeschkies jeschkies requested a review from a team as a code owner January 28, 2022 16:27
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Nice! Added a question about Windows but overall LGTM


err = ioutil.WriteFile(temp, buf, os.FileMode(positionFileMode))
err = renameio.WriteFile(target, buf, os.FileMode(positionFileMode))
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/google/renameio#windows-support

According to this, we should probably special-case Windows here. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to reference it. You were faster. I think so. We should use the old version on Windows.

go.mod Outdated Show resolved Hide resolved

err = ioutil.WriteFile(temp, buf, os.FileMode(positionFileMode))
err = renameio.WriteFile(target, buf, os.FileMode(positionFileMode))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to reference it. You were faster. I think so. We should use the old version on Windows.

Copy link
Contributor

@chaudum chaudum left a comment

Choose a reason for hiding this comment

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

Minor suggestion, but otherwise LGTM!

clients/pkg/promtail/positions/write_positions.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@jeschkies jeschkies merged commit b92b544 into grafana:main Feb 1, 2022
@jeschkies jeschkies deleted the karsten/write-position-file branch February 1, 2022 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promtail: recover from corrupted position file
3 participants