Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6233e2f

Browse files
committed
Set Content-Length for Metrics requests
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>
1 parent 91e886d commit 6233e2f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

changelog.d/7730.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set `Content-Length` on HTTP responses from the metrics handler.

synapse/metrics/_exposition.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def do_GET(self):
208208
raise
209209
self.send_response(200)
210210
self.send_header("Content-Type", CONTENT_TYPE_LATEST)
211+
self.send_header("Content-Length", str(len(output)))
211212
self.end_headers()
212213
self.wfile.write(output)
213214

@@ -261,4 +262,6 @@ def __init__(self, registry=REGISTRY):
261262

262263
def render_GET(self, request):
263264
request.setHeader(b"Content-Type", CONTENT_TYPE_LATEST.encode("ascii"))
264-
return generate_latest(self.registry)
265+
response = generate_latest(self.registry)
266+
request.setHeader(b"Content-Length", str(len(response)))
267+
return response

0 commit comments

Comments
 (0)