-
Notifications
You must be signed in to change notification settings - Fork 37
Add proxy log file cleanup #736
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
base: main
Are you sure you want to change the base?
Conversation
Clean up old coder-ssh-*.log files when count exceeds 20 and files are older than 7 days. Uses mtime-based sorting to delete oldest stale files first.
25684d1 to
128754a
Compare
mtojek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 for writing tests
| const stats = await fs.stat(path.join(logDir, name)); | ||
| return { name, mtime: stats.mtime.getTime() }; | ||
| } catch { | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is any weird permission denied error, wouldn't this be an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be swallowed yes, I'm not sure I wanna log these 🤔
| const now = Date.now(); | ||
| const files = await fs.readdir(logDir); | ||
|
|
||
| const withStats = await Promise.all( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that in a typical setup, we will have max 20 log files? no way we will need a handle 100+ = 100 x fs.stat in parallel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The files themselves have timestamps in the name, would it make sense to delete based on the filename only? They are named based on the creation but not necessarily when they were last modified so that's why I settled for this. Potentially we can just sort, delete until there's 20 left
Summary
coder-ssh-*.log) in the proxy log directoryFixed #377