Reduce client & cluster logs upon requests

Change-Id: I333769380edb41e283c13e1ca78f3a5f956e610e
This commit is contained in:
asarfaty
2020-08-06 10:11:17 +02:00
committed by Adit Sarfaty
parent 0cbbc2f8a9
commit d18c78e8c0
2 changed files with 22 additions and 14 deletions

View File

@@ -249,25 +249,24 @@ class RESTClient(object):
request_headers.update(inject_headers) request_headers.update(inject_headers)
request_url = self._build_url(url) request_url = self._build_url(url)
do_request = getattr(self._conn, method.lower()) do_request = getattr(self._conn, method.lower())
if not silent: if silent:
self._conn.set_silent(True)
LOG.debug("REST call: %s %s. Headers: %s. Body: %s",
method, request_url,
utils.censor_headers(request_headers),
self._mask_password(body))
ts = time.time() ts = time.time()
result = do_request( result = do_request(
request_url, request_url,
data=body, data=body,
headers=request_headers) headers=request_headers)
te = time.time() te = time.time()
if silent:
self._conn.set_silent(False)
if not silent: if not silent:
LOG.debug("REST call: %s %s. Response: %s. Took %2.4f", LOG.debug("REST call: %s %s. Headers: %s. Body: %s. Response: %s. "
"Took %2.4f",
method, request_url, method, request_url,
utils.censor_headers(request_headers),
self._mask_password(body),
result.json() if result.content else '', result.json() if result.content else '',
te - ts) te - ts)

View File

@@ -87,6 +87,7 @@ class TimeoutSession(requests.Session):
self.timeout = timeout self.timeout = timeout
self.read_timeout = read_timeout self.read_timeout = read_timeout
self.cert_provider = None self.cert_provider = None
self._silent = False
super(TimeoutSession, self).__init__() super(TimeoutSession, self).__init__()
@property @property
@@ -97,6 +98,9 @@ class TimeoutSession(requests.Session):
def cert_provider(self, value): def cert_provider(self, value):
self._cert_provider = value self._cert_provider = value
def set_silent(self, silent_mode):
self._silent = silent_mode
# wrapper timeouts at the session level # wrapper timeouts at the session level
# see: https://goo.gl/xNk7aM # see: https://goo.gl/xNk7aM
def request(self, *args, **kwargs): def request(self, *args, **kwargs):
@@ -438,6 +442,7 @@ class ClusteredAPI(object):
self._http_provider = http_provider self._http_provider = http_provider
self._keepalive_interval = keepalive_interval self._keepalive_interval = keepalive_interval
self._print_keepalive = 0 self._print_keepalive = 0
self._silent = False
def _init_cluster(*args, **kwargs): def _init_cluster(*args, **kwargs):
self._init_endpoints(providers, min_conns_per_pool, self._init_endpoints(providers, min_conns_per_pool,
@@ -451,6 +456,9 @@ class ClusteredAPI(object):
# loops + state # loops + state
self._reinit_cluster = _init_cluster self._reinit_cluster = _init_cluster
def set_silent(self, silent_mode):
self._silent = silent_mode
def _init_endpoints(self, providers, min_conns_per_pool, def _init_endpoints(self, providers, min_conns_per_pool,
max_conns_per_pool, api_rate_limit, api_rate_mode): max_conns_per_pool, api_rate_limit, api_rate_mode):
LOG.debug("Initializing API endpoints") LOG.debug("Initializing API endpoints")
@@ -719,10 +727,11 @@ class ClusteredAPI(object):
if conn.default_headers: if conn.default_headers:
kwargs['headers'] = kwargs.get('headers', {}) kwargs['headers'] = kwargs.get('headers', {})
kwargs['headers'].update(conn.default_headers) kwargs['headers'].update(conn.default_headers)
LOG.debug("API cluster proxy %s %s to %s with %s. " if not self._silent:
"Waited conn: %2.4f, rate: %2.4f", LOG.debug("API cluster proxy %s %s to %s with %s. "
proxy_for.upper(), uri, url, kwargs, "Waited conn: %2.4f, rate: %2.4f",
conn_data.conn_wait, conn_data.rate_wait) proxy_for.upper(), uri, url, kwargs,
conn_data.conn_wait, conn_data.rate_wait)
# call the actual connection method to do the # call the actual connection method to do the
# http request/response over the wire # http request/response over the wire
@@ -753,7 +762,7 @@ class ClusteredAPI(object):
raise e raise e
# Returning the exception instead of raising it will cause # Returning the exception instead of raising it will cause
# decarator to retry. If retry attempts is exceeded, this # decorator to retry. If retry attempts is exceeded, this
# same exception will be raised due to overriden reraise # same exception will be raised due to overriden reraise
# method of RetryAttemptsExceeded # method of RetryAttemptsExceeded
return e return e