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 a287e45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmake/googletest.imp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
{ include: [ "@<gmock/.*>", private, "<gmock/gmock.h>", public ] },
{ include: [ "@<gtest/.*>", private, "<gtest/gtest.h>", public ] }
{ include: [ "@<gtest/.*>", private, "<gtest/gtest.h>", public ] },
{ include: [ "@<bits/this_thread_sleep.h>", private, "<thread>", public ]}
]
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 a287e45

Please sign in to comment.