Skip to content

Commit

Permalink
Adjust Content-Type header for Prometheus endpoint to include version
Browse files Browse the repository at this point in the history
Prometheus v3 will, by default, be more strict about the content-types
returned from scrape endpoints. With the current value (just
`text/plain`), it would fail to scrape.

In this commit the value is changed from `text/plain` to `text/plain;
version=0.0.4`.

See also [1] and [2]
[1] https://prometheus.io/docs/instrumenting/exposition_formats/
[2] https://prometheus.io/docs/prometheus/3.0/migration/

(cherry picked from commit f572f31)
  • Loading branch information
Woutifier authored and omoerbeek committed Feb 24, 2025
1 parent 544037c commit fe9f4ff
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-web.cc
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ static void handlePrometheus(const YaHTTP::Request& req, YaHTTP::Response& resp)
output << "dnsdist_info{version=\"" << VERSION << "\"} " << "1" << "\n";

resp.body = output.str();
resp.headers["Content-Type"] = "text/plain";
resp.headers["Content-Type"] = "text/plain; version=0.0.4";
// clang-format on
}
#endif /* DISABLE_PROMETHEUS */
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/docs/http-api/prometheus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Prometheus Data Endpoint
HTTP/1.1 200 OK
Connection: close
Content-Length: 19203
Content-Type: text/plain
Content-Type: text/plain; version=0.0.4
Server: PowerDNS/0.0.16480.0.g876dd46192

# HELP pdns_recursor_all_outqueries Number of outgoing UDP queries since starting
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/ws-recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ static void prometheusMetrics(HttpRequest* /* req */, HttpResponse* resp)
<< "\n";

resp->body = output.str();
resp->headers["Content-Type"] = "text/plain";
resp->headers["Content-Type"] = "text/plain; version=0.0.4";
resp->status = 200;
}

Expand Down
2 changes: 1 addition & 1 deletion pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ static void prometheusMetrics(HttpRequest* /* req */, HttpResponse* resp)
<< "\n";

resp->body = output.str();
resp->headers["Content-Type"] = "text/plain";
resp->headers["Content-Type"] = "text/plain; version=0.0.4";
resp->status = 200;
}

Expand Down

0 comments on commit fe9f4ff

Please # to comment.