Skip to content

Commit 106246d

Browse files
committed
recommend using a time-weighted reservoir sampling algorithm for histograms
1 parent fbcd7a3 commit 106246d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ release.
2121

2222
- Changes of `MeterConfig.disabled` MUST be eventually visible.
2323
([#4645](https://github.com/open-telemetry/opentelemetry-specification/pull/4645))
24+
- `AlignedHistogramBucketExemplarReservoir` SHOULD use a time-weighted algorithm.
25+
([#4678](https://github.com/open-telemetry/opentelemetry-specification/pull/4678))
2426

2527
### Logs
2628

specification/metrics/sdk.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ algorithm](https://en.wikipedia.org/wiki/Reservoir_sampling) can be used:
12031203
if bucket < num_buckets then
12041204
reservoir[bucket] = measurement
12051205
end
1206+
num_measurements_seen += 1
12061207
```
12071208

12081209
Any stateful portion of sampling computation SHOULD be reset every collection
@@ -1217,15 +1218,23 @@ contention. Otherwise, a default size of `1` SHOULD be used.
12171218
#### AlignedHistogramBucketExemplarReservoir
12181219

12191220
This Exemplar reservoir MUST take a configuration parameter that is the
1220-
configuration of a Histogram. This implementation MUST keep the last seen
1221-
measurement that falls within a histogram bucket. The reservoir will accept
1221+
configuration of a Histogram. This implementation MUST store at most one
1222+
measurement that falls within a histogram bucket, and SHOULD use a
1223+
uniformly-weighted sampling algorithm based on the number of measurements the
1224+
bucket has seen so far to determine if the offered measurements should be
1225+
sampled. Alternatively, the implementation MAY instead keep the last seen
1226+
measurement that falls within a histogram bucket.
1227+
1228+
The reservoir will accept
12221229
measurements using the equivalent of the following naive algorithm:
12231230

12241231
```
12251232
bucket = find_histogram_bucket(measurement)
1226-
if bucket < num_buckets then
1233+
num_measurements_seen_bucket = num_measurements_seen[bucket]
1234+
if num_measurements_seen_bucket == 0 or random_integer(0, num_measurements_seen_bucket) == 0 then
12271235
reservoir[bucket] = measurement
12281236
end
1237+
num_measurements_seen[bucket] += 1
12291238
12301239
def find_histogram_bucket(measurement):
12311240
for boundary, idx in bucket_boundaries do

0 commit comments

Comments
 (0)