Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix push gateway code #273

Merged
merged 3 commits into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions push/src/gateway.cc
@@ -1,6 +1,7 @@

#include "prometheus/gateway.h"

#include <memory>
#include <sstream>

#include "prometheus/client_metric.h"
Expand Down Expand Up @@ -139,7 +140,7 @@ int Gateway::push(HttpMethod method) {
auto uri = getUri(wcollectable);
auto status_code = performHttpRequest(method, uri, body);

if (status_code >= 400) {
if (status_code < 100 || status_code >= 400) {
return status_code;
}
}
Expand All @@ -162,11 +163,11 @@ std::future<int> Gateway::async_push(HttpMethod method) {
}

auto metrics = collectable->Collect();
auto body = serializer.Serialize(metrics);
auto body = std::make_shared<std::string>(serializer.Serialize(metrics));
auto uri = getUri(wcollectable);

futures.push_back(std::async(std::launch::async, [&] {
return performHttpRequest(method, uri, body);
futures.push_back(std::async(std::launch::async, [method, uri, body, this] {
return performHttpRequest(method, uri, *body);
}));
}

Expand All @@ -176,7 +177,7 @@ std::future<int> Gateway::async_push(HttpMethod method) {
for (auto& future : lfutures) {
auto status_code = future.get();

if (status_code >= 400) {
if (status_code < 100 || status_code >= 400) {
final_status_code = status_code;
}
}
Expand Down