diff options
author | Christian Svensson <blue@cmd.nu> | 2020-06-23 19:06:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 18:06:01 +0100 |
commit | 8bbe87f42d7736b3f11db0fcfb4557b214e0356d (patch) | |
tree | 40e1cbcdf20d26fca2d141c41e14c212aa958127 | |
parent | Sync ignored table names in synapse_port_db to current database schema (#7717) (diff) | |
download | synapse-8bbe87f42d7736b3f11db0fcfb4557b214e0356d.tar.xz |
Set Content-Length for Metrics requests (#7730)
HTTP requires the response to contain a Content-Length header unless chunked encoding is being used. Prometheus metrics endpoint did not set this, causing software such as prometheus-proxy to not be able to scrape synapse for metrics. Signed-off-by: Christian Svensson <blue@cmd.nu>
-rw-r--r-- | changelog.d/7730.bugfix | 1 | ||||
-rw-r--r-- | synapse/metrics/_exposition.py | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/changelog.d/7730.bugfix b/changelog.d/7730.bugfix new file mode 100644 index 0000000000..9da254b56c --- /dev/null +++ b/changelog.d/7730.bugfix @@ -0,0 +1 @@ +Fix missing `Content-Length` on HTTP responses from the metrics handler. diff --git a/synapse/metrics/_exposition.py b/synapse/metrics/_exposition.py index ab7f948ed4..4304c60d56 100644 --- a/synapse/metrics/_exposition.py +++ b/synapse/metrics/_exposition.py @@ -208,6 +208,7 @@ class MetricsHandler(BaseHTTPRequestHandler): raise self.send_response(200) self.send_header("Content-Type", CONTENT_TYPE_LATEST) + self.send_header("Content-Length", str(len(output))) self.end_headers() self.wfile.write(output) @@ -261,4 +262,6 @@ class MetricsResource(Resource): def render_GET(self, request): request.setHeader(b"Content-Type", CONTENT_TYPE_LATEST.encode("ascii")) - return generate_latest(self.registry) + response = generate_latest(self.registry) + request.setHeader(b"Content-Length", str(len(response))) + return response |