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 af84494 commit b738880
Show file tree
Hide file tree
Showing 2 changed files with 16 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 @@ -13,21 +13,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
8 changes: 8 additions & 0 deletions core/tests/summary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,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 b738880

Please sign in to comment.