Skip to content

Incomplete example implementation of naive reservoir sampling algorithm #2205

@dyladan

Description

@dyladan

In exemplar defaults the SimpleExemplarReservoir is defined as:

SimpleExemplarReservoir This Exemplar reservoir MAY take a configuration parameter for the size of the reservoir pool. The reservoir will accept measurements using an equivalent of the naive reservoir sampling algorithm

bucket = random_integer(0, num_measurements_seen)
if bucket < num_buckets then
 reservoir[bucket] = measurement
end

Reading the article, it seems like the implementation given here is incorrect or at least incomplete. For the first n elements where n is the size of the reservoir the exemplar should be offered to bucket n-1. Only after the reservoir is full should exemplars be sampled by generating the random number.

A more complete example might be:

bucket = num_measurements_seen if num_measurements_seen < reservoir.size else random_integer(0, num_measurements_seen)
if bucket < num_buckets then
	reservoir[bucket] = measurement
end

Metadata

Metadata

Assignees

Labels

area:sdkRelated to the SDKspec:metricsRelated to the specification/metrics directory

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions