Add configurable timeout for Drydock client

Adds configs to allow a drydock client to use a non-default read
timeout.

Change-Id: Id4e4a235861165bfb5eb571684c8ce0be4181543
This commit is contained in:
Bryan Strassner 2018-11-13 13:10:07 -06:00
parent 077bf7653a
commit 84d99967bc
7 changed files with 59 additions and 7 deletions

View File

@ -420,6 +420,8 @@ conf:
validation_read_timeout: 300
notes_connect_timeout: 5
notes_read_timeout: 10
drydock_client_connect_timeout: 20
drydock_client_read_timeout: 300
airflow:
worker_endpoint_scheme: 'http'
worker_port: 8793

View File

@ -385,6 +385,14 @@
# Read timeout for a note source URL (in seconds) (integer value)
#notes_read_timeout = 10
# Connect timeout used for connecting to Drydock using the Drydock client (in
# seconds) (integer value)
#drydock_client_connect_timeout = 20
# Read timeout used for responses from Drydock using the Drydock client (in
# seconds) (integer value)
#drydock_client_read_timeout = 300
[shipyard]

View File

@ -385,6 +385,14 @@
# Read timeout for a note source URL (in seconds) (integer value)
#notes_read_timeout = 10
# Connect timeout used for connecting to Drydock using the Drydock client (in
# seconds) (integer value)
#drydock_client_connect_timeout = 20
# Read timeout used for responses from Drydock using the Drydock client (in
# seconds) (integer value)
#drydock_client_read_timeout = 300
[shipyard]

View File

@ -245,6 +245,18 @@ SECTIONS = [
default=10,
help='Read timeout for a note source URL (in seconds)'
),
cfg.IntOpt(
'drydock_client_connect_timeout',
default=20,
help=('Connect timeout used for connecting to Drydock using '
'the Drydock client (in seconds)')
),
cfg.IntOpt(
'drydock_client_read_timeout',
default=300,
help=('Read timeout used for responses from Drydock using '
'the Drydock client (in seconds)')
),
]
),
ConfigSection(

View File

@ -14,14 +14,16 @@
"""Generates clients and client-like objects and functions"""
from urllib.parse import urlparse
from oslo_config import cfg
from deckhand.client import client as dh_client
import drydock_provisioner.drydock_client.client as dd_client
import drydock_provisioner.drydock_client.session as dd_session
from shipyard_airflow.control.service_endpoints import Endpoints
from shipyard_airflow.control import service_endpoints as svc_endpoints
CONF = cfg.CONF
#
# Deckhand Client
@ -44,7 +46,10 @@ def drydock_client():
# Setup the drydock session
endpoint = svc_endpoints.get_endpoint(Endpoints.DRYDOCK)
dd_url = urlparse(endpoint)
session = dd_session.DrydockSession(dd_url.hostname,
port=dd_url.port,
auth_gen=_auth_gen)
session = dd_session.DrydockSession(
dd_url.hostname,
port=dd_url.port,
auth_gen=_auth_gen,
timeout=(CONF.requests_config.drydock_client_connect_timeout,
CONF.requests_config.drydock_client_read_timeout))
return dd_client.DrydockClient(session)

View File

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import configparser
import copy
import pprint
import logging
@ -88,6 +89,8 @@ class DrydockBaseOperator(UcpBaseOperator):
'container': 'drydock-api'}],
*args, **kwargs)
self.drydock_client = drydock_client
self.drydock_client_connect_timeout = None
self.drydock_client_read_timeout = None
self.drydock_task_id = drydock_task_id
self.node_filter = node_filter
self.redeploy_server = redeploy_server
@ -103,6 +106,15 @@ class DrydockBaseOperator(UcpBaseOperator):
LOG.debug("Drydock Operator for action %s", self.action_id)
# if continue processing is false, don't bother setting up things.
if self._continue_processing_flag():
# Retrieve config values from shipyard configuration.
config = configparser.ConfigParser()
config.read(self.shipyard_conf)
self.drydock_client_connect_timeout = int(config.get(
'requests_config', 'drydock_client_connect_timeout'))
self.drydock_client_read_timeout = int(config.get(
'requests_config', 'drydock_client_read_timeout'))
# Setup the drydock client
self._setup_drydock_client()
def _continue_processing_flag(self):
@ -137,9 +149,12 @@ class DrydockBaseOperator(UcpBaseOperator):
# information.
# The DrydockSession will care for TCP connection pooling
# and header management
dd_session = session.DrydockSession(drydock_url.hostname,
port=drydock_url.port,
auth_gen=self._auth_gen)
dd_session = session.DrydockSession(
drydock_url.hostname,
port=drydock_url.port,
auth_gen=self._auth_gen,
timeout=(self.drydock_client_connect_timeout,
self.drydock_client_read_timeout))
# Raise Exception if we are not able to set up the session
if not dd_session:

View File

@ -10,6 +10,8 @@ profiler = false
[requests_config]
notes_connect_timeout = 5
notes_read_timeout = 10
drydock_client_connect_timeout = 20
drydock_client_read_timeout = 300
[keystone_authtoken]
auth_section = keystone_authtoken