[trivial fix] Remove logging of health checks

Reduce the amount of repeated and otherwise not useful logging for
health checks. Most of the time he book-ending request/response are
useful for bounding other logs in the same requeest, the health check
bounding logs provide little benefit.

Change-Id: I486223bd92b3a6d5c7f6a11b3d9cc4153dd548a7
This commit is contained in:
Bryan Strassner 2018-04-13 16:05:51 -05:00
parent f8fb44b7a0
commit 89840303b1
2 changed files with 23 additions and 10 deletions

View File

@ -77,7 +77,8 @@ SECTIONS = [
),
cfg.DictOpt(
'named_log_levels',
default={"keystoneauth": logging.INFO},
default={"keystoneauth": logging.INFO,
"keystonemiddleware": logging.INFO},
help=('The logging levels for named loggers. '
'Use standard representations for logging levels: '
'ERROR. WARN, INFO, DEBUG. Configuration file format: '

View File

@ -19,6 +19,7 @@ import re
from shipyard_airflow.control import ucp_logging
LOG = logging.getLogger(__name__)
HEALTH_URL = '/health'
class LoggingMiddleware(object):
@ -33,21 +34,32 @@ class LoggingMiddleware(object):
ucp_logging.set_logvar('req_id', req.context.request_id)
ucp_logging.set_logvar('external_ctx', req.context.external_marker)
ucp_logging.set_logvar('user', req.context.user)
LOG.info("Request %s %s", req.method, req.url)
self._log_headers(req.headers)
if not req.url.endswith(HEALTH_URL):
# Log requests other than the health check.
LOG.info("Request %s %s", req.method, req.url)
self._log_headers(req.headers)
def process_response(self, req, resp, resource, req_succeeded):
""" Log the response information
"""
ctx = req.context
resp.append_header('X-Shipyard-Req', ctx.request_id)
LOG.info('%s %s - %s', req.method, req.uri, resp.status)
# TODO(bryan-strassner) since response bodies can contain sensitive
# information, only logging error response bodies here. When we
# have response scrubbing or way to categorize responses in the
# future, this may be an appropriate place to utilize it.
if self._get_resp_code(resp) >= 400:
LOG.debug('Errored Response body: %s', resp.body)
resp_code = self._get_resp_code(resp)
if req.url.endswith(HEALTH_URL):
# Only log health checks upon failure. This prevents repeated
# trivial logging due to constant health checks.
if not resp_code == 204:
LOG.error('Health check has failed with response status %s',
resp.status)
else:
LOG.info('%s %s - %s', req.method, req.uri, resp.status)
# TODO(bryan-strassner) since response bodies can contain sensitive
# information, only logging error response bodies here. When we
# have response scrubbing or way to categorize responses in the
# future, this may be an appropriate place to utilize it.
if resp_code >= 400:
LOG.debug('Errored Response body: %s', resp.body)
def _log_headers(self, headers):
""" Log request headers, while scrubbing sensitive values