This is an automated email from the ASF dual-hosted git repository.
bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new d663d8bc76 Clean up webserver endpoints adding to audit log (#37580)
d663d8bc76 is described below
commit d663d8bc76ec3de3356cadbda392b9e0c90e0a36
Author: Brent Bovenzi <[email protected]>
AuthorDate: Fri Feb 23 01:04:26 2024 -0500
Clean up webserver endpoints adding to audit log (#37580)
* Clean up webserver endpoints adding to audit log
* Remove all view-only action logging and change excluded events list
* Restore robots logging
* Remove two extra loggings+tests, add test for robots.txt
* Fix rendered template test
---
airflow/config_templates/config.yml | 4 +--
airflow/www/views.py | 43 +++++---------------------------
tests/www/views/test_views_decorators.py | 36 +++++---------------------
3 files changed, 14 insertions(+), 69 deletions(-)
diff --git a/airflow/config_templates/config.yml
b/airflow/config_templates/config.yml
index 4db178cd8f..41d0b56c9f 100644
--- a/airflow/config_templates/config.yml
+++ b/airflow/config_templates/config.yml
@@ -1837,8 +1837,8 @@ webserver:
The audit logs in the db will not be affected by this parameter.
version_added: 2.3.0
type: string
- example: ~
- default:
"gantt,landing_times,tries,duration,calendar,graph,grid,tree,tree_data"
+ example: "cli_task_run,running,success"
+ default: ~
audit_view_included_events:
description: |
Comma separated string of view events to include in dag audit view.
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 1e00e86423..9b19f26fc6 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1325,8 +1325,7 @@ class Airflow(AirflowBaseView):
@expose("/dags/<string:dag_id>/code")
@auth.has_access_dag("GET", DagAccessEntity.CODE)
- @provide_session
- def code(self, dag_id, session: Session = NEW_SESSION):
+ def code(self, dag_id):
"""Dag Code."""
kwargs = {
**sanitize_args(request.args),
@@ -1348,7 +1347,6 @@ class Airflow(AirflowBaseView):
@expose("/rendered-templates")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def rendered_templates(self, session):
"""Get rendered Dag."""
@@ -1362,7 +1360,7 @@ class Airflow(AirflowBaseView):
logging.info("Retrieving rendered templates.")
dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
- dag_run = dag.get_dagrun(execution_date=dttm, session=session)
+ dag_run = dag.get_dagrun(execution_date=dttm)
raw_task = dag.get_task(task_id).prepare_for_execution()
no_dagrun = False
@@ -1467,7 +1465,6 @@ class Airflow(AirflowBaseView):
@expose("/rendered-k8s")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def rendered_k8s(self, *, session: Session = NEW_SESSION):
"""Get rendered k8s yaml."""
@@ -1533,7 +1530,6 @@ class Airflow(AirflowBaseView):
@expose("/get_logs_with_metadata")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
@auth.has_access_dag("GET", DagAccessEntity.TASK_LOGS)
- @action_logging
@provide_session
def get_logs_with_metadata(self, session: Session = NEW_SESSION):
"""Retrieve logs including metadata."""
@@ -1614,7 +1610,6 @@ class Airflow(AirflowBaseView):
@expose("/log")
@auth.has_access_dag("GET", DagAccessEntity.TASK_LOGS)
- @action_logging
@provide_session
def log(self, session: Session = NEW_SESSION):
"""Retrieve log."""
@@ -1659,7 +1654,6 @@ class Airflow(AirflowBaseView):
@expose("/redirect_to_external_log")
@auth.has_access_dag("GET", DagAccessEntity.TASK_LOGS)
- @action_logging
@provide_session
def redirect_to_external_log(self, session: Session = NEW_SESSION):
"""Redirects to external log."""
@@ -1691,7 +1685,6 @@ class Airflow(AirflowBaseView):
@expose("/task")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def task(self, session: Session = NEW_SESSION):
"""Retrieve task."""
@@ -1817,7 +1810,6 @@ class Airflow(AirflowBaseView):
@expose("/xcom")
@auth.has_access_dag("GET", DagAccessEntity.XCOM)
- @action_logging
@provide_session
def xcom(self, session: Session = NEW_SESSION):
"""Retrieve XCOM."""
@@ -2346,6 +2338,7 @@ class Airflow(AirflowBaseView):
@expose("/blocked", methods=["POST"])
@auth.has_access_dag("GET", DagAccessEntity.RUN)
+ @action_logging
@provide_session
def blocked(self, session: Session = NEW_SESSION):
"""Mark Dag Blocked."""
@@ -2491,7 +2484,7 @@ class Airflow(AirflowBaseView):
@expose("/dagrun_details")
def dagrun_details(self):
- """Redirect to the GRID DAGRun page. This is avoids breaking links."""
+ """Redirect to the Grid DagRun page. This is avoids breaking links."""
dag_id = request.args.get("dag_id")
run_id = request.args.get("run_id")
return redirect(url_for("Airflow.grid", dag_id=dag_id,
dag_run_id=run_id))
@@ -2762,16 +2755,12 @@ class Airflow(AirflowBaseView):
)
@expose("/dags/<string:dag_id>")
- @gzipped
- @action_logging
def dag(self, dag_id):
"""Redirect to default DAG view."""
kwargs = {**sanitize_args(request.args), "dag_id": dag_id}
return redirect(url_for("Airflow.grid", **kwargs))
@expose("/tree")
- @gzipped
- @action_logging
def legacy_tree(self):
"""Redirect to the replacement - grid view. Kept for backwards
compatibility."""
return redirect(url_for("Airflow.grid", **sanitize_args(request.args)))
@@ -2779,7 +2768,6 @@ class Airflow(AirflowBaseView):
@expose("/dags/<string:dag_id>/grid")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
@gzipped
- @action_logging
@provide_session
def grid(self, dag_id: str, session: Session = NEW_SESSION):
"""Get Dag's grid view."""
@@ -2838,8 +2826,6 @@ class Airflow(AirflowBaseView):
)
@expose("/calendar")
- @gzipped
- @action_logging
def legacy_calendar(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.calendar",
**sanitize_args(request.args)))
@@ -2847,7 +2833,6 @@ class Airflow(AirflowBaseView):
@expose("/dags/<string:dag_id>/calendar")
@auth.has_access_dag("GET", DagAccessEntity.RUN)
@gzipped
- @action_logging
@provide_session
def calendar(self, dag_id: str, session: Session = NEW_SESSION):
"""Get DAG runs as calendar."""
@@ -2953,15 +2938,12 @@ class Airflow(AirflowBaseView):
)
@expose("/graph")
- @gzipped
- @action_logging
def legacy_graph(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.graph",
**sanitize_args(request.args)))
@expose("/dags/<string:dag_id>/graph")
@gzipped
- @action_logging
@provide_session
def graph(self, dag_id: str, session: Session = NEW_SESSION):
"""Redirect to the replacement - grid + graph. Kept for backwards
compatibility."""
@@ -2984,14 +2966,12 @@ class Airflow(AirflowBaseView):
return redirect(url_for("Airflow.grid", **kwargs))
@expose("/duration")
- @action_logging
def legacy_duration(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.duration",
**sanitize_args(request.args)))
@expose("/dags/<string:dag_id>/duration")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def duration(self, dag_id: str, session: Session = NEW_SESSION):
"""Get Dag as duration graph."""
@@ -3137,14 +3117,12 @@ class Airflow(AirflowBaseView):
)
@expose("/tries")
- @action_logging
def legacy_tries(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.tries",
**sanitize_args(request.args)))
@expose("/dags/<string:dag_id>/tries")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def tries(self, dag_id: str, session: Session = NEW_SESSION):
"""Show all tries."""
@@ -3220,14 +3198,12 @@ class Airflow(AirflowBaseView):
)
@expose("/landing_times")
- @action_logging
def legacy_landing_times(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.landing_times",
**sanitize_args(request.args)))
@expose("/dags/<string:dag_id>/landing-times")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def landing_times(self, dag_id: str, session: Session = NEW_SESSION):
"""Show landing times."""
@@ -3326,14 +3302,12 @@ class Airflow(AirflowBaseView):
return "OK"
@expose("/gantt")
- @action_logging
def legacy_gantt(self):
"""Redirect from url param."""
return redirect(url_for("Airflow.gantt",
**sanitize_args(request.args)))
@expose("/dags/<string:dag_id>/gantt")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def gantt(self, dag_id: str, session: Session = NEW_SESSION):
"""Redirect to the replacement - grid + gantt. Kept for backwards
compatibility."""
@@ -3349,7 +3323,6 @@ class Airflow(AirflowBaseView):
@expose("/extra_links")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
@provide_session
def extra_links(self, *, session: Session = NEW_SESSION):
"""
@@ -3406,12 +3379,10 @@ class Airflow(AirflowBaseView):
@expose("/object/graph_data")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
@gzipped
- @action_logging
- @provide_session
- def graph_data(self, session: Session = NEW_SESSION):
+ def graph_data(self):
"""Get Graph Data."""
dag_id = request.args.get("dag_id")
- dag = get_airflow_app().dag_bag.get_dag(dag_id, session=session)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
root = request.args.get("root")
if root:
filter_upstream = request.args.get("filter_upstream") == "true"
@@ -3435,7 +3406,6 @@ class Airflow(AirflowBaseView):
@expose("/object/task_instances")
@auth.has_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
- @action_logging
def task_instances(self):
"""Show task instances."""
dag_id = request.args.get("dag_id")
@@ -5798,7 +5768,6 @@ class DagDependenciesView(AirflowBaseView):
@expose("/dag-dependencies")
@auth.has_access_dag("GET", DagAccessEntity.DEPENDENCIES)
@gzipped
- @action_logging
def list(self):
"""Display DAG dependencies."""
title = "DAG Dependencies"
diff --git a/tests/www/views/test_views_decorators.py
b/tests/www/views/test_views_decorators.py
index 00e657a2d7..4cfab0926e 100644
--- a/tests/www/views/test_views_decorators.py
+++ b/tests/www/views/test_views_decorators.py
@@ -17,8 +17,6 @@
# under the License.
from __future__ import annotations
-import urllib.parse
-
import pytest
from airflow.models import DagBag, Variable
@@ -92,39 +90,17 @@ def clean_db():
clear_db_variables()
-def test_action_logging_get(session, admin_client):
- url = (
- f"dags/example_bash_operator/grid?"
-
f"execution_date={urllib.parse.quote_plus(str(EXAMPLE_DAG_DEFAULT_DATE))}"
- )
- resp = admin_client.get(url, follow_redirects=True)
- check_content_in_response("success", resp)
+def test_action_logging_robots(session, admin_client):
+ url = "/robots.txt"
+ admin_client.get(url, follow_redirects=True)
# In mysql backend, this commit() is needed to write down the logs
session.commit()
_check_last_log(
session,
- dag_id="example_bash_operator",
- event="grid",
- execution_date=EXAMPLE_DAG_DEFAULT_DATE,
- )
-
-
-def test_action_logging_get_legacy_view(session, admin_client):
- url = (
- f"tree?dag_id=example_bash_operator&"
-
f"execution_date={urllib.parse.quote_plus(str(EXAMPLE_DAG_DEFAULT_DATE))}"
- )
- resp = admin_client.get(url, follow_redirects=True)
- check_content_in_response("success", resp)
-
- # In mysql backend, this commit() is needed to write down the logs
- session.commit()
- _check_last_log(
- session,
- dag_id="example_bash_operator",
- event="legacy_tree",
- execution_date=EXAMPLE_DAG_DEFAULT_DATE,
+ event="robots",
+ dag_id=None,
+ execution_date=None,
)