From f572f31ecd8d76793f1f5864ab740f6f7f7e2b84 Mon Sep 17 00:00:00 2001 From: Wouter de Vries Date: Tue, 21 Jan 2025 15:18:57 +0100 Subject: [PATCH] Adjust Content-Type header for Prometheus endpoint to include version 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/ --- pdns/dnsdistdist/dnsdist-web.cc | 2 +- pdns/recursordist/docs/http-api/prometheus.rst | 2 +- pdns/recursordist/ws-recursor.cc | 2 +- pdns/ws-auth.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-web.cc b/pdns/dnsdistdist/dnsdist-web.cc index 253c00d3bb..94db95c31a 100644 --- a/pdns/dnsdistdist/dnsdist-web.cc +++ b/pdns/dnsdistdist/dnsdist-web.cc @@ -918,7 +918,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 */ diff --git a/pdns/recursordist/docs/http-api/prometheus.rst b/pdns/recursordist/docs/http-api/prometheus.rst index 1fd9fd859e..41407c2d50 100644 --- a/pdns/recursordist/docs/http-api/prometheus.rst +++ b/pdns/recursordist/docs/http-api/prometheus.rst @@ -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 diff --git a/pdns/recursordist/ws-recursor.cc b/pdns/recursordist/ws-recursor.cc index 36569d29c2..8e548ecdc4 100644 --- a/pdns/recursordist/ws-recursor.cc +++ b/pdns/recursordist/ws-recursor.cc @@ -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; } diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index e0713e623c..7fb9c6fe38 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -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; } -- 2.47.2