Skip to content

Commit

Permalink
fix(pull): Properly lock Exposer functions
Browse files Browse the repository at this point in the history
Fixes: #529
  • Loading branch information
gjasny committed Nov 12, 2021
1 parent 556d4ed commit b6615c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pull/include/prometheus/exposer.h
Expand Up @@ -3,6 +3,7 @@
#include <cstddef>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <vector>

Expand Down Expand Up @@ -50,6 +51,7 @@ class PROMETHEUS_CPP_PULL_EXPORT Exposer {

std::unique_ptr<CivetServer> server_;
std::vector<std::unique_ptr<detail::Endpoint>> endpoints_;
std::mutex mutex_;
};

} // namespace prometheus
3 changes: 3 additions & 0 deletions pull/src/exposer.cc
Expand Up @@ -27,19 +27,22 @@ Exposer::~Exposer() = default;

void Exposer::RegisterCollectable(const std::weak_ptr<Collectable>& collectable,
const std::string& uri) {
std::lock_guard<std::mutex> lock{mutex_};
auto& endpoint = GetEndpointForUri(uri);
endpoint.RegisterCollectable(collectable);
}

void Exposer::RegisterAuth(
std::function<bool(const std::string&, const std::string&)> authCB,
const std::string& realm, const std::string& uri) {
std::lock_guard<std::mutex> lock{mutex_};
auto& endpoint = GetEndpointForUri(uri);
endpoint.RegisterAuth(std::move(authCB), realm);
}

void Exposer::RemoveCollectable(const std::weak_ptr<Collectable>& collectable,
const std::string& uri) {
std::lock_guard<std::mutex> lock{mutex_};
auto& endpoint = GetEndpointForUri(uri);
endpoint.RemoveCollectable(collectable);
}
Expand Down

0 comments on commit b6615c7

Please sign in to comment.