From 25236ac89b3cb1aed48ca512145243c1e9e495f2 Mon Sep 17 00:00:00 2001 From: Anthony Lin Date: Tue, 6 Feb 2018 02:45:32 +0000 Subject: [PATCH] Make Request Timeout Configurable As the size of the YAMLs increases, the amount of time needed to process the request increased as well. Hence there is a need to make 'timeout' configurable for the deckhand client. Change-Id: Iab91091cd8b9a900ad0daeac22e435d4e5c9c97d --- charts/shipyard/values.yaml | 5 ++ etc/shipyard/shipyard.conf.sample | 15 ++++++ shipyard_airflow/conf/config.py | 37 ++++++++++++-- .../control/configdocs/configdocs_helper.py | 12 ++--- .../control/configdocs/deckhand_client.py | 48 ++++++++++++------- tests/unit/control/test.conf | 5 ++ tools/resources/shipyard.conf | 5 ++ 7 files changed, 99 insertions(+), 28 deletions(-) diff --git a/charts/shipyard/values.yaml b/charts/shipyard/values.yaml index 96ea5586..a2287e28 100644 --- a/charts/shipyard/values.yaml +++ b/charts/shipyard/values.yaml @@ -334,6 +334,11 @@ conf: auth_section: keystone_authtoken auth_version: v3 memcache_security_strategy: ENCRYPT + requests_config: + deckhand_client_connect_timeout: 5 + deckhand_client_read_timeout: 300 + validation_connect_timeout: 5 + validation_read_timeout: 300 airflow: override: append: diff --git a/etc/shipyard/shipyard.conf.sample b/etc/shipyard/shipyard.conf.sample index 2d3097f5..1c18d2cc 100644 --- a/etc/shipyard/shipyard.conf.sample +++ b/etc/shipyard/shipyard.conf.sample @@ -277,6 +277,21 @@ #log_level = 10 +[requests_config] +# Deckhand client connect timeout (in seconds) +#deckhand_client_connect_timeout = 5 + +# Deckhand client timeout (in seconds) for GET, +# PUT, POST and DELETE request +#deckhand_client_read_timeout = 300 + +# UCP component validation connect timeout (in seconds) +#validation_connect_timeout = 5 + +# UCP component validation timeout (in seconds) +#validation_read_timeout = 300 + + [shipyard] # diff --git a/shipyard_airflow/conf/config.py b/shipyard_airflow/conf/config.py index 6509fa7e..76f8b43a 100644 --- a/shipyard_airflow/conf/config.py +++ b/shipyard_airflow/conf/config.py @@ -77,7 +77,7 @@ SECTIONS = [ help=( 'The service type for the service playing the role ' 'of Shipyard. The specified type is used to perform ' - 'the service lookup in the Keystone service catalog. ' + 'the service lookup in the Keystone service catalog.' ) ), ] @@ -92,7 +92,7 @@ SECTIONS = [ help=( 'The service type for the service playing the role ' 'of Deckhand. The specified type is used to perform ' - 'the service lookup in the Keystone service catalog. ' + 'the service lookup in the Keystone service catalog.' ) ), ] @@ -107,7 +107,7 @@ SECTIONS = [ help=( 'The service type for the service playing the role ' 'of Armada. The specified type is used to perform ' - 'the service lookup in the Keystone service catalog. ' + 'the service lookup in the Keystone service catalog.' ) ), ] @@ -122,7 +122,7 @@ SECTIONS = [ help=( 'The service type for the service playing the role ' 'of Drydock. The specified type is used to perform ' - 'the service lookup in the Keystone service catalog. ' + 'the service lookup in the Keystone service catalog.' ) ), cfg.IntOpt( @@ -182,6 +182,35 @@ SECTIONS = [ ), ] ), + ConfigSection( + name='requests_config', + title='Requests Configuration', + options=[ + cfg.IntOpt( + 'deckhand_client_connect_timeout', + default=5, + help='Deckhand client connect timeout (in seconds)' + ), + cfg.IntOpt( + 'deckhand_client_read_timeout', + default=300, + help=( + 'Deckhand client timeout (in seconds) for GET, ' + 'PUT, POST and DELETE request' + ) + ), + cfg.IntOpt( + 'validation_connect_timeout', + default=5, + help='UCP component validation connect timeout (in seconds)' + ), + cfg.IntOpt( + 'validation_read_timeout', + default=300, + help='UCP component validation timeout (in seconds)' + ), + ] + ), ] diff --git a/shipyard_airflow/control/configdocs/configdocs_helper.py b/shipyard_airflow/control/configdocs/configdocs_helper.py index 1771eb10..49ddca2d 100644 --- a/shipyard_airflow/control/configdocs/configdocs_helper.py +++ b/shipyard_airflow/control/configdocs/configdocs_helper.py @@ -437,13 +437,13 @@ class ConfigdocsHelper(object): 'content-type': 'application/json' } - # TODO: We will need to make timeout a configurable value as it - # will differ from site to site based on the size of the rendered - # document - # Note that 30 seconds is not sufficient to complete validations. - # Hence we are increaing the default timeout to 60 seconds. http_resp = requests.post( - url, headers=headers, data=design_reference, timeout=(5, 60)) + url, + headers=headers, + data=design_reference, + timeout=( + CONF.requests_config.validation_connect_timeout, + CONF.requests_config.validation_read_timeout)) # 400 response is "valid" failure to validate. > 400 is a problem. if http_resp.status_code > 400: http_resp.raise_for_status() diff --git a/shipyard_airflow/control/configdocs/deckhand_client.py b/shipyard_airflow/control/configdocs/deckhand_client.py index ef3513a3..bb56f006 100644 --- a/shipyard_airflow/control/configdocs/deckhand_client.py +++ b/shipyard_airflow/control/configdocs/deckhand_client.py @@ -362,11 +362,14 @@ class DeckhandClient(object): headers['content-type'] = 'application/x-yaml' DeckhandClient._log_request('PUT', url, params) - response = requests.put(url, - params=params, - headers=headers, - data=document_data, - timeout=(5, 30)) + response = requests.put( + url, + params=params, + headers=headers, + data=document_data, + timeout=( + CONF.requests_config.deckhand_client_connect_timeout, + CONF.requests_config.deckhand_client_read_timeout)) return response except RequestException as rex: LOG.error(rex) @@ -386,10 +389,13 @@ class DeckhandClient(object): } DeckhandClient._log_request('GET', url, params) - response = requests.get(url, - params=params, - headers=headers, - timeout=(5, 30)) + response = requests.get( + url, + params=params, + headers=headers, + timeout=( + CONF.requests_config.deckhand_client_connect_timeout, + CONF.requests_config.deckhand_client_read_timeout)) return response except RequestException as rex: LOG.error(rex) @@ -411,11 +417,14 @@ class DeckhandClient(object): headers['content-type'] = 'application/x-yaml' DeckhandClient._log_request('POST', url, params) - response = requests.post(url, - params=params, - headers=headers, - data=document_data, - timeout=(5, 30)) + response = requests.post( + url, + params=params, + headers=headers, + data=document_data, + timeout=( + CONF.requests_config.deckhand_client_connect_timeout, + CONF.requests_config.deckhand_client_read_timeout)) return response except RequestException as rex: LOG.error(rex) @@ -434,10 +443,13 @@ class DeckhandClient(object): } DeckhandClient._log_request('DELETE', url, params) - response = requests.delete(url, - params=params, - headers=headers, - timeout=(5, 30)) + response = requests.delete( + url, + params=params, + headers=headers, + timeout=( + CONF.requests_config.deckhand_client_connect_timeout, + CONF.requests_config.deckhand_client_read_timeout)) return response except RequestException as rex: LOG.error(rex) diff --git a/tests/unit/control/test.conf b/tests/unit/control/test.conf index f689a6f2..d9324273 100644 --- a/tests/unit/control/test.conf +++ b/tests/unit/control/test.conf @@ -35,6 +35,11 @@ project_domain_name = default project_name = service user_domain_name = default username = shipyard +[requests_config] +deckhand_client_connect_timeout=5 +deckhand_client_read_timeout=300 +validation_connect_timeout=5 +validation_read_timeout=300 [shipyard] service_type = shipyard diff --git a/tools/resources/shipyard.conf b/tools/resources/shipyard.conf index 779a2444..55bea973 100644 --- a/tools/resources/shipyard.conf +++ b/tools/resources/shipyard.conf @@ -37,5 +37,10 @@ project_domain_name = default project_name = service user_domain_name = default username = shipyard +[requests_config] +deckhand_client_connect_timeout=5 +deckhand_client_read_timeout=300 +validation_connect_timeout=5 +validation_read_timeout=300 [shipyard] service_type = shipyard