-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(dumper): implement time
in dump path template
#145
Conversation
1ae11ea
to
f8c4b85
Compare
Holding file opened looks strange if we have dynamic parts in the template, since open time and time when happens
Doing things smart way (1) is even more harder if we take precision into account, for example, for file |
f8c4b85
to
abefe08
Compare
04e326e
to
be83ae0
Compare
484045c
to
43df2b0
Compare
ce088f0
to
51fdcfc
Compare
I guess we're okay as for now with whatever meaning of time used, for now it's time of opening the file or time of writing to the disk, depends on what precision of time is used, for most use-cases, where user doesn't use seconds precision, it would be time of opening the file. |
There's some unsafe dropped in the place, it's used only because of using Unsafe is used to:
unsafe usages are isolated and tested, so I guess it's okay |
51fdcfc
to
cf68ad0
Compare
let now = SystemTime::now(); | ||
let ts = now | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.expect("shit happens") |
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.
.unwrap_or(SystemTime::UNIX_EPOCH)
or more appropriate comment
@@ -106,7 +134,7 @@ impl Dumper { | |||
let config = self.ctx.config(); | |||
self.interval.set_period(config.write_interval); | |||
|
|||
path = config.path(self.ctx.key()); | |||
self.render_path(&mut path); | |||
self.file_registry |
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 the active file is changed between reconfiguration and the following DumpingTick
, we leave the previous one unclosed.
It seems we should replace open()
also with acquire_for_write()
here.
pub(crate) async fn acquire_for_write(&self, old_path: &str, path: &str) -> Result<FileHandle> { | ||
let mut fh = { | ||
let mut files = self.files.lock(); | ||
if old_path != path { |
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.
We can move the open logic to FileHandle
and store FileHandle
for a long time in every actor (instead of path
and path_swap
), which makes the code both clearer and less error-prone
Implements more flexible templating for storing dumps. Questions needed to be resolved in order to undraft:
The
{time}
itself has no information about precision (to hours? to minutes? to seconds?) and format (ISO? unix time?), we either need to choose format and precision, or allow customization, likestrftime
, but simpler:{time:dd-mm-YYYY}
with some default when format is omitted.IMO latter is better, it gives more flexibility in granularity.
We could use last dump message time or time when writing dump to the disk. IMO latter is nice approximation, since for the rotation purposes we usually need to clean-up space, not specific time interval and using that approximation wouldn't be problematic - time of writing the dump is never less than last dump message time, so, the worst-case scenario is keeping for some time expired files in FS. Or the hell scenario is broken system clock, which is problematic in any chosen way.