#2021 add HEAD support - minimal (#2360)

This commit is contained in:
Robert Cutajar
2022-08-19 13:27:08 +02:00
committed by GitHub
parent 2ee09d0a66
commit f92d975e7b
4 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ Patroni has a rich REST API, which is used by Patroni itself during the leader r
Health check endpoints
----------------------
For all health check ``GET`` requests Patroni returns a JSON document with the status of the node, along with the HTTP status code. If you don't want or don't need the JSON document, you might consider using the ``OPTIONS`` method instead of ``GET``.
For all health check ``GET`` requests Patroni returns a JSON document with the status of the node, along with the HTTP status code. If you don't want or don't need the JSON document, you might consider using the ``HEAD`` or ``OPTIONS`` method instead of ``GET``.
- The following requests to Patroni REST API will return HTTP status code **200** only when the Patroni node is running as the primary with leader lock:
+2 -2
View File
@@ -18,14 +18,14 @@ listen stats
listen master
bind *:5000
option httpchk OPTIONS /master
option httpchk HEAD /master
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
{{range gets "/members/*"}} server {{base .Key}} {{$data := json .Value}}{{base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}} maxconn 100 check port {{index (split (index (split $data.api_url "/") 2) ":") 1}}
{{end}}
listen replicas
bind *:5001
option httpchk OPTIONS /replica
option httpchk HEAD /replica
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
{{range gets "/members/*"}} server {{base .Key}} {{$data := json .Value}}{{base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}} maxconn 100 check port {{index (split (index (split $data.api_url "/") 2) ":") 1}}
+4
View File
@@ -38,6 +38,7 @@ class RestApiHandler(BaseHTTPRequestHandler):
self.log_request(status_code)
def _write_response(self, status_code, body, content_type='text/html', headers=None):
# TODO: try-catch ConnectionResetError: [Errno 104] Connection reset by peer and log it in DEBUG level
self.send_response(status_code)
headers = headers or {}
if content_type:
@@ -185,6 +186,9 @@ class RestApiHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
self.do_GET(write_status_code_only=True)
def do_HEAD(self):
self.do_GET(write_status_code_only=True)
def do_GET_liveness(self):
self._write_status_code_only(200)
+3
View File
@@ -286,6 +286,9 @@ class TestRestApiHandler(unittest.TestCase):
def test_do_OPTIONS(self):
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'OPTIONS / HTTP/1.0'))
def test_do_HEAD(self):
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'HEAD / HTTP/1.0'))
def test_do_GET_liveness(self):
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /liveness HTTP/1.0'))