77
88#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
99
10+ # include < algorithm>
11+
1012# include " opentelemetry/common/macros.h"
1113# include " opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
1214# include " opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.h"
@@ -28,6 +30,23 @@ static inline MapAndResetCellType GetMapAndResetCellMethod(
2830 return &ReservoirCell::GetAndResetDouble;
2931}
3032
33+ static inline size_t GetSimpleFixedReservoirDefaultSize (const AggregationType agg_type,
34+ const AggregationConfig *const agg_config)
35+
36+ {
37+ constexpr size_t kMaxBase2ExponentialHistogramReservoirSize = 20 ;
38+
39+ if (agg_type == AggregationType::kBase2ExponentialHistogram )
40+ {
41+ const auto *histogram_agg_config =
42+ static_cast <const Base2ExponentialHistogramAggregationConfig *>(agg_config);
43+ return (std::min)(kMaxBase2ExponentialHistogramReservoirSize ,
44+ histogram_agg_config->max_buckets_ );
45+ }
46+
47+ return SimpleFixedSizeExemplarReservoir::kDefaultSimpleReservoirSize ;
48+ }
49+
3150static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir (
3251 const AggregationType agg_type,
3352 const AggregationConfig *agg_config,
@@ -53,7 +72,7 @@ static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir(
5372 }
5473
5574 return nostd::shared_ptr<ExemplarReservoir>(new SimpleFixedSizeExemplarReservoir (
56- SimpleFixedSizeExemplarReservoir:: kDefaultSimpleReservoirSize ,
75+ GetSimpleFixedReservoirDefaultSize (agg_type, agg_config) ,
5776 SimpleFixedSizeExemplarReservoir::GetSimpleFixedSizeCellSelector (),
5877 GetMapAndResetCellMethod (instrument_descriptor)));
5978}
0 commit comments