Skip to content

fix: discard power samples when the record time_diff is implausibly small - #443

Open
jaimeib wants to merge 1 commit into
hubblo-org:devfrom
IFCA-Advanced-Computing:fix/host-power-time-diff-guard-dev
Open

jaimeib wants to merge 1 commit into
hubblo-org:devfrom
IFCA-Advanced-Computing:fix/host-power-time-diff-guard-dev

Conversation

@jaimeib

@jaimeib jaimeib commented Sep 19, 2026

Copy link
Copy Markdown

Fixes #441

What

get_records_diff_power_microwatts() (for Topology, CPUSocket and Domain) now discards the sample (returns None) when the interval between the two records is below a 10 ms floor (MIN_RECORD_TIME_DIFF_S), instead of dividing by it.

Why

Record::timestamp comes from SystemTime (wall clock, not monotonic), so a clock adjustment between two records can make the interval tiny while the energy delta stays normal, which produces a bogus power value. See #441 for the details and the reproduction.

The prometheus exporter already debounces refreshes so records are at least ~2 s apart, so the floor does not affect normal operation. The stdout/json exporters accept a configurable, potentially sub-second step, which is why the floor is only 10 ms.

Test plan

  • cargo test --no-default-features --features "prometheus containers prometheuspush qemu json" --lib: all pass, including the two new unit tests (discards_power_sample_when_time_diff_too_small, computes_power_sample_when_time_diff_is_plausible).
  • repro_bogus_power_spike_on_real_hardware (#[ignore], needs root and real RAPL): a real ~2 s delta with the second timestamp corrupted to +0.5 ms gave ~54.7 kW before the change; the sample is now discarded.
  • cargo fmt --check

…mall

Record::timestamp comes from SystemTime (wall clock, not monotonic), so a
clock adjustment between two consecutive records can make their time diff
tiny. get_records_diff_power_microwatts() (Topology, CPUSocket and Domain)
then divides a normal energy delta by that interval and reports a bogus
power value.

This is reproducible deterministically on real RAPL hardware: a real ~2s
energy delta with the second record's timestamp corrupted to be 0.5ms after
the first one's yields ~54.7 kW on the unpatched code.

Discard the sample (return None) when time_diff is below a 10ms floor
instead of dividing by it. The prometheus exporter's own scrape debounce
already guarantees records are at least ~2s apart in normal operation, so
the floor has ample margin without rejecting legitimate fast sampling in
other exporters (stdout/json support a configurable, potentially
sub-second step).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant