mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
+1
-1
@@ -7,7 +7,7 @@ Patroni has a rich REST API, which is used by Patroni itself during the leader r
|
|||||||
|
|
||||||
Health check endpoints
|
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:
|
- 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:
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ listen stats
|
|||||||
|
|
||||||
listen master
|
listen master
|
||||||
bind *:5000
|
bind *:5000
|
||||||
option httpchk OPTIONS /master
|
option httpchk HEAD /master
|
||||||
http-check expect status 200
|
http-check expect status 200
|
||||||
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
|
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}}
|
{{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}}
|
{{end}}
|
||||||
listen replicas
|
listen replicas
|
||||||
bind *:5001
|
bind *:5001
|
||||||
option httpchk OPTIONS /replica
|
option httpchk HEAD /replica
|
||||||
http-check expect status 200
|
http-check expect status 200
|
||||||
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
|
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}}
|
{{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}}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class RestApiHandler(BaseHTTPRequestHandler):
|
|||||||
self.log_request(status_code)
|
self.log_request(status_code)
|
||||||
|
|
||||||
def _write_response(self, status_code, body, content_type='text/html', headers=None):
|
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)
|
self.send_response(status_code)
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
if content_type:
|
if content_type:
|
||||||
@@ -185,6 +186,9 @@ class RestApiHandler(BaseHTTPRequestHandler):
|
|||||||
def do_OPTIONS(self):
|
def do_OPTIONS(self):
|
||||||
self.do_GET(write_status_code_only=True)
|
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):
|
def do_GET_liveness(self):
|
||||||
self._write_status_code_only(200)
|
self._write_status_code_only(200)
|
||||||
|
|
||||||
|
|||||||
@@ -286,6 +286,9 @@ class TestRestApiHandler(unittest.TestCase):
|
|||||||
def test_do_OPTIONS(self):
|
def test_do_OPTIONS(self):
|
||||||
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'OPTIONS / HTTP/1.0'))
|
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):
|
def test_do_GET_liveness(self):
|
||||||
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /liveness HTTP/1.0'))
|
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /liveness HTTP/1.0'))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user