Skip to content

Commit

Permalink
fix use of deprecated method get_quantiles
Browse files Browse the repository at this point in the history
  • Loading branch information
leoparente committed Jan 24, 2024
1 parent 16c0316 commit 913bd53
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ static inline uint64_t timespec_to_uint64(timespec &stamp)
return stamp.tv_sec * 1000000000ULL + stamp.tv_nsec;
}

template <typename T>
static inline std::vector<T> get_quantiles(const datasketches::kll_sketch<T> &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:
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -392,8 +397,7 @@ class Quantile final : public Metric

std::vector<T> 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;
}
Expand All @@ -414,8 +418,7 @@ class Quantile final : public Metric

std::vector<T> 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;
}
Expand Down Expand Up @@ -448,9 +451,8 @@ class Quantile final : public Metric
}

std::vector<T> 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;
}
Expand All @@ -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()]);
Expand Down

0 comments on commit 913bd53

Please sign in to comment.