diff --git a/cargo-prosa/Cargo.toml b/cargo-prosa/Cargo.toml index 2a8e8cc..3d962e9 100644 --- a/cargo-prosa/Cargo.toml +++ b/cargo-prosa/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-prosa" -version = "0.4.0" +version = "0.4.1" authors.workspace = true description = "ProSA utility to package and deliver a builded ProSA" homepage.workspace = true @@ -19,7 +19,7 @@ clap = "4" clap_complete = "4" serde.workspace = true toml.workspace = true -toml_edit = { version = "0.23", features = ["serde"] } +toml_edit = { version = "0.25", features = ["serde"] } serde_json = "1" tera = "1" diff --git a/cargo-prosa/src/main.rs b/cargo-prosa/src/main.rs index 354fc07..7dd91ca 100755 --- a/cargo-prosa/src/main.rs +++ b/cargo-prosa/src/main.rs @@ -186,24 +186,22 @@ fn init_prosa(path: &str, context: &tera::Context) -> io::Result<()> { metadata_table.insert("generate-rpm", toml_edit::Item::Table(rpm_table)); } } else { + let mut metadata_table = toml_edit::Table::new(); + metadata_table.set_implicit(true); + if deb_pkg { let mut deb_table = toml_edit::Table::new(); DebPkg::add_deb_pkg_metadata(&mut deb_table, name); - - let mut metadata_table = toml_edit::Table::new(); - metadata_table.set_implicit(true); metadata_table.insert("deb", toml_edit::Item::Table(deb_table)); - - package_table.insert("metadata", toml_edit::Item::Table(metadata_table)); } + if rpm_pkg { let mut rpm_table = toml_edit::Table::new(); RpmPkg::add_rpm_pkg_metadata(&mut rpm_table, name); - - let mut metadata_table = toml_edit::Table::new(); - metadata_table.set_implicit(true); metadata_table.insert("generate-rpm", toml_edit::Item::Table(rpm_table)); + } + if deb_pkg || rpm_pkg { package_table.insert("metadata", toml_edit::Item::Table(metadata_table)); } } diff --git a/prosa/Cargo.toml b/prosa/Cargo.toml index 944230d..69a3ac0 100644 --- a/prosa/Cargo.toml +++ b/prosa/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prosa" -version = "0.4.1" +version = "0.4.2" authors.workspace = true description = "ProSA core" homepage.workspace = true @@ -46,7 +46,7 @@ log.workspace = true tracing = "0.1" thiserror.workspace = true url = { version = "2", features = ["serde"] } -rlimit = "0.10" +rlimit = "0.11" aquamarine.workspace = true diff --git a/prosa/src/core/service.rs b/prosa/src/core/service.rs index 15a7e61..d52cef6 100644 --- a/prosa/src/core/service.rs +++ b/prosa/src/core/service.rs @@ -118,7 +118,7 @@ where /// Can be call only by the main task to modify the service table pub fn remove_service(&mut self, name: &str, proc_id: u32, queue_id: u32) { if let Some((services, _)) = self.table.get_mut(name) { - services.retain(|s| s.proc_id != proc_id && s.queue_id != queue_id); + services.retain(|s| s.proc_id != proc_id || s.queue_id != queue_id); } } @@ -138,7 +138,7 @@ where pub fn remove_proc_queue_services(&mut self, proc_id: u32, queue_id: u32) { // This will let service with empty processors for (services, _) in self.table.values_mut() { - services.retain(|s| s.proc_id != proc_id && s.queue_id != queue_id); + services.retain(|s| s.proc_id != proc_id || s.queue_id != queue_id); } } } diff --git a/prosa/src/event/queue/timed.rs b/prosa/src/event/queue/timed.rs index 83324c8..3867cb6 100644 --- a/prosa/src/event/queue/timed.rs +++ b/prosa/src/event/queue/timed.rs @@ -22,7 +22,7 @@ macro_rules! spmc { impl $sender { /// Method to check if timer are still on existing items fn timers_retain(&mut self, head: $p, id: $p) { - let tail = id + 1 % self.queue.max_capacity(); + let tail = (id + 1) % self.queue.max_capacity(); self.timers.retain(|t| prosa_utils::id_in_queue!(t, head, tail)); } diff --git a/prosa/src/event/speed.rs b/prosa/src/event/speed.rs index 673cdf2..a9b776f 100644 --- a/prosa/src/event/speed.rs +++ b/prosa/src/event/speed.rs @@ -116,13 +116,18 @@ impl Speed { } } - /// Getter of the duration time it must wait since the last event to target the given TPS (Transaction Per Seconds) rate - /// Consider an overhead to get a lasy duration to not overwhelmed a distant - /// TPS should be superior to 0 otherwise it'll panic - /// Duration equal 0 if the result is negative + /// Returns the duration to wait since the last event to achieve the target TPS (Transactions Per Second). + /// Includes a small overhead to ensure a conservative duration and avoid overwhelming a remote system. + /// If TPS is not positive or finite, returns `Duration::MAX`. + /// Returns `Duration::ZERO` if the calculated duration is negative. /// /// 1000 × NtTPS + overhead − Σt = duration pub fn get_duration_overhead(&self, tps: f64, overhead: Option) -> Duration { + // Guard against invalid TPS values to prevent division by zero or invalid computation + if tps <= 0.0 || !tps.is_finite() { + return Duration::MAX; + } + let duration = Duration::from_millis(((1000 * self.event_speeds.len()) as f64 / tps) as u64); let sum_duration = self.accumulate_event_speeds(); @@ -135,9 +140,9 @@ impl Speed { } } - /// Getter of the duration time it must wait since the last event to target the given TPS (Transaction Per Seconds) rate - /// TPS should be superior to 0 otherwise it'll panic - /// Duration equal 0 if the result is negative + /// Returns the duration to wait since the last event to achieve the target TPS (Transactions Per Second). + /// If TPS is not positive or finite, returns `Duration::MAX`. + /// Returns `Duration::ZERO` if the calculated duration is negative. /// /// 1000 × NtTPSΣt = duration pub fn get_duration(&self, tps: f64) -> Duration { diff --git a/prosa_utils/Cargo.toml b/prosa_utils/Cargo.toml index 374a544..b532448 100644 --- a/prosa_utils/Cargo.toml +++ b/prosa_utils/Cargo.toml @@ -46,7 +46,7 @@ openssl = { workspace = true, optional = true } # Config Observability log = { workspace = true, optional = true } tracing-core = { version = "0.1", optional = true } -tracing-subscriber = { version = "0.3", features = ["std", "env-filter"], optional = true } +tracing-subscriber = { version = ">=0.3.20, < 0.4", features = ["std", "env-filter"], optional = true } tracing-opentelemetry = { version = "0.32.1", optional = true } opentelemetry = { workspace = true, optional = true } opentelemetry_sdk = { workspace = true, optional = true }