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,23 @@ 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 ,
43+ histogram_agg_config->max_buckets_ );
44+ }
45+
46+ return SimpleFixedSizeExemplarReservoir::kDefaultSimpleReservoirSize ;
47+ }
48+
3049static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir (
3150 const AggregationType agg_type,
3251 const AggregationConfig *agg_config,
@@ -52,7 +71,7 @@ static inline nostd::shared_ptr<ExemplarReservoir> GetExemplarReservoir(
5271 }
5372
5473 return nostd::shared_ptr<ExemplarReservoir>(new SimpleFixedSizeExemplarReservoir (
55- SimpleFixedSizeExemplarReservoir:: kDefaultSimpleReservoirSize ,
74+ GetSimpleFixedReservoirDefaultSize (agg_type, agg_config) ,
5675 SimpleFixedSizeExemplarReservoir::GetSimpleFixedSizeCellSelector (),
5776 GetMapAndResetCellMethod (instrument_descriptor)));
5877}
0 commit comments