From 9cee0fa70629345a250de012b50d4520c2cceff5 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/ (cherry picked from commit f572f31ecd8d76793f1f5864ab740f6f7f7e2b84) --- pdns/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/dnsdist-web.cc b/pdns/dnsdist-web.cc index 000579e4b6..225c06647f 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -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"; } #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 af2cbfee3e..823458447c 100644 --- a/pdns/recursordist/ws-recursor.cc +++ b/pdns/recursordist/ws-recursor.cc @@ -562,7 +562,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 9c82d7dafa..6f0e387ff6 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -2664,7 +2664,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