Skip to content

Commit

Permalink
feat(push): allow any url prefix for push gateway
Browse files Browse the repository at this point in the history
Fix: #718
  • Loading branch information
gjasny committed Nov 3, 2024
1 parent 6492e82 commit 5d2c502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions push/include/prometheus/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class PROMETHEUS_CPP_PUSH_EXPORT Gateway {
std::function<void(CURL*)> presetupCurl, const std::string& jobname,
const Labels& labels = {});

Gateway(const std::string& url,
std::function<void(CURL*)> presetupCurl, const std::string& jobname,
const Labels& labels = {});

Gateway(const Gateway&) = delete;
Gateway(Gateway&&) = delete;
Gateway& operator=(const Gateway&) = delete;
Expand Down
17 changes: 16 additions & 1 deletion push/src/gateway.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class SetupAdapter {
std::string auth_;
std::chrono::seconds timeout_;
};

std::string concatenate(const std::string& host, const std::string& port) {
std::stringstream ss;
ss << host << ":" << port;
return ss.str();
}
} // namespace

Gateway::Gateway(const std::string& host, const std::string& port,
Expand All @@ -52,12 +58,21 @@ Gateway::Gateway(const std::string& host, const std::string& port,
labels) {}

Gateway::Gateway(const std::string& host, const std::string& port,
std::function<void(CURL*)> presetupCurl,
const std::string& jobname, const Labels& labels)
: Gateway(concatenate(host, port), presetupCurl, jobname, labels) {}

Gateway::Gateway(const std::string& url,
std::function<void(CURL*)> presetupCurl,
const std::string& jobname, const Labels& labels) {
curlWrapper_ = detail::make_unique<detail::CurlWrapper>(presetupCurl);

std::stringstream jobUriStream;
jobUriStream << host << ':' << port << "/metrics";
jobUriStream << url;
if (!url.empty() && url.back() != '/') {
jobUriStream << "/";
}
jobUriStream << "metrics";
detail::encodeLabel(jobUriStream, {"job", jobname});
jobUri_ = jobUriStream.str();

Expand Down

0 comments on commit 5d2c502

Please sign in to comment.