Delta exponential histogram never goes back to the maximum scale after a wide-range interval
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- observability
Hướng nghiên cứu
Bắt đầu trong opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py, tại _ExponentialBucketHistogramAggregation.collect và nhánh DELTA→DELTA của nó. Tái hiện vấn đề bằng script được cung cấp, sau đó kiểm tra các bài kiểm thử metrics để tìm vị trí phù hợp cho bài kiểm thử hồi quy. Công việc được xem là hoàn tất khi các khoảng delta một giá trị về sau quay lại thang đo tối đa mà không làm hỏng bộ kiểm thử metrics hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe your environment
OS: macOS (arm64)
Python version: 3.12
SDK version: main at 18d7e24 (opentelemetry-sdk installed from source)
API version: main at 18d7e24
What happened?
With DELTA temporality, the exponential histogram aggregation lowers its scale when an interval's values span a wide range, but never raises it again. Collection resets the buckets but not self._mapping (_ExponentialBucketHistogramAggregation.collect, the DELTA→DELTA branch in opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py). So every later delta point keeps the lowest scale any earlier interval needed, even when it holds a single value.
The SDK spec says: "When the histogram contains not more than one value in either of the positive or negative ranges, the implementation SHOULD use the maximum scale." A delta point covers only its own interval.
Steps to Reproduce
from opentelemetry.sdk.metrics import Histogram, MeterProvider
from opentelemetry.sdk.metrics.export import AggregationTemporality, InMemoryMetricReader
from opentelemetry.sdk.metrics.view import ExponentialBucketHistogramAggregation, View
reader = InMemoryMetricReader(preferred_temporality={Histogram: AggregationTemporality.DELTA})
provider = MeterProvider(
metric_readers=[reader],
views=[View(instrument_name="latency", aggregation=ExponentialBucketHistogramAggregation())],
)
hist = provider.get_meter("demo").create_histogram("latency")
def point():
return reader.get_metrics_data().resource_metrics[0].scope_metrics[0].metrics[0].data.data_points[0]
hist.record(1e-6)
hist.record(1e6)
print(point().scale) # interval 1: 2
for _ in range(3):
hist.record(5.0)
print(point().scale) # each later interval holds one value: 2, 2, 2
Expected Result
Each interval after the first holds a single value, so it's exported at the maximum scale (20 by default), with positive.offset = 2434718.
Actual Result
Every later interval is exported at scale 2, with positive.offset = 9. That bucket is (4.757, 5.657], a relative error of about 8.6% instead of about 3.3e-7 at scale 20. It never recovers.
In a worse case, one interval that records 1e-300 and 1e300 pins later intervals at scale -4. After that, four measurements of 10, 12, 15 and 20 ms all land in the single bucket (2^-16, 1].
Additional context
Adding self._mapping = self._new_mapping(self._max_scale) in that DELTA→DELTA branch, next to the bucket reset, restores the maximum scale for every interval. With it, the reproduction above prints 20 for each later interval, and the outlier case goes back to scale 7 with the four values in separate buckets. The 335 tests in opentelemetry-sdk/tests/metrics pass with and without the change, so none of them currently covers this.
For comparison, jmacd noted during review of #2964 that when the structure goes from 0 measurements to 1, "the scale is supposed to reset to the maximum scale again".
Found while auditing the metrics SDK with Claude Code. The outputs above come from running the script against main at 18d7e24.
Would you like to implement a fix?
Not at the moment. The one-line change above is what I tested, and anyone is welcome to pick it up.
- Ngôn ngữ chính
- Python
- Star
- 2.7k
- Fork
- 1k
- Merge trung bình
- 4 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 48
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của open-telemetry/opentelemetry-python
-
Prometheus exporter greedy regex in unit annotation stripping corrupts compound and ratio metric unitsCó thể đã có người làm @samarth-git27 đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
open-telemetry/opentelemetry-python#5766 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
open-telemetry/opentelemetry-python#5700 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Tests in test_metric_reader_storage.py assert on process-global mock state instead of on the storage under testCó thể đã có người làm @ocelotl đã nhận 42 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
open-telemetry/opentelemetry-python#5638 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
`SpanProcessor.on_end` exceptions escape cleanup and replace application exceptionsCó thể đã có người làm @somuai đã nhận 45 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
open-telemetry/opentelemetry-python#5624 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
PeriodicExportingMetricReader discards its shutdown timeoutCó thể đã có người làm @dwin-gharibi đã nhận 58 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
open-telemetry/opentelemetry-python#5574 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của open-telemetry/opentelemetry-python
Issue tương tự
-
idxmax/idxmin raise ValueError when a single partition is all-NACó thể đã có người làm @Jason10191019999 đã nhận hôm nay. Đang mởneeds triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Old versions of datamodelsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
[BUG]: Windows GUI package of v1.17.0-rc3 has no GTK DLLsCó thể đã có người làm @andrut-ds đã nhận hôm nay. Đang mởbug CI/CD Pactus-GUI Windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pactus-project/pactus#2428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DiskDataset.reshard() can hang with a zero or negative shard sizeCó thể đã có người làm @Programmer-Develops đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 19 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
GNS3/gns3-server#3017 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày