From 7d1a5cad03e7fbc067176e75b84b972f9d3b6820 Mon Sep 17 00:00:00 2001 From: Jan Tomsa Date: Mon, 1 Jul 2019 11:02:26 +0200 Subject: [PATCH] Allow to specify consul consistency mode (#1094) Allow users to specify consul consistency mode. This option will be passed to the Consul client as kwargs https://github.com/zalando/patroni/blob/master/patroni/dcs/consul.py#L213. The library will then enforce the selected consistency level https://python-consul.readthedocs.io/en/latest/#consul More about consistency mode here https://www.consul.io/api/features/consistency.html --- docs/ENVIRONMENT.rst | 1 + docs/SETTINGS.rst | 1 + patroni/config.py | 6 +++--- patroni/dcs/consul.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst index 78c42089..52cdd759 100644 --- a/docs/ENVIRONMENT.rst +++ b/docs/ENVIRONMENT.rst @@ -41,6 +41,7 @@ Consul - **PATRONI\_CONSUL\_CERT**: (optional) File with the client certificate - **PATRONI\_CONSUL\_KEY**: (optional) File with the client key. Can be empty if the key is part of certificate. - **PATRONI\_CONSUL\_DC**: (optional) Datacenter to communicate with. By default the datacenter of the host is used. +- **PATRONI\_CONSUL\_CONSISTENCY**: (optional) Select consul consistency mode. Possible values are ``default``, ``consistent``, or ``stale`` (more details in `consul API reference `__) - **PATRONI\_CONSUL\_CHECKS**: (optional) list of Consul health checks used for the session. If not specified Consul will use "serfHealth" in additional to the TTL based check created by Patroni. Additional checks, in particular the "serfHealth", may cause the leader lock to expire faster than in `ttl` seconds when the leader instance becomes unavailable. - **PATRONI\_CONSUL\_REGISTER\_SERVICE**: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, replica or standby-leader depending on the node's role. Defaults to **false** - **PATRONI\_CONSUL\_SERVICE\_CHECK\_INTERVAL**: (optional) how often to perform health check against registered url diff --git a/docs/SETTINGS.rst b/docs/SETTINGS.rst index c9fe9b1f..e9fa5bcb 100644 --- a/docs/SETTINGS.rst +++ b/docs/SETTINGS.rst @@ -88,6 +88,7 @@ Most of the parameters are optional, but you have to specify one of the **host** - **cert**: (optional) file with the client certificate - **key**: (optional) file with the client key. Can be empty if the key is part of **cert**. - **dc**: (optional) Datacenter to communicate with. By default the datacenter of the host is used. +- **consistency**: (optional) Select consul consistency mode. Possible values are ``default``, ``consistent``, or ``stale`` (more details in `consul API reference `__) - **checks**: (optional) list of Consul health checks used for the session. If not specified Consul will use "serfHealth" in additional to the TTL based check created by Patroni. Additional checks, in particular the "serfHealth", may cause the leader lock to expire faster than in `ttl` seconds when the leader instance becomes unavailable - **register\_service**: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, replica or standby-leader depending on the node's role. Defaults to **false** - **service\_check\_interval**: (optional) how often to perform health check against registered url diff --git a/patroni/config.py b/patroni/config.py index c83cd28c..b73a6fea 100644 --- a/patroni/config.py +++ b/patroni/config.py @@ -285,9 +285,9 @@ class Config(object): # PATRONI_(ETCD|CONSUL|ZOOKEEPER|EXHIBITOR|...)_(HOSTS?|PORT|..) name, suffix = (param[8:].split('_', 1) + [''])[:2] if suffix in ('HOST', 'HOSTS', 'PORT', 'USE_PROXIES', 'PROTOCOL', 'SRV', 'URL', 'PROXY', - 'CACERT', 'CERT', 'KEY', 'VERIFY', 'TOKEN', 'CHECKS', 'DC', 'REGISTER_SERVICE', - 'SERVICE_CHECK_INTERVAL', 'NAMESPACE', 'CONTEXT', 'USE_ENDPOINTS', 'SCOPE_LABEL', - 'ROLE_LABEL', 'POD_IP', 'PORTS', 'LABELS') and name: + 'CACERT', 'CERT', 'KEY', 'VERIFY', 'TOKEN', 'CHECKS', 'DC', 'CONSISTENCY', + 'REGISTER_SERVICE', 'SERVICE_CHECK_INTERVAL', 'NAMESPACE', 'CONTEXT', + 'USE_ENDPOINTS', 'SCOPE_LABEL', 'ROLE_LABEL', 'POD_IP', 'PORTS', 'LABELS') and name: value = os.environ.pop(param) if suffix == 'PORT': value = value and parse_int(value) diff --git a/patroni/dcs/consul.py b/patroni/dcs/consul.py index 5d610f15..10d71655 100644 --- a/patroni/dcs/consul.py +++ b/patroni/dcs/consul.py @@ -201,7 +201,7 @@ class Consul(AbstractDCS): if config.get('key') and config.get('cert'): config['cert'] = (config['cert'], config['key']) - config_keys = ('host', 'port', 'token', 'scheme', 'cert', 'ca_cert', 'dc') + config_keys = ('host', 'port', 'token', 'scheme', 'cert', 'ca_cert', 'dc', 'consistency') kwargs = {p: config.get(p) for p in config_keys if config.get(p)} verify = config.get('verify')