Skip to content

Commit

Permalink
Make summary quantiles non-const
Browse files Browse the repository at this point in the history
This change removes an unnecessary API constraint that makes it
harder to dynamically construct quantile configurations for summaries.

Fixes #425
  • Loading branch information
Jupp Mueller committed May 14, 2021
1 parent 722d8d0 commit 00238ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/include/prometheus/detail/ckms_quantiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ namespace detail {
class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles {
public:
struct PROMETHEUS_CPP_CORE_EXPORT Quantile {
const double quantile;
const double error;
const double u;
const double v;

Quantile(double quantile, double error);

double quantile;
double error;
double u;
double v;
};

private:
struct Item {
/*const*/ double value;
double value;
int g;
/*const*/ int delta;
int delta;

explicit Item(double value, int lower_delta, int delta);
Item(double value, int lower_delta, int delta);
};

public:
Expand Down
9 changes: 9 additions & 0 deletions core/tests/summary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gtest/gtest.h>

#include <chrono>
#include <cmath>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -92,5 +93,13 @@ TEST(SummaryTest, max_age) {
test_value(std::numeric_limits<double>::quiet_NaN());
}

TEST(SummaryTest, construction_with_dynamic_quantile_vector) {
auto quantiles = Summary::Quantiles{{0.99, 0.001}};
quantiles.push_back({0.5, 0.05});

Summary summary{quantiles, std::chrono::seconds(1), 2};
summary.Observe(8.0);
}

} // namespace
} // namespace prometheus

0 comments on commit 00238ae

Please sign in to comment.