Merge pull request #58981 from azat/prom-handler

Fix timeout for prometheus exporter for HTTP/1.1 (due to keep-alive)
This commit is contained in:
Alexey Milovidov 2024-01-20 09:42:05 +01:00 committed by GitHub
commit 587295aca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -19,6 +19,13 @@ void WriteBufferFromHTTPServerResponse::startSendHeaders()
if (response.getChunkedTransferEncoding())
setChunked();
else if (response.getContentLength() == Poco::Net::HTTPMessage::UNKNOWN_CONTENT_LENGTH)
{
/// In case there is no Content-Length we cannot use keep-alive,
/// since there is no way to know when the server send all the
/// data, so "Connection: close" should be sent.
response.setKeepAlive(false);
}
if (add_cors_header)
response.set("Access-Control-Allow-Origin", "*");

View File

@ -23,6 +23,10 @@ void PrometheusRequestHandler::handleRequest(HTTPServerRequest & request, HTTPSe
const auto & config = server.config();
unsigned keep_alive_timeout = config.getUInt("keep_alive_timeout", DEFAULT_HTTP_KEEP_ALIVE_TIMEOUT);
/// In order to make keep-alive works.
if (request.getVersion() == HTTPServerRequest::HTTP_1_1)
response.setChunkedTransferEncoding(true);
setResponseDefaultHeaders(response, keep_alive_timeout);
response.setContentType("text/plain; version=0.0.4; charset=UTF-8");

View File

@ -40,6 +40,8 @@ def get_and_check_metrics(retries):
response = requests.get(
"http://{host}:{port}/metrics".format(host=node.ip_address, port=8001),
allow_redirects=False,
# less then default keep-alive timeout (10 seconds)
timeout=5,
)
if response.status_code != 200: