Skip to content

Commit 7fda385

Browse files
authored
fix: report bugs (#70)
Signed-off-by: Jeremy HERGAULT <jeremy.hergault@worldline.com>
1 parent 1c2c2be commit 7fda385

7 files changed

Lines changed: 26 additions & 23 deletions

File tree

cargo-prosa/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-prosa"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors.workspace = true
55
description = "ProSA utility to package and deliver a builded ProSA"
66
homepage.workspace = true
@@ -19,7 +19,7 @@ clap = "4"
1919
clap_complete = "4"
2020
serde.workspace = true
2121
toml.workspace = true
22-
toml_edit = { version = "0.23", features = ["serde"] }
22+
toml_edit = { version = "0.25", features = ["serde"] }
2323
serde_json = "1"
2424
tera = "1"
2525

cargo-prosa/src/main.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,22 @@ fn init_prosa(path: &str, context: &tera::Context) -> io::Result<()> {
186186
metadata_table.insert("generate-rpm", toml_edit::Item::Table(rpm_table));
187187
}
188188
} else {
189+
let mut metadata_table = toml_edit::Table::new();
190+
metadata_table.set_implicit(true);
191+
189192
if deb_pkg {
190193
let mut deb_table = toml_edit::Table::new();
191194
DebPkg::add_deb_pkg_metadata(&mut deb_table, name);
192-
193-
let mut metadata_table = toml_edit::Table::new();
194-
metadata_table.set_implicit(true);
195195
metadata_table.insert("deb", toml_edit::Item::Table(deb_table));
196-
197-
package_table.insert("metadata", toml_edit::Item::Table(metadata_table));
198196
}
197+
199198
if rpm_pkg {
200199
let mut rpm_table = toml_edit::Table::new();
201200
RpmPkg::add_rpm_pkg_metadata(&mut rpm_table, name);
202-
203-
let mut metadata_table = toml_edit::Table::new();
204-
metadata_table.set_implicit(true);
205201
metadata_table.insert("generate-rpm", toml_edit::Item::Table(rpm_table));
202+
}
206203

204+
if deb_pkg || rpm_pkg {
207205
package_table.insert("metadata", toml_edit::Item::Table(metadata_table));
208206
}
209207
}

prosa/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "prosa"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors.workspace = true
55
description = "ProSA core"
66
homepage.workspace = true
@@ -46,7 +46,7 @@ log.workspace = true
4646
tracing = "0.1"
4747
thiserror.workspace = true
4848
url = { version = "2", features = ["serde"] }
49-
rlimit = "0.10"
49+
rlimit = "0.11"
5050

5151
aquamarine.workspace = true
5252

prosa/src/core/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ where
118118
/// Can be call only by the main task to modify the service table
119119
pub fn remove_service(&mut self, name: &str, proc_id: u32, queue_id: u32) {
120120
if let Some((services, _)) = self.table.get_mut(name) {
121-
services.retain(|s| s.proc_id != proc_id && s.queue_id != queue_id);
121+
services.retain(|s| s.proc_id != proc_id || s.queue_id != queue_id);
122122
}
123123
}
124124

@@ -138,7 +138,7 @@ where
138138
pub fn remove_proc_queue_services(&mut self, proc_id: u32, queue_id: u32) {
139139
// This will let service with empty processors
140140
for (services, _) in self.table.values_mut() {
141-
services.retain(|s| s.proc_id != proc_id && s.queue_id != queue_id);
141+
services.retain(|s| s.proc_id != proc_id || s.queue_id != queue_id);
142142
}
143143
}
144144
}

prosa/src/event/queue/timed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! spmc {
2222
impl<T, const N: usize> $sender<T, N> {
2323
/// Method to check if timer are still on existing items
2424
fn timers_retain(&mut self, head: $p, id: $p) {
25-
let tail = id + 1 % self.queue.max_capacity();
25+
let tail = (id + 1) % self.queue.max_capacity();
2626
self.timers.retain(|t| prosa_utils::id_in_queue!(t, head, tail));
2727
}
2828

prosa/src/event/speed.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,18 @@ impl Speed {
116116
}
117117
}
118118

119-
/// Getter of the duration time it must wait since the last event to target the given TPS (Transaction Per Seconds) rate
120-
/// Consider an overhead to get a lasy duration to not overwhelmed a distant
121-
/// TPS should be superior to 0 otherwise it'll panic
122-
/// Duration equal 0 if the result is negative
119+
/// Returns the duration to wait since the last event to achieve the target TPS (Transactions Per Second).
120+
/// Includes a small overhead to ensure a conservative duration and avoid overwhelming a remote system.
121+
/// If TPS is not positive or finite, returns `Duration::MAX`.
122+
/// Returns `Duration::ZERO` if the calculated duration is negative.
123123
///
124124
/// <math><mfrac><mi>1000 × <msub><mi>N</mi><mn>t</mn></msub></mi><mi>TPS</mi></mfrac> + overhead − <msub><mi>Σ</mi><mn>t</mn></msub> = duration</math>
125125
pub fn get_duration_overhead(&self, tps: f64, overhead: Option<Duration>) -> Duration {
126+
// Guard against invalid TPS values to prevent division by zero or invalid computation
127+
if tps <= 0.0 || !tps.is_finite() {
128+
return Duration::MAX;
129+
}
130+
126131
let duration =
127132
Duration::from_millis(((1000 * self.event_speeds.len()) as f64 / tps) as u64);
128133
let sum_duration = self.accumulate_event_speeds();
@@ -135,9 +140,9 @@ impl Speed {
135140
}
136141
}
137142

138-
/// Getter of the duration time it must wait since the last event to target the given TPS (Transaction Per Seconds) rate
139-
/// TPS should be superior to 0 otherwise it'll panic
140-
/// Duration equal 0 if the result is negative
143+
/// Returns the duration to wait since the last event to achieve the target TPS (Transactions Per Second).
144+
/// If TPS is not positive or finite, returns `Duration::MAX`.
145+
/// Returns `Duration::ZERO` if the calculated duration is negative.
141146
///
142147
/// <math><mfrac><mi>1000 × <msub><mi>N</mi><mn>t</mn></msub></mi><mi>TPS</mi></mfrac> − <msub><mi>Σ</mi><mn>t</mn></msub> = duration</math>
143148
pub fn get_duration(&self, tps: f64) -> Duration {

prosa_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ openssl = { workspace = true, optional = true }
4646
# Config Observability
4747
log = { workspace = true, optional = true }
4848
tracing-core = { version = "0.1", optional = true }
49-
tracing-subscriber = { version = "0.3", features = ["std", "env-filter"], optional = true }
49+
tracing-subscriber = { version = ">=0.3.20, < 0.4", features = ["std", "env-filter"], optional = true }
5050
tracing-opentelemetry = { version = "0.32.1", optional = true }
5151
opentelemetry = { workspace = true, optional = true }
5252
opentelemetry_sdk = { workspace = true, optional = true }

0 commit comments

Comments
 (0)