Xuanwo opened a new pull request, #8909: URL: https://github.com/apache/opendal/pull/8909
# Which issue does this PR close? None. # Rationale for this change `opendal-layer-observe-metrics-common` unconditionally computed `size as f64 / duration.as_secs_f64()` when observing `HttpRequestBytesRate`, `HttpResponseBytesRate`, `OperationBytesRate`, and `OperationEntriesRate`. When `start.elapsed()` returns `Duration::ZERO` (for example on coarse timers such as WASM `performance.now()`, Windows QPC ticks, VMs, or fast in-memory operations): - `size == 0` yields `f64::NAN` (`0.0 / 0.0`). - `size > 0` yields `f64::INFINITY` (`size / 0.0`). Observing a single `NaN` or `+Inf` into a histogram (such as in `opendal-layer-prometheus` or `opendal-layer-prometheus-client`) permanently corrupts that series' `_sum` to `NaN` or `+Inf` for the lifetime of the process. # What changes are included in this PR? - Add a private `compute_rate(count: u64, duration: Duration) -> Option<f64>` helper in `core/layers/observe-metrics-common/src/lib.rs` that returns `Some(rate)` only when `duration.as_secs_f64() > 0.0` and the computed rate is finite. - Guard all four rate observations (`HttpRequestBytesRate`, `HttpResponseBytesRate`, `OperationBytesRate`, `OperationEntriesRate`) with `compute_rate`, skipping the rate observation when the elapsed duration is zero or produces a non-finite value while continuing to record byte/entry counts and duration metrics. - Add deterministic regression tests covering `compute_rate`, `MetricsWrapper` (bytes and entries), and `MetricsStream` for both zero-duration (`size = 0` and `size > 0`) and positive-duration cases. # Are there any user-facing changes? Rate histograms (`operation_bytes_rate`, `operation_entries_rate`, `http_request_bytes_rate`, and `http_response_bytes_rate`) no longer emit `NaN` or `+Inf` observations when an operation or HTTP phase completes with a zero elapsed duration; those zero-duration rate samples are omitted instead. # Breaking changes # AI Usage Statement - **Harness:** Pi coding agent - **Model:** Gemini 4 Neon - **Effort:** high - **Role:** Verified the zero-duration division-by-zero rate calculation bug, implemented the finite-rate guard across all four rate observation sites in `opendal-layer-observe-metrics-common`, and added deterministic unit and regression tests. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
