Hook for auditing queries (#6484)

* Hook for auditing queries

* Address comments

* Use __name__
This commit is contained in:
Beto Dealmeida
2018-12-07 12:19:19 -08:00
committed by GitHub
parent eb408d71c4
commit 5168c69a25
3 changed files with 23 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ config = app.config
celery_app = get_celery_app(config)
stats_logger = app.config.get('STATS_LOGGER')
SQLLAB_TIMEOUT = config.get('SQLLAB_ASYNC_TIME_LIMIT_SEC', 600)
log_query = config.get('QUERY_LOGGER')
class SqlLabException(Exception):
@@ -180,6 +181,14 @@ def execute_sql(
logging.info('Running query: \n{}'.format(executed_sql))
logging.info(query.executed_sql)
query_start_time = now_as_float()
if log_query:
log_query(
query.database.sqlalchemy_uri,
query.executed_sql,
query.schema,
user_name,
__name__,
)
db_engine_spec.execute(cursor, query.executed_sql, async_=True)
logging.info('Handling cursor')
db_engine_spec.handle_cursor(cursor, query, session)