Add "request_queue_size" option to REST API server (#2643)

Sets request queue size for TCP socket used by Patroni REST API. Once the queue is full, further requests get a "Connection denied" error. The default value is 5.
This commit is contained in:
Andrey
2023-04-12 10:25:14 +02:00
committed by GitHub
parent 6ffc73946a
commit 8a5d6ec74d
5 changed files with 16 additions and 8 deletions
+2
View File
@@ -187,6 +187,8 @@ REST API
- **PATRONI\_RESTAPI\_ALLOWLIST\_INCLUDE\_MEMBERS**: (optional): If set to ``true`` it allows accessing unsafe REST API endpoints from other cluster members registered in DCS (IP address or hostname is taken from the members ``api_url``). Be careful, it might happen that OS will use a different IP for outgoing connections.
- **PATRONI\_RESTAPI\_HTTP\_EXTRA\_HEADERS**: (optional) HTTP headers let the REST API server pass additional information with an HTTP response.
- **PATRONI\_RESTAPI\_HTTPS\_EXTRA\_HEADERS**: (optional) HTTPS headers let the REST API server pass additional information with an HTTP response when TLS is enabled. This will also pass additional information set in ``http_extra_headers``.
- **PATRONI\_RESTAPI\_REQUEST\_QUEUE\_SIZE**: (optional): Sets request queue size for TCP socket used by Patroni REST API. Once the queue is full, further requests get a "Connection denied" error. The default value is 5.
- ```
CTL
---
+1
View File
@@ -352,6 +352,7 @@ REST API
- **allowlist\_include\_members**: (optional): If set to ``true`` it allows accessing unsafe REST API endpoints from other cluster members registered in DCS (IP address or hostname is taken from the members ``api_url``). Be careful, it might happen that OS will use a different IP for outgoing connections.
- **http\_extra\_headers**: (optional): HTTP headers let the REST API server pass additional information with an HTTP response.
- **https\_extra\_headers**: (optional): HTTPS headers let the REST API server pass additional information with an HTTP response when TLS is enabled. This will also pass additional information set in ``http_extra_headers``.
- **request_queue_size**: (optional): Sets request queue size for TCP socket used by Patroni REST API. Once the queue is full, further requests get a "Connection denied" error. The default value is 5.
Here is an example of both **http_extra_headers** and **https_extra_headers**:
+1
View File
@@ -759,6 +759,7 @@ class RestApiServer(ThreadingMixIn, HTTPServer, Thread):
def __init__(self, patroni, config):
self.patroni = patroni
self.__listen = None
self.request_queue_size = int(config.get('request_queue_size', 5))
self.__ssl_options = None
self.__ssl_serial_number = None
self._received_new_cert = False
+10 -7
View File
@@ -378,7 +378,8 @@ class Config(object):
_set_section_values('restapi', ['listen', 'connect_address', 'certfile', 'keyfile', 'keyfile_password',
'cafile', 'ciphers', 'verify_client', 'http_extra_headers',
'https_extra_headers', 'allowlist', 'allowlist_include_members'])
'https_extra_headers', 'allowlist', 'allowlist_include_members',
'request_queue_size'])
_set_section_values('ctl', ['insecure', 'cacert', 'certfile', 'keyfile', 'keyfile_password'])
_set_section_values('postgresql', ['listen', 'connect_address', 'proxy_address',
'config_dir', 'data_dir', 'pgpass', 'bin_dir'])
@@ -393,12 +394,14 @@ class Config(object):
if value is not None:
ret[first][second] = value
for second in ('max_queue_size', 'file_size', 'file_num'):
value = ret.get('log', {}).pop(second, None)
if value:
value = parse_int(value)
if value is not None:
ret['log'][second] = value
for first, params in (('restapi', ('request_queue_size',)),
('log', ('max_queue_size', 'file_size', 'file_num'))):
for second in params:
value = ret.get(first, {}).pop(second, None)
if value:
value = parse_int(value)
if value is not None:
ret[first][second] = value
def _parse_list(value):
if not (value.strip().startswith('-') or '[' in value):
+2 -1
View File
@@ -703,7 +703,8 @@ schema = Schema({
"scope": str,
"restapi": {
"listen": validate_host_port_listen,
"connect_address": validate_connect_address
"connect_address": validate_connect_address,
Optional("request_queue_size"): lambda i: assert_(0 <= int(i) <= 4096)
},
Optional("bootstrap"): {
"dcs": {