Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_library(${PROJECT_NAME}::core ALIAS core)

target_compile_features(core
PUBLIC
cxx_std_11
cxx_std_17
)

target_link_libraries(core
Expand Down
6 changes: 2 additions & 4 deletions core/include/prometheus/detail/ckms_quantiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

// IWYU pragma: private, include "prometheus/summary.h"

namespace prometheus {
namespace detail {
namespace prometheus::detail {

class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles {
public:
Expand Down Expand Up @@ -53,5 +52,4 @@ class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles {
std::size_t buffer_count_;
};

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
16 changes: 0 additions & 16 deletions core/include/prometheus/detail/future_std.h

This file was deleted.

6 changes: 2 additions & 4 deletions core/include/prometheus/detail/time_window_quantiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

// IWYU pragma: private, include "prometheus/summary.h"

namespace prometheus {
namespace detail {
namespace prometheus::detail {

class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles {
using Clock = std::chrono::steady_clock;
Expand All @@ -33,5 +32,4 @@ class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles {
const Clock::duration rotation_interval_;
};

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
6 changes: 2 additions & 4 deletions core/include/prometheus/detail/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "prometheus/detail/core_export.h"
#include "prometheus/labels.h"

namespace prometheus {
namespace detail {
namespace prometheus::detail {

/// \brief Label hasher for use in STL containers.
struct PROMETHEUS_CPP_CORE_EXPORT LabelHasher {
Expand All @@ -18,5 +17,4 @@ struct PROMETHEUS_CPP_CORE_EXPORT LabelHasher {
std::size_t operator()(const Labels& labels) const;
};

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
3 changes: 1 addition & 2 deletions core/include/prometheus/family.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "prometheus/client_metric.h"
#include "prometheus/collectable.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/detail/utils.h"
#include "prometheus/labels.h"
#include "prometheus/metric_family.h"
Expand Down Expand Up @@ -111,7 +110,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
/// \throw std::invalid_argument on invalid label names.
template <typename... Args>
T& Add(const Labels& labels, Args&&... args) {
return Add(labels, detail::make_unique<T>(args...));
return Add(labels, std::make_unique<T>(args...));
}

/// \brief Remove the given dimensional data.
Expand Down
6 changes: 2 additions & 4 deletions core/src/detail/ckms_quantiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <limits>
#include <memory>

namespace prometheus {
namespace detail {
namespace prometheus::detail {

CKMSQuantiles::Quantile::Quantile(double quantile, double error)
: quantile(quantile),
Expand Down Expand Up @@ -149,5 +148,4 @@ void CKMSQuantiles::compress() {
}
}

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
8 changes: 2 additions & 6 deletions core/src/detail/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <cstddef>
#include <functional>

namespace prometheus {

namespace detail {
namespace prometheus::detail {

/// \brief Combine a hash value with nothing.
/// It's the boundary condition of this serial functions.
Expand Down Expand Up @@ -34,6 +32,4 @@ inline void hash_combine(std::size_t* seed, const T& value,
hash_combine(seed, args...);
}

} // namespace detail

} // namespace prometheus
} // namespace prometheus::detail
6 changes: 2 additions & 4 deletions core/src/detail/time_window_quantiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <memory>
#include <ratio>

namespace prometheus {
namespace detail {
namespace prometheus::detail {

TimeWindowQuantiles::TimeWindowQuantiles(
const std::vector<CKMSQuantiles::Quantile>& quantiles,
Expand Down Expand Up @@ -42,5 +41,4 @@ CKMSQuantiles& TimeWindowQuantiles::rotate() const {
return ckms_quantiles_[current_bucket_];
}

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
8 changes: 2 additions & 6 deletions core/src/detail/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#include "hash.h"

namespace prometheus {

namespace detail {
namespace prometheus::detail {

std::size_t LabelHasher::operator()(const Labels& labels) const {
std::size_t seed = 0;
Expand All @@ -19,6 +17,4 @@ std::size_t LabelHasher::operator()(const Labels& labels) const {
return seed;
}

} // namespace detail

} // namespace prometheus
} // namespace prometheus::detail
31 changes: 14 additions & 17 deletions core/src/family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Family<T>::Family(const std::string& name, const std::string& help,
if (!CheckMetricName(name_)) {
throw std::invalid_argument("Invalid metric name");
}
for (auto& label_pair : constant_labels_) {
auto& label_name = label_pair.first;
for (auto& [label_name, label_value] : constant_labels_) {
if (!CheckLabelName(label_name, T::metric_type)) {
throw std::invalid_argument("Invalid label name");
}
Expand All @@ -34,25 +33,23 @@ template <typename T>
T& Family<T>::Add(const Labels& labels, std::unique_ptr<T> object) {
std::lock_guard<std::mutex> lock{mutex_};

auto insert_result =
metrics_.insert(std::make_pair(labels, std::move(object)));
auto [it, inserted] = metrics_.emplace(labels, std::move(object));

if (insert_result.second) {
if (inserted) {
// insertion took place, retroactively check for unlikely issues
for (auto& label_pair : labels) {
const auto& label_name = label_pair.first;
for (auto& [label_name, label_value] : labels) {
if (!CheckLabelName(label_name, T::metric_type)) {
metrics_.erase(insert_result.first);
metrics_.erase(it);
throw std::invalid_argument("Invalid label name");
}
if (constant_labels_.count(label_name)) {
metrics_.erase(insert_result.first);
metrics_.erase(it);
throw std::invalid_argument("Duplicate label name");
}
}
}

auto& stored_object = insert_result.first->second;
auto& stored_object = it->second;
assert(stored_object);
return *stored_object;
}
Expand All @@ -61,11 +58,11 @@ template <typename T>
void Family<T>::Remove(T* metric) {
std::lock_guard<std::mutex> lock{mutex_};

for (auto it = metrics_.begin(); it != metrics_.end(); ++it) {
if (it->second.get() == metric) {
metrics_.erase(it);
break;
}
const auto it = std::find_if(
metrics_.begin(), metrics_.end(),
[metric](const auto& entry) { return entry.second.get() == metric; });
if (it != metrics_.end()) {
metrics_.erase(it);
}
}

Expand Down Expand Up @@ -98,8 +95,8 @@ std::vector<MetricFamily> Family<T>::Collect() const {
family.help = help_;
family.type = T::metric_type;
family.metric.reserve(metrics_.size());
for (const auto& m : metrics_) {
family.metric.push_back(std::move(CollectMetric(m.first, m.second.get())));
for (const auto& [metric_labels, metric] : metrics_) {
family.metric.push_back(CollectMetric(metric_labels, metric.get()));
}
return {family};
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <tuple>

#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/gauge.h"
#include "prometheus/histogram.h"
#include "prometheus/info.h"
Expand Down Expand Up @@ -135,7 +134,7 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
}
}

auto family = detail::make_unique<Family<T>>(name, help, labels);
auto family = std::make_unique<Family<T>>(name, help, labels);
auto& ref = *family;
families.push_back(std::move(family));
return ref;
Expand Down
9 changes: 4 additions & 5 deletions core/tests/family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "prometheus/client_metric.h"
#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/histogram.h"
#include "prometheus/labels.h"
#include "prometheus/summary.h"
Expand Down Expand Up @@ -82,14 +81,14 @@ TEST(FamilyTest, add_twice) {

TEST(FamilyTest, throw_on_invalid_metric_name) {
auto create_family_with_invalid_name = []() {
return detail::make_unique<Family<Counter>>("", "empty name", Labels{});
return std::make_unique<Family<Counter>>("", "empty name", Labels{});
};
EXPECT_ANY_THROW(create_family_with_invalid_name());
}

TEST(FamilyTest, throw_on_invalid_constant_label_name) {
auto create_family_with_invalid_labels = []() {
return detail::make_unique<Family<Counter>>(
return std::make_unique<Family<Counter>>(
"total_requests", "Counts all requests",
Labels{{"__inavlid", "counter1"}});
};
Expand Down Expand Up @@ -120,7 +119,7 @@ TEST(FamilyTest, query_family_if_metric_already_exists) {
TEST(FamilyTest, reject_histogram_with_constant_le_label) {
auto labels = Labels{{"le", "test"}};
EXPECT_ANY_THROW(
detail::make_unique<Family<Histogram>>("name", "help", labels));
std::make_unique<Family<Histogram>>("name", "help", labels));
}

TEST(FamilyTest, reject_histogram_with_le_label) {
Expand All @@ -132,7 +131,7 @@ TEST(FamilyTest, reject_histogram_with_le_label) {
TEST(FamilyTest, reject_summary_with_constant_quantile_label) {
auto labels = Labels{{"quantile", "test"}};
EXPECT_ANY_THROW(
detail::make_unique<Family<Summary>>("name", "help", labels));
std::make_unique<Family<Summary>>("name", "help", labels));
}

TEST(FamilyTest, reject_summary_with_quantile_label) {
Expand Down
4 changes: 1 addition & 3 deletions core/tests/serializer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <vector>

#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/family.h"
#include "prometheus/metric_family.h"
#include "prometheus/text_serializer.h"
Expand Down Expand Up @@ -40,8 +39,7 @@ TEST_F(SerializerTest, shouldSerializeLocaleIndependent) {

// ignore missing locale and skip test if setup fails
try {
localeWithCommaDecimalSeparator =
detail::make_unique<RAIILocale>("de_DE.UTF-8");
localeWithCommaDecimalSeparator = std::make_unique<RAIILocale>("de_DE.UTF-8");
} catch (std::runtime_error&) {
GTEST_SKIP();
}
Expand Down
2 changes: 1 addition & 1 deletion pull/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_library(${PROJECT_NAME}::pull ALIAS pull)

target_compile_features(pull
PUBLIC
cxx_std_11
cxx_std_17
)

target_link_libraries(pull
Expand Down
11 changes: 4 additions & 7 deletions pull/src/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

#include "basic_auth.h"
#include "handler.h"
#include "prometheus/detail/future_std.h"

namespace prometheus {
namespace detail {
namespace prometheus::detail {

Endpoint::Endpoint(CivetServer& server, std::string uri)
: server_(server),
uri_(std::move(uri)),
endpoint_registry_(std::make_shared<Registry>()),
metrics_handler_(
detail::make_unique<MetricsHandler>(*endpoint_registry_)) {
std::make_unique<MetricsHandler>(*endpoint_registry_)) {
RegisterCollectable(endpoint_registry_);
server_.addHandler(uri_, metrics_handler_.get());
}
Expand All @@ -37,7 +35,7 @@ void Endpoint::RegisterAuth(
// split creating, assigning, and storing to avoid a race-condition when
// being called the second time and the handler is replaced
auto new_handler =
detail::make_unique<BasicAuthHandler>(std::move(authCB), realm);
std::make_unique<BasicAuthHandler>(std::move(authCB), realm);
server_.addAuthHandler(uri_, new_handler.get());
auth_handler_ = std::move(new_handler);
}
Expand All @@ -49,5 +47,4 @@ void Endpoint::RemoveCollectable(

const std::string& Endpoint::GetURI() const { return uri_; }

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
6 changes: 2 additions & 4 deletions pull/src/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "prometheus/collectable.h"
#include "prometheus/registry.h"

namespace prometheus {
namespace detail {
namespace prometheus::detail {
class MetricsHandler;

class Endpoint {
Expand Down Expand Up @@ -40,5 +39,4 @@ class Endpoint {
std::unique_ptr<BasicAuthHandler> auth_handler_;
};

} // namespace detail
} // namespace prometheus
} // namespace prometheus::detail
3 changes: 1 addition & 2 deletions pull/src/exposer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "CivetServer.h"
#include "endpoint.h"
#include "prometheus/detail/future_std.h"

namespace prometheus {

Expand Down Expand Up @@ -67,7 +66,7 @@ detail::Endpoint& Exposer::GetEndpointForUri(const std::string& uri) {
return *it->get();
}

endpoints_.emplace_back(detail::make_unique<detail::Endpoint>(*server_, uri));
endpoints_.emplace_back(std::make_unique<detail::Endpoint>(*server_, uri));
return *endpoints_.back().get();
}

Expand Down
Loading
Loading