Skip to content
Open
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
5 changes: 4 additions & 1 deletion core/include/prometheus/detail/future_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
namespace prometheus {
namespace detail {

// Remove as soon C++14 can be used.
#if __cplusplus >= 201402L
using std::make_unique;
#else
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif

} // namespace detail
} // namespace prometheus
3 changes: 2 additions & 1 deletion pull/include/prometheus/exposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Endpoint;

class PROMETHEUS_CPP_PULL_EXPORT Exposer {
public:
explicit Exposer(std::shared_ptr<CivetServer> server);
explicit Exposer(const std::string& bind_address, std::size_t num_threads = 2,
const CivetCallbacks* callbacks = nullptr);
explicit Exposer(std::vector<std::string> options,
Expand Down Expand Up @@ -48,7 +49,7 @@ class PROMETHEUS_CPP_PULL_EXPORT Exposer {
private:
detail::Endpoint& GetEndpointForUri(const std::string& uri);

std::unique_ptr<CivetServer> server_;
std::shared_ptr<CivetServer> server_;
std::vector<std::unique_ptr<detail::Endpoint>> endpoints_;
std::mutex mutex_;
};
Expand Down
9 changes: 8 additions & 1 deletion pull/src/exposer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

namespace prometheus {

Exposer::Exposer(std::shared_ptr<CivetServer> server)
: server_(std::move(server)) {
if (!server_) {
throw std::invalid_argument("Invalid CivetServer: cannot be null");
}
}

Exposer::Exposer(const std::string& bind_address, const std::size_t num_threads,
const CivetCallbacks* callbacks)
: Exposer(
Expand All @@ -20,7 +27,7 @@ Exposer::Exposer(const std::string& bind_address, const std::size_t num_threads,

Exposer::Exposer(std::vector<std::string> options,
const CivetCallbacks* callbacks)
: server_(detail::make_unique<CivetServer>(std::move(options), callbacks)) {
: Exposer(std::make_shared<CivetServer>(std::move(options), callbacks)) {
}

Exposer::~Exposer() = default;
Expand Down
6 changes: 6 additions & 0 deletions pull/tests/unit/exposer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <gtest/gtest.h>

#include "CivetServer.h"

namespace prometheus {
namespace {

Expand All @@ -21,5 +23,9 @@ TEST(ExposerTest, listenOnDistinctPorts) {
EXPECT_NE(firstExposerPorts, secondExposerPorts);
}

TEST(ExposerTest, invalidExternalServer) {
EXPECT_THROW(Exposer(std::shared_ptr<CivetServer>(nullptr)), std::invalid_argument);
}

} // namespace
} // namespace prometheus