Xuanwo opened a new pull request, #8994:
URL: https://github.com/apache/opendal/pull/8994
# Which issue does this PR close?
Related Issues: None.
# Rationale for this change
Three bugs were identified in `opendal-layer-observe-metrics-common` and
`opendal-layer-metrics`:
1. **`MetricsWrapper::copy_from` panicked on unbounded `BytesRange` before
delegating:** `copy_from` called `range.size().expect(...)` prior to invoking
`self.inner.copy_from`, causing an unconditional panic on unbounded ranges
(such as `BytesRange::new(0, None)` or `BytesRange::from(..)`) instead of
letting the inner writer return its `Err`. In addition,
`BytesRange::suffix(n).size()` returns `Some(n)`, which could mis-account
copied bytes if an inner writer accepts a suffix range.
2. **Error paths dropped duration histograms:** The five unary async
operations (`create_dir`, `rename`, `restore`, `stat`, `presign`),
`MetricsReader::open`, and `MetricsHttpTransport::fetch` recorded duration
histograms on success and future cancellation, but omitted them when the inner
call returned `Err`. Slow failed operations and connection timeouts therefore
disappeared from duration histograms, inconsistent with `MetricsWrapper::drop`.
3. **`MetricsInterceptor` passed negative deltas to `Gauge::increment`:**
`OperationExecuting(-1)` and `HttpExecuting(-1)` invoked
`gauge!(...).increment(v as f64)` with `-1.0` instead of dispatching negative
values to `decrement(v.unsigned_abs() as f64)` per `metrics::GaugeFn`
semantics, which can corrupt or malform gauge updates on recorders/exporters
that expect non-negative magnitudes.
# What changes are included in this PR?
- `core/layers/observe-metrics-common/src/lib.rs`:
- Delegate `MetricsWrapper::copy_from` directly to `self.inner.copy_from`
without `.expect(...)`, and only add `range.size()` to `self.size` on `Ok(())`
when `!range.is_suffix()`.
- Record `OperationDurationSeconds` on `Err` in
`MetricsService::{create_dir, rename, restore, stat, presign}` and
`MetricsReader::open`, and record `HttpRequestDurationSeconds` on `Err` in
`MetricsHttpTransport::fetch`.
- Add unit tests covering unbounded/suffix/bounded `copy_from`, HTTP
connection error duration, all five unary async operation error durations, and
`MetricsReader::open` error duration.
- `core/layers/observe-metrics-common/Cargo.toml`:
- Enable `tokio`'s `time` feature in `[dev-dependencies]` for bounded
async test timeouts.
- `core/layers/metrics/src/lib.rs`:
- Dispatch `OperationExecuting(v)` and `HttpExecuting(v)` to
`gauge.increment(v as f64)` for `v >= 0` and `gauge.decrement(v.unsigned_abs()
as f64)` for `v < 0`.
- Add unit tests using `metrics::with_local_recorder` verifying
`increment` vs `decrement` dispatch (including `isize::MIN`).
# Are there any user-facing changes?
- `MetricsWrapper::copy_from` no longer panics on unbounded ranges and
returns the inner writer's error instead.
- Failed unary operations (`create_dir`, `rename`, `restore`, `stat`,
`presign`), failed `open` calls, and HTTP connection errors now emit duration
histogram observations consistently with successful and cancelled operations.
- `MetricsLayer` now invokes `metrics::GaugeFn::decrement` instead of
`increment` with a negative value when in-flight operation and HTTP gauges
decrease.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Implemented the three fixes and unit tests in
`opendal-layer-observe-metrics-common` and `opendal-layer-metrics`, verified
them against the metrics layer crates, and drafted the commit and PR
description. No public APIs were changed; `MetricsReader::open` error duration
recording was included alongside the five unary async operations for
consistency.
--
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]