hive-c0re/swarm-*: drop clippy allows and dedupe unix_now + KV open_or_create
No behaviour change. Casts replaced by try_from / Duration math; schedules.rs reuses agent_renewal::unix_now; the five swarm-queue-client KV open-or-create copies share one private kv::open_or_create.
This commit is contained in:
parent
f53ccb2740
commit
b874d21cda
11 changed files with 74 additions and 133 deletions
|
|
@ -222,16 +222,8 @@ pub async fn gather() -> Vec<ContainerResource> {
|
|||
let t0: Vec<Option<u64>> = candidates.iter().map(|(_, d)| read_usage_usec(d)).collect();
|
||||
sleep(CPU_SAMPLE).await;
|
||||
|
||||
#[allow(
|
||||
clippy::cast_precision_loss,
|
||||
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
|
||||
)]
|
||||
let nproc = host_nproc() as f64;
|
||||
#[allow(
|
||||
clippy::cast_precision_loss,
|
||||
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
|
||||
)]
|
||||
let interval_usec = CPU_SAMPLE.as_micros() as f64;
|
||||
let nproc = f64::from(u32::try_from(host_nproc()).unwrap_or(u32::MAX));
|
||||
let interval_secs = CPU_SAMPLE.as_secs_f64();
|
||||
|
||||
// Snapshot the slow disk cache once (cheap clone of a small map) so
|
||||
// the per-agent loop below is a plain map lookup — no `du` on this
|
||||
|
|
@ -246,12 +238,8 @@ pub async fn gather() -> Vec<ContainerResource> {
|
|||
let usage_now = read_usage_usec(dir);
|
||||
let cpu_pct = match (t0[i], usage_now) {
|
||||
(Some(a), Some(b)) => {
|
||||
#[allow(
|
||||
clippy::cast_precision_loss,
|
||||
reason = "CPU-utilisation math; the operands (core count, microsecond sample interval, cgroup time delta) stay well under f64's 2^53 exact-integer range, so no precision is lost"
|
||||
)]
|
||||
let delta = b.saturating_sub(a) as f64;
|
||||
(delta / (interval_usec * nproc)) * 100.0
|
||||
let delta_secs = Duration::from_micros(b.saturating_sub(a)).as_secs_f64();
|
||||
(delta_secs / (interval_secs * nproc)) * 100.0
|
||||
}
|
||||
_ => 0.0,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -236,13 +236,8 @@ struct AgentAgg {
|
|||
skills: HashMap<String, u64>,
|
||||
}
|
||||
|
||||
#[allow(
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
reason = "v.max(0) clamps to a non-negative value first, so the i64->u64 cast is exact: no sign loss, and no truncation since u64 covers all non-negative i64"
|
||||
)]
|
||||
fn u64_from_i64(v: i64) -> u64 {
|
||||
v.max(0) as u64
|
||||
u64::try_from(v).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Aggregate one agent's turn-stats over `[from, now]`. Errors bubble
|
||||
|
|
|
|||
|
|
@ -154,8 +154,7 @@ fn register_instruments(provider: &SdkMeterProvider, snapshot: Arc<Mutex<Vec<Con
|
|||
if let Ok(g) = snap.lock() {
|
||||
for c in g.iter() {
|
||||
if let Some(usec) = c.cpu_time_usec {
|
||||
#[allow(clippy::cast_precision_loss)]
|
||||
obs.observe(usec as f64 / 1_000_000.0, &attrs(c));
|
||||
obs.observe(Duration::from_micros(usec).as_secs_f64(), &attrs(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue