Skip to content
Snippets Groups Projects
Commit f9e8c30d authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature DBOARD3-220-configurable-socket-timeout.

parents c4203334 63aa728e
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,4 @@ coverage.xml ...@@ -7,3 +7,4 @@ coverage.xml
.coverage .coverage
.tox .tox
htmlcov htmlcov
dist
...@@ -16,7 +16,11 @@ CONFIG_SCHEMA = { ...@@ -16,7 +16,11 @@ CONFIG_SCHEMA = {
}, },
"required": ["hostname", "dbname", "username", "password"], "required": ["hostname", "dbname", "username", "password"],
"additionalProperties": False "additionalProperties": False
},
"timeout": {
"type": "number",
"maximum": 10, # sanity
"exclusiveMinimum": 0
} }
}, },
...@@ -37,7 +41,8 @@ CONFIG_SCHEMA = { ...@@ -37,7 +41,8 @@ CONFIG_SCHEMA = {
"type": "object", "type": "object",
"properties": { "properties": {
"hostname": {"type": "string"}, "hostname": {"type": "string"},
"port": {"type": "integer"} "port": {"type": "integer"},
"socket_timeout": {"$ref": "#/definitions/timeout"}
}, },
"required": ["hostname", "port"], "required": ["hostname", "port"],
"additionalProperties": False "additionalProperties": False
...@@ -47,7 +52,9 @@ CONFIG_SCHEMA = { ...@@ -47,7 +52,9 @@ CONFIG_SCHEMA = {
"properties": { "properties": {
"hostname": {"type": "string"}, "hostname": {"type": "string"},
"port": {"type": "integer"}, "port": {"type": "integer"},
"name": {"type": "string"} "name": {"type": "string"},
"redis_socket_timeout": {"$ref": "#/definitions/timeout"},
"sentinel_socket_timeout": {"$ref": "#/definitions/timeout"}
}, },
"required": ["hostname", "port", "name"], "required": ["hostname", "port", "name"],
"additionalProperties": False "additionalProperties": False
......
...@@ -7,6 +7,9 @@ import redis.sentinel ...@@ -7,6 +7,9 @@ import redis.sentinel
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
DEFAULT_REDIS_SENTINEL_TIMEOUT = 0.1
DEFAULT_SENTINEL_SOCKET_TIMEOUT = 0.1
DB_LATCH_SCHEMA = { DB_LATCH_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
...@@ -102,19 +105,23 @@ def _get_redis(config, dbid=None): ...@@ -102,19 +105,23 @@ def _get_redis(config, dbid=None):
dbid = min(config['redis-databases']) dbid = min(config['redis-databases'])
kwargs = { kwargs = {
'db': dbid, 'db': dbid
'socket_timeout': 0.1
} }
if 'sentinel' in config: if 'sentinel' in config:
kwargs['socket_timeout'] = config['sentinel'].get(
'sentinel_socket_timeout', DEFAULT_SENTINEL_SOCKET_TIMEOUT)
sentinel = redis.sentinel.Sentinel([( sentinel = redis.sentinel.Sentinel([(
config['sentinel']['hostname'], config['sentinel']['hostname'],
config['sentinel']['port'])], config['sentinel']['port'])],
**kwargs) **kwargs)
return sentinel.master_for( return sentinel.master_for(
config['sentinel']['name'], config['sentinel']['name'],
socket_timeout=0.1) socket_timeout=config['sentinel'].get(
'redis_socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT))
else: else:
kwargs['socket_timeout'] = config['redis'].get(
'socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT)
return redis.StrictRedis( return redis.StrictRedis(
host=config['redis']['hostname'], host=config['redis']['hostname'],
port=config['redis']['port'], port=config['redis']['port'],
......
...@@ -13,7 +13,7 @@ setup( ...@@ -13,7 +13,7 @@ setup(
'click', 'click',
'mysql-connector', 'mysql-connector',
'pysnmp', 'pysnmp',
'jsonschema', 'jsonschema==3.2.0',
'paramiko', 'paramiko',
'flask', 'flask',
'redis==3.2.1', 'redis==3.2.1',
......
...@@ -38,7 +38,8 @@ def data_config_filename(): ...@@ -38,7 +38,8 @@ def data_config_filename():
}, },
"redis": { "redis": {
"hostname": "xxxxxx", "hostname": "xxxxxx",
"port": 6379 "port": 6379,
"socket_timeout": 2.8
}, },
"redis-databases": [0, 7], "redis-databases": [0, 7],
"junosspace": { "junosspace": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment