Skip to content

Commit 4098a59

Browse files
committed
feat(push): allow any url prefix for push gateway
Fix: #718
1 parent 6492e82 commit 4098a59

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

push/include/prometheus/gateway.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class PROMETHEUS_CPP_PUSH_EXPORT Gateway {
3434
std::function<void(CURL*)> presetupCurl, const std::string& jobname,
3535
const Labels& labels = {});
3636

37+
Gateway(const std::string& url,
38+
std::function<void(CURL*)> presetupCurl, const std::string& jobname,
39+
const Labels& labels = {});
40+
3741
Gateway(const Gateway&) = delete;
3842
Gateway(Gateway&&) = delete;
3943
Gateway& operator=(const Gateway&) = delete;

push/src/gateway.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class SetupAdapter {
4242
std::string auth_;
4343
std::chrono::seconds timeout_;
4444
};
45+
46+
std::string concatenate(const std::string& host, const std::string& port) {
47+
std::stringstream ss;
48+
ss << host << ":" << port;
49+
return ss.str();
50+
}
4551
} // namespace
4652

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

5460
Gateway::Gateway(const std::string& host, const std::string& port,
61+
std::function<void(CURL*)> presetupCurl,
62+
const std::string& jobname, const Labels& labels)
63+
: Gateway(concatenate(host, port), presetupCurl, jobname, labels) {}
64+
65+
Gateway::Gateway(const std::string& url,
5566
std::function<void(CURL*)> presetupCurl,
5667
const std::string& jobname, const Labels& labels) {
5768
curlWrapper_ = detail::make_unique<detail::CurlWrapper>(presetupCurl);
5869

5970
std::stringstream jobUriStream;
60-
jobUriStream << host << ':' << port << "/metrics";
71+
jobUriStream << url;
72+
if (!url.empty() && url.back() != '/') {
73+
jobUriStream << "/";
74+
}
75+
jobUriStream << "metrics";
6176
detail::encodeLabel(jobUriStream, {"job", jobname});
6277
jobUri_ = jobUriStream.str();
6378

0 commit comments

Comments
 (0)