create performance logger to log api response time

this middleware allready existed, and we were trying to log this
data but it was not working.

Hope is these logs will be able to be shipped via external logging
and we could use kibana to track response time of different endpoints
This commit is contained in:
Elijah DeLee 2021-02-18 17:56:01 -05:00
parent 080c430b82
commit 0e6c14e707
2 changed files with 9 additions and 1 deletions

View File

@ -45,7 +45,10 @@ class TimingMiddleware(threading.local, MiddlewareMixin):
response['X-API-Total-Time'] = '%0.3fs' % total_time
if settings.AWX_REQUEST_PROFILE:
response['X-API-Profile-File'] = self.prof.stop()
perf_logger.info('api response times', extra=dict(python_objects=dict(request=request, response=response)))
perf_logger.info(
f'request: {request}, response_time: {response["X-API-Total-Time"]}',
extra=dict(python_objects=dict(request=request, response=response, X_API_TOTAL_TIME=response["X-API-Total-Time"]))
)
return response

View File

@ -1044,6 +1044,11 @@ LOGGING = {
'level': 'INFO',
'propagate': False
},
'awx.analytics.performance': {
'handlers': ['console', 'file', 'tower_warnings', 'external_logger'],
'level': 'DEBUG',
'propagate': False
},
'awx.analytics.job_lifecycle': {
'handlers': ['console', 'job_lifecycle'],
'level': 'DEBUG',