Skip to content

Commit 2cc3dfe

Browse files
committed
[SDK] update SimpleFixedSizeExemplarReservoir default size for exponential histograms
1 parent 5423b91 commit 2cc3dfe

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Increment the:
1818
* [TEST] Shared otel-cpp libs linked to latest static protobuf and grpc
1919
[#3544](https://github.com/open-telemetry/opentelemetry-cpp/pull/3544)
2020

21+
* [SDK] Set SimpleFixedSizeExemplarReservoir default size for exponential
22+
histograms based on maximum bucket count
23+
2124
## [1.22 2025-07-11]
2225

2326
* [DOC] Udpate link to membership document

sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_utils.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
77

8+
# include <algorithm>
9+
810
# include "opentelemetry/common/macros.h"
911
# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
1012
# include "opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.h"
@@ -27,6 +29,22 @@ static inline MapAndResetCellType GetMapAndResetCellMethod(
2729
return &ReservoirCell::GetAndResetDouble;
2830
}
2931

32+
static inline size_t GetSimpleFixedReservoirDefaultSize(const AggregationType agg_type,
33+
const AggregationConfig *const agg_config)
34+
35+
{
36+
constexpr size_t kMaxBase2ExponentialHistogramReservoirSize = 20;
37+
38+
if (agg_type == AggregationType::kBase2ExponentialHistogram)
39+
{
40+
const auto *histogram_agg_config =
41+
static_cast<const Base2ExponentialHistogramAggregationConfig *>(agg_config);
42+
return std::min(kMaxBase2ExponentialHistogramReservoirSize, histogram_agg_config->max_buckets_);
43+
}
44+
45+
return SimpleFixedSizeExemplarReservoir::kDefaultSimpleReservoirSize;
46+
}
47+
3048
static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir(
3149
const AggregationType agg_type,
3250
const AggregationConfig *agg_config,
@@ -52,7 +70,7 @@ static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir(
5270
}
5371

5472
return nostd::shared_ptr<ExemplarReservoir>(new SimpleFixedSizeExemplarReservoir(
55-
SimpleFixedSizeExemplarReservoir::kDefaultSimpleReservoirSize,
73+
GetSimpleFixedReservoirDefaultSize(agg_type, agg_config),
5674
SimpleFixedSizeExemplarReservoir::GetSimpleFixedSizeCellSelector(),
5775
GetMapAndResetCellMethod(instrument_descriptor)));
5876
}

0 commit comments

Comments
 (0)