Skip to content

Commit

Permalink
Disable uses_queues
Browse files Browse the repository at this point in the history
There's currently an issue where logs in the gunicorn app server process don't
get pushed to CW. This resolves that, in order to make way for formatting RBAC
logs as JSON.

Here are some related issues which presented the solution:

kislyuk/watchtower#54
kislyuk/watchtower#89
  • Loading branch information
coderbydesign committed Apr 3, 2020
1 parent 280250f commit 977fc6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
22 changes: 13 additions & 9 deletions rbac/rbac/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ def process_response(self, request, response): # pylint: disable=no-self-use
request (object): The request object
response (object): The response object
"""
context = ''
query_string = ''
is_admin = False
account = None
Expand All @@ -293,15 +292,20 @@ def process_response(self, request, response): # pylint: disable=no-self-use
is_system = f'System: {request.user.system}'
req_id = request.user.req_id

logger.info(dict(request_id=req_id,
account=account,
username=username,
is_admin=request.user.admin,
is_system=request.user.system))
log_object = {
'method': request.method,
'path': request.path + query_string,
'status': response.status_code,
}

if account:
context = f' -- {req_id} {account} {username} {is_admin} {is_system}'
logger.info(f'{request.method} {request.path}{query_string}' # pylint: disable=W1203
f' {response.status_code}{context}')
log_object['req_id'] = req_id
log_object['account'] = account
log_object['username'] = username
log_object['is_admin'] = request.user.admin
log_object['is_system'] = request.user.system

logger.info(log_object)
return response


Expand Down
10 changes: 2 additions & 8 deletions rbac/rbac/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,10 @@
'handlers': LOGGING_HANDLERS,
'level': RBAC_LOGGING_LEVEL,
},
'gunicorn.access': {
'handlers': ['console'],
'level': RBAC_LOGGING_LEVEL,
'propagate': False,
},
},
}

if CW_AWS_ACCESS_KEY_ID:
print('setting up CW handler')
NAMESPACE = ENVIRONMENT.get_value('APP_NAMESPACE', default='unknown')
BOTO3_SESSION = Session(aws_access_key_id=CW_AWS_ACCESS_KEY_ID,
aws_secret_access_key=CW_AWS_SECRET_ACCESS_KEY,
Expand All @@ -306,8 +300,9 @@
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': BOTO3_SESSION,
'log_group': CW_LOG_GROUP,
'stream_name': 'rbac-test',
'stream_name': NAMESPACE,
'formatter': LOGGING_FORMATTER,
'use_queues': False,
}
LOGGING['handlers']['watchtower'] = WATCHTOWER_HANDLER

Expand Down Expand Up @@ -335,7 +330,6 @@

# Role Seeding Setup
ROLE_SEEDING_ENABLED = ENVIRONMENT.bool('ROLE_SEEDING_ENABLED', default=True)
logconfig_dict = LOGGING

# disable log messages less than CRITICAL when running unit tests.
if len(sys.argv) > 1 and sys.argv[1] == 'test':
Expand Down

0 comments on commit 977fc6a

Please sign in to comment.