Skip to content

Commit

Permalink
Fix interior mutablility problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jupp0r committed Dec 19, 2019
1 parent aa04fb8 commit 5e64208
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions core/include/prometheus/detail/time_window_quantiles.h
Expand Up @@ -17,17 +17,17 @@ class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles {
TimeWindowQuantiles(const std::vector<CKMSQuantiles::Quantile>& quantiles,
Clock::duration max_age_seconds, int age_buckets);

double get(double q);
double get(double q) const;
void insert(double value);

private:
CKMSQuantiles& rotate();
CKMSQuantiles& rotate() const;

const std::vector<CKMSQuantiles::Quantile>& quantiles_;
std::vector<CKMSQuantiles> ckms_quantiles_;
std::size_t current_bucket_;
mutable std::vector<CKMSQuantiles> ckms_quantiles_;
mutable std::size_t current_bucket_;

Clock::time_point last_rotation_;
mutable Clock::time_point last_rotation_;
const Clock::duration rotation_interval_;
};

Expand Down
4 changes: 2 additions & 2 deletions core/include/prometheus/family.h
Expand Up @@ -143,9 +143,9 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
const std::string name_;
const std::string help_;
const std::map<std::string, std::string> constant_labels_;
std::mutex mutex_;
mutable std::mutex mutex_;

ClientMetric CollectMetric(std::size_t hash, T* metric);
ClientMetric CollectMetric(std::size_t hash, T* metric) const;
T& Add(const std::map<std::string, std::string>& labels,
std::unique_ptr<T> object);
};
Expand Down
2 changes: 1 addition & 1 deletion core/include/prometheus/registry.h
Expand Up @@ -92,7 +92,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Registry : public Collectable {
std::vector<std::unique_ptr<Family<Gauge>>> gauges_;
std::vector<std::unique_ptr<Family<Histogram>>> histograms_;
std::vector<std::unique_ptr<Family<Summary>>> summaries_;
std::mutex mutex_;
mutable std::mutex mutex_;
};

} // namespace prometheus
2 changes: 1 addition & 1 deletion core/include/prometheus/summary.h
Expand Up @@ -85,7 +85,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Summary {

private:
const Quantiles quantiles_;
std::mutex mutex_;
mutable std::mutex mutex_;
std::uint64_t count_;
double sum_;
detail::TimeWindowQuantiles quantile_values_;
Expand Down
4 changes: 2 additions & 2 deletions core/src/detail/time_window_quantiles.cc
Expand Up @@ -12,7 +12,7 @@ TimeWindowQuantiles::TimeWindowQuantiles(
last_rotation_(Clock::now()),
rotation_interval_(max_age / age_buckets) {}

double TimeWindowQuantiles::get(double q) {
double TimeWindowQuantiles::get(double q) const {
CKMSQuantiles& current_bucket = rotate();
return current_bucket.get(q);
}
Expand All @@ -24,7 +24,7 @@ void TimeWindowQuantiles::insert(double value) {
}
}

CKMSQuantiles& TimeWindowQuantiles::rotate() {
CKMSQuantiles& TimeWindowQuantiles::rotate() const {
auto delta = Clock::now() - last_rotation_;
while (delta > rotation_interval_) {
ckms_quantiles_[current_bucket_].reset();
Expand Down
2 changes: 1 addition & 1 deletion core/src/family.cc
Expand Up @@ -82,7 +82,7 @@ std::vector<MetricFamily> Family<T>::Collect() const {
}

template <typename T>
ClientMetric Family<T>::CollectMetric(std::size_t hash, T* metric) {
ClientMetric Family<T>::CollectMetric(std::size_t hash, T* metric) const {
auto collected = metric->Collect();
auto add_label =
[&collected](const std::pair<std::string, std::string>& label_pair) {
Expand Down

0 comments on commit 5e64208

Please sign in to comment.