From 1d3fd3ac0bb25e66bfa6e0c2967e47ece629e4da Mon Sep 17 00:00:00 2001 From: Jan Tomsa Date: Mon, 1 Jul 2019 10:50:39 +0200 Subject: [PATCH] Enable debug logging for GET/OPTIONS API calls together with latency --- patroni/api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/patroni/api.py b/patroni/api.py index 0628303a..a0977201 100644 --- a/patroni/api.py +++ b/patroni/api.py @@ -86,6 +86,9 @@ class RestApiHandler(BaseHTTPRequestHandler): def do_GET(self, write_status_code_only=False): """Default method for processing all GET requests which can not be routed to other methods""" + time_start = time.time() + request_type = 'OPTIONS' if write_status_code_only else 'GET' + path = '/master' if self.path == '/' else self.path response = self.get_postgresql_status() @@ -124,6 +127,10 @@ class RestApiHandler(BaseHTTPRequestHandler): else: self._write_status_response(status_code, response) + time_end = time.time() + self.log_message('%s %s %s latency: %s ms', request_type, path, + status_code, (time_end - time_start) * 1000) + def do_OPTIONS(self): self.do_GET(write_status_code_only=True)