Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/logging for pausing #36182

Merged
merged 6 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion airflow/www/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def wrapper(*args, **kwargs):
user = get_auth_manager().get_user_name()
user_display = get_auth_manager().get_user_display_name()

fields_skip_logging = {"csrf_token", "_csrf_token"}
fields_skip_logging = {"csrf_token", "_csrf_token", "is_paused"}
extra_fields = [
(k, secrets_masker.redact(v, k))
for k, v in itertools.chain(request.values.items(multi=True), request.view_args.items())
Expand All @@ -106,6 +106,8 @@ def wrapper(*args, **kwargs):

params = {**request.values, **request.view_args}

if params and "is_paused" in params:
extra_fields.append(("is_paused", params["is_paused"] == "false"))
log = Log(
event=event or f.__name__,
task_instance=None,
Expand Down
50 changes: 50 additions & 0 deletions tests/www/views/test_views_paused.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import pytest

from airflow.models.log import Log
from tests.test_utils.db import clear_db_dags

pytestmark = pytest.mark.db_test


@pytest.fixture(autouse=True)
def dags(create_dummy_dag):
paused_dag, _ = create_dummy_dag(dag_id="paused_dag", is_paused_upon_creation=True)
dag, _ = create_dummy_dag(dag_id="unpaused_dag")

yield dag, paused_dag

clear_db_dags()


def test_logging_pause_dag(admin_client, dags, session):
dag, _ = dags
# is_paused=false mean pause the dag
admin_client.post(f"/paused?is_paused=false&dag_id={dag.dag_id}", follow_redirects=True)
dag_query = session.query(Log).filter(Log.dag_id == dag.dag_id)
assert "('is_paused', True)" in dag_query.first().extra


def test_logging_unpuase_dag(admin_client, dags, session):
_, paused_dag = dags
# is_paused=true mean unpause the dag
admin_client.post(f"/paused?is_paused=true&dag_id={paused_dag.dag_id}", follow_redirects=True)
dag_query = session.query(Log).filter(Log.dag_id == paused_dag.dag_id)
assert "('is_paused', False)" in dag_query.first().extra