From 913bd5369337fd380de3b1f90a0c0a7ae60fcd8b Mon Sep 17 00:00:00 2001 From: Leonardo Parente <23251360+leoparente@users.noreply.github.com> Date: Fri, 5 Jan 2024 18:25:24 -0400 Subject: [PATCH] fix use of deprecated method get_quantiles --- src/Metrics.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Metrics.h b/src/Metrics.h index d3c716f51..a11dc23a7 100644 --- a/src/Metrics.h +++ b/src/Metrics.h @@ -55,6 +55,12 @@ static inline uint64_t timespec_to_uint64(timespec &stamp) return stamp.tv_sec * 1000000000ULL + stamp.tv_nsec; } +template +static inline std::vector get_quantiles(const datasketches::kll_sketch &quatile) +{ + return {quatile.get_quantile(0.50), quatile.get_quantile(0.90), quatile.get_quantile(0.95), quatile.get_quantile(0.99)}; +} + class Metric { public: @@ -350,10 +356,9 @@ class Quantile final : public Metric if (other._quantile.is_empty()) { return; } - const double fractions[4]{0.50, 0.90, 0.95, 0.99}; - auto other_quantiles = other._quantile.get_quantiles(fractions, 4); + auto other_quantiles = get_quantiles(other._quantile); if (_quantiles_sum.empty()) { - _quantiles_sum = _quantile.get_quantiles(fractions, 4); + _quantiles_sum = get_quantiles(_quantile); } for (uint8_t i = 0; i < 4; i++) { _quantiles_sum[i] += other_quantiles[i]; @@ -392,8 +397,7 @@ class Quantile final : public Metric std::vector quantiles; if (_quantiles_sum.empty()) { - const double fractions[4]{0.50, 0.90, 0.95, 0.99}; - quantiles = _quantile.get_quantiles(fractions, 4); + quantiles = get_quantiles(_quantile); } else { quantiles = _quantiles_sum; } @@ -414,8 +418,7 @@ class Quantile final : public Metric std::vector quantiles; if (_quantiles_sum.empty()) { - const double fractions[4]{0.50, 0.90, 0.95, 0.99}; - quantiles = _quantile.get_quantiles(fractions, 4); + quantiles = get_quantiles(_quantile); } else { quantiles = _quantiles_sum; } @@ -448,9 +451,8 @@ class Quantile final : public Metric } std::vector quantiles; - const double fractions[4]{0.50, 0.90, 0.95, 0.99}; if (_quantiles_sum.empty()) { - quantiles = _quantile.get_quantiles(fractions, 4); + quantiles = get_quantiles(_quantile); } else { quantiles = _quantiles_sum; } @@ -461,6 +463,7 @@ class Quantile final : public Metric auto summary_data_point = metric->mutable_summary()->add_data_points(); summary_data_point->set_start_time_unix_nano(timespec_to_uint64(start)); summary_data_point->set_time_unix_nano(timespec_to_uint64(end)); + const double fractions[4]{0.50, 0.90, 0.95, 0.99}; for (auto it = quantiles.begin(); it != quantiles.end(); ++it) { auto quantile = summary_data_point->add_quantile_values(); quantile->set_quantile(fractions[it - quantiles.begin()]);