-
Notifications
You must be signed in to change notification settings - Fork 37
simln-lib/feature: Optional name for activity descriptions #253
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?
simln-lib/feature: Optional name for activity descriptions #253
Conversation
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.
Thanks for the PR!
This needs a little git surgery to get the last few commits into shape, feel free to just restructure as you see fit + squash (rather than using fixups) so that we can start with a solid base.
Only major design ask is whether we actually need Option
throughout
sim-cli/src/parsing.rs
Outdated
for (index, act) in activity.into_iter().enumerate() { | ||
// Generate a default name if one is not provided | ||
let name = match &act.name { | ||
Some(name) if !name.is_empty() => { |
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 think we can afford to be stricter and disallow an empty string - really can't see somebody having much purpose for name: ""
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.
Okay, that could be done
sim-cli/src/parsing.rs
Outdated
while !activity_names.insert(unique_name.clone()) { | ||
unique_name = format!("{}-{}", default_name, counter); | ||
counter += 1; | ||
} |
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.
This validation has an ordering condition - right?
- If we've got an explicit name
Activity-x
before this, we'll correctly validate - If we've got an explicit name
Activity-x
after this, we'll end up failing the above check on a user-provided check
I think that we can afford to be strict and just disallow explicit names with the internally reserved format Activity-x
- I feel like all (sane) users can live with that. Simplifies this, and then we just need to add a regex above to check the explicit names (I think we can just match Activity-{any number})
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.
Yeah, I didn't think it that way, I would add that condition to it
Thanks for the heads up
simln-lib/src/lib.rs
Outdated
@@ -164,6 +164,8 @@ pub type Interval = ValueOrRange<u16>; | |||
/// This is constructed during activity validation and passed along to the [Simulation]. | |||
#[derive(Debug, Clone)] | |||
pub struct ActivityDefinition { | |||
/// Optional name/identifier for this activity |
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.
nit: here and above, name/identifier
isn't helpful - since we're requiring that these be unique I think we can just say identifier in our comments.
Should also terminate comments with .
- applies in various places for this PR
@@ -7,6 +7,7 @@ use tokio::time::Duration; | |||
|
|||
#[derive(Clone)] | |||
pub struct DefinedPaymentActivity { | |||
name: Option<String>, |
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 we're going to always fill this in if the end user provides it, so we want this to be Option
?
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.
Yeah, and also another reason for the Option
is for it not to break the system for backward compatibility
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 agree that this should be optional in ActivityParser
, but DefinedPaymentActivity
is an internal struct unrelated to parsing user values? It can be an Option
when we parse it and required when we use it interanally.
Also shouldn't have #[allow(dead_code)]
here?
simln-lib/src/defined_activity.rs
Outdated
"[{:?}] static payment of {} to {} every {}s", | ||
self.name, self.amount, self.destination, self.wait |
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 don't think we need an option here, but if I'm wrong this needs cleanup:
This is going to print something ugly like Some(name)
, rather inline a quick decomposing of the option.
if let Some(name) = self.name { name } else { "" }
simln-lib/src/defined_activity.rs
Outdated
@@ -39,8 +39,8 @@ impl fmt::Display for DefinedPaymentActivity { | |||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |||
write!( | |||
f, | |||
"[{:?}] static payment of {} to {} every {}s", | |||
self.name, self.amount, self.destination, self.wait | |||
"static payment of {} to {} every {}s", |
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.
Name added in the commit before and removed here?
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.
Yeah, I found out it wasn't where I needed it to be in
0401324
to
b99ac02
Compare
Thank you for the feedback, I have implemented the changes needed. |
@@ -7,6 +7,7 @@ use tokio::time::Duration; | |||
|
|||
#[derive(Clone)] | |||
pub struct DefinedPaymentActivity { | |||
name: Option<String>, |
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 agree that this should be optional in ActivityParser
, but DefinedPaymentActivity
is an internal struct unrelated to parsing user values? It can be an Option
when we parse it and required when we use it interanally.
Also shouldn't have #[allow(dead_code)]
here?
// Disallow empty names | ||
if name.is_empty() { | ||
return Err(LightningError::ValidationError( | ||
"activity name cannot be empty".to_string() |
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.
nit: let's make this a little more helpful?
"activity name cannot be an empty string, either remove name entirely or provide a string value"
let reserved_pattern = Regex::new(r"^Activity-\d+$").unwrap(); | ||
if reserved_pattern.is_match(name) { | ||
return Err(LightningError::ValidationError(format!( | ||
"'{}' uses a reserved name format. 'Activity-{{number}}' is reserved for system use.", |
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.
likewise - slightly more helpful error names, add a prompt to pick another name here
@@ -958,9 +964,11 @@ impl Simulation { | |||
let pe_sender = sender.clone(); | |||
tasks.spawn(async move { | |||
let source = executor.source_info.clone(); | |||
let name = executor.name.as_deref().unwrap(); |
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.
Having something be an Option
then unwrap
ing it later effectively means that it isn't actually an Option
?
If somebody were using sim-ln as a library, this would make their code panic if they didn't provide a name
which is seemingly optional based on our public API.
|
||
log::info!( | ||
"Starting activity producer for {}: {}.", | ||
"[{}] Starting activity producer for {}: {}.", |
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.
nit: log name elsewhere as well?
@@ -207,12 +207,13 @@ pub fn create_simulation( | |||
) | |||
} | |||
pub fn create_activity( | |||
name: Option<String>, |
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.
Unclear to me what value this commit is adding?
CI unhappy - see contribution guidelines! |
This PR adds an optional
name
field to activity descriptions that is used as a logging prefix. This makes it easier to relate logs to their corresponding activity, improving debugging and monitoring of simulations with multiple activities.Fixes #127
Changes
name
field toActivityParser
andActivityDefinition
structsname
field toDefinedPaymentActivity
structs and added allow deadcode due to compiler warnings; this may be an ineffective way.validate_activities()
to handle named activities and auto-generate names for unnamed onesExecutorKit
to include the activity nameImplementation Notes
DefinedActivity
(not for random activities)Test Vector
Tested with the following simulation file:
Resulting logs properly show activity names: