-
Notifications
You must be signed in to change notification settings - Fork 281
added flag for clearing log files at restart #3203
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ where | |
local_app_dir: Option<PathBuf>, | ||
provided_state_dir: UserProvidedPath, | ||
provided_log_dir: UserProvidedPath, | ||
refresh_logs: bool, | ||
) -> anyhow::Result<Self> { | ||
let toml = match runtime_config_path { | ||
Some(runtime_config_path) => { | ||
|
@@ -117,8 +118,13 @@ where | |
} | ||
None => Default::default(), | ||
}; | ||
let toml_resolver = | ||
TomlResolver::new(&toml, local_app_dir, provided_state_dir, provided_log_dir); | ||
let toml_resolver = TomlResolver::new( | ||
&toml, | ||
local_app_dir, | ||
provided_state_dir, | ||
provided_log_dir, | ||
refresh_logs, | ||
); | ||
|
||
Self::new(toml_resolver, runtime_config_path) | ||
} | ||
|
@@ -192,6 +198,8 @@ pub struct TomlResolver<'a> { | |
state_dir: UserProvidedPath, | ||
/// Explicitly provided log directory. | ||
log_dir: UserProvidedPath, | ||
/// Whether to refresh logs when restarted. | ||
refresh_logs: bool, | ||
} | ||
|
||
impl<'a> TomlResolver<'a> { | ||
|
@@ -201,12 +209,14 @@ impl<'a> TomlResolver<'a> { | |
local_app_dir: Option<PathBuf>, | ||
state_dir: UserProvidedPath, | ||
log_dir: UserProvidedPath, | ||
refresh_logs: bool, | ||
) -> Self { | ||
Self { | ||
table: TomlKeyTracker::new(table), | ||
local_app_dir, | ||
state_dir, | ||
log_dir, | ||
refresh_logs, | ||
} | ||
} | ||
|
||
|
@@ -268,7 +278,17 @@ impl<'a> TomlResolver<'a> { | |
} | ||
|
||
match log_dir { | ||
UserProvidedPath::Provided(p) if self.refresh_logs => Ok(Some({ | ||
let _ = std::fs::remove_dir_all(&p); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to end up duplicating the check and the deletion code. It seems like something you could do outside the But I see this is in a function whose job is to "get the configured log directory." Getting path to a directory should not have a potential side effect of deleting that directory - that's super surprising behaviour. (Similarly, notice that this function does not create the directory. It just gets the path.) So I think this code needs to move somewhere else, at which point hopefully we will know where the log directory is (if we have one) and can clear it without resorting to repeated guards or code. |
||
|
||
std::path::absolute(p)? | ||
})), | ||
UserProvidedPath::Provided(p) => Ok(Some(std::path::absolute(p)?)), | ||
UserProvidedPath::Default if self.refresh_logs => Ok(self.state_dir()?.map(|p| { | ||
let _ = std::fs::remove_dir_all(&p); | ||
|
||
p.join("logs") | ||
})), | ||
UserProvidedPath::Default => Ok(self.state_dir()?.map(|p| p.join("logs"))), | ||
UserProvidedPath::Unset => Ok(None), | ||
} | ||
|
@@ -619,6 +639,7 @@ mod tests { | |
None, | ||
UserProvidedPath::Default, | ||
UserProvidedPath::Default, | ||
false, | ||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ pub use stdio::StdioLoggingExecutorHooks; | |||||
pub use summary::{KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook}; | ||||||
|
||||||
pub const APP_LOG_DIR: &str = "APP_LOG_DIR"; | ||||||
pub const REFRESH_LOGS: &str = "REFRESH_LOGS"; | ||||||
pub const DISABLE_WASMTIME_CACHE: &str = "DISABLE_WASMTIME_CACHE"; | ||||||
pub const FOLLOW_LOG_OPT: &str = "FOLLOW_ID"; | ||||||
pub const WASMTIME_CACHE_FILE: &str = "WASMTIME_CACHE_FILE"; | ||||||
|
@@ -54,6 +55,14 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde | |||||
)] | ||||||
pub log: Option<PathBuf>, | ||||||
|
||||||
/// Whether to refresh logs when restarted. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the word "refresh" a bit odd here, although I can see the connection when I squint. At least in help text, I think we should be more explicit about what the flag does, e.g.
Suggested change
(or 'clears the log files'? Not sure which is better) |
||||||
#[clap( | ||||||
name = REFRESH_LOGS, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe consider a (sorry forgot to think of this while reviewing) |
||||||
short = 'r', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't spend a valuable shortcode on this. |
||||||
long = "refresh-logs", | ||||||
)] | ||||||
pub refresh_logs: bool, | ||||||
|
||||||
/// Disable Wasmtime cache. | ||||||
#[clap( | ||||||
name = DISABLE_WASMTIME_CACHE, | ||||||
|
@@ -139,6 +148,8 @@ pub struct FactorsConfig { | |||||
pub follow_components: FollowComponents, | ||||||
/// Log directory for component stdout/stderr. | ||||||
pub log_dir: UserProvidedPath, | ||||||
/// Whether to refresh logs when restarted. | ||||||
pub refresh_logs: bool, | ||||||
} | ||||||
|
||||||
/// An empty implementation of clap::Args to be used as TriggerExecutor::RunConfig | ||||||
|
@@ -220,6 +231,7 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> FactorsTriggerCommand<T, | |||||
local_app_dir: local_app_dir.clone(), | ||||||
follow_components, | ||||||
log_dir, | ||||||
refresh_logs: self.refresh_logs, | ||||||
}; | ||||||
|
||||||
let run_fut = builder | ||||||
|
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.
A bit strange to see this in a struct called TomlResolver - it's not like it has anything to do with resolving TOML. But I guess maybe the log directory is already non-TOML-related and the struct has just grown beyond its original name? Not sure.
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.
Somewhat, yes.
All but
refresh_logs
still source the default value fromtable: TomlKeyTracker<'a>
, so the initial name makes sense. However, with other elements added, a change of name would be better, something likeRuntimeConfigurationResolver
. Would that be fine, or what would you suggest?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 should have come back to this comment after writing the one about the location of the delete code - sorry.
We should first figure out a good place for the delete code to live, whether in this struct impl or elsewhere. Then that will guide us as to whether this flag needs to live here or not.