SamWheating commented on a change in pull request #20733:
URL: https://github.com/apache/airflow/pull/20733#discussion_r785235303
##########
File path: airflow/www/views.py
##########
@@ -3127,6 +3127,50 @@ def robots(self):
"""
return send_from_directory(current_app.static_folder, 'robots.txt')
+ @expose('/audit_log')
+ @auth.has_access(
+ [
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_AUDIT_LOG),
+ ]
+ )
+ @provide_session
+ def audit_log(self, session=None):
+ dag_id = request.args.get('dag_id')
+
+ included_events = conf.get('webserver', 'included_events')
+ excluded_events = conf.get('webserver', 'excluded_events')
+ query_start_dttm = timezone.utcnow() - timedelta(days=query_days)
+
+ query = session.query(Log).filter(
+ Log.dag_id == dag_id,
+ Log.dttm >= query_start_dttm,
+ )
+ if included_events:
+ included_events = {event.strip() for event in
included_events.split(',')}
+ query = query.filter(Log.event.in_(included_events))
+ if excluded_events:
+ excluded_events = {event.strip() for event in
excluded_events.split(',')}
+ query = query.filter(Log.event.notin_(excluded_events))
+
+ overlapping_events = included_events & excluded_events
+ if overlapping_events:
+ flash(Markup(f'There exists overlapping events:
<b>{overlapping_events}</b>. Please '
+ f'check included_events and excluded_events to have
unique events in each '
+ f'config. An event cannot be both. Reach out to
system administrator '
+ f'if any questions remain.'))
+ dag_audit_logs = []
+ else:
+ dag_audit_logs = query.all()
Review comment:
```suggestion
if included_events:
included_events = {event.strip() for event in
included_events.split(',')}
query = query.filter(Log.event.in_(included_events))
elif excluded_events:
excluded_events = {event.strip() for event in
excluded_events.split(',')}
query = query.filter(Log.event.notin_(excluded_events))
dag_audit_logs = query.all()
```
I don't think that there's any case where both of these values should be
set, since that would be redundant, right?
What if we set it up like so, and include in the documentation that
`included_events` will always take precedence over `excluded_events`?
Alternatively, we could just get rid of one of these options.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]