You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2024/03/18 22:32:05 UTC

(airflow) branch v2-8-test updated (19d684d3ce -> bcdd076200)

This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a change to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


    from 19d684d3ce Update documentation about recent image changes (#38085)
     new 07b32f04fe Fix hash caching in `ObjectStoragePath` (#37769)
     new c44f5396be Add padding to prevent grid horizontal scroll overlapping tasks (#37942)
     new 8c4f10427c Fix a bug where scheduler heartrate parameter were not used (#37992)
     new 0e60195448 Fix task instances list link (#38096)
     new e6ab8fc158 Fix excessive permission changing for log task handler (#38164)
     new 62f636f0d4 bump `croniter` to fix an issue with 29 Feb cron expressions (#38198)
     new bcdd076200 Fix filtered TI links (#38274)

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 airflow/io/path.py                       |  6 ++---
 airflow/jobs/job.py                      |  2 ++
 airflow/jobs/scheduler_job_runner.py     |  1 -
 airflow/utils/log/file_task_handler.py   | 41 +++++++-------------------------
 airflow/www/static/js/dag/grid/index.tsx |  1 +
 airflow/www/utils.py                     | 11 +++++++--
 pyproject.toml                           |  2 +-
 tests/io/test_path.py                    |  9 +++++++
 tests/jobs/test_base_job.py              |  9 ++++---
 tests/jobs/test_scheduler_job.py         | 10 ++++++++
 tests/models/test_dag.py                 | 13 ++++++++++
 tests/utils/test_log_handlers.py         | 28 ++++++++++------------
 12 files changed, 75 insertions(+), 58 deletions(-)


(airflow) 07/07: Fix filtered TI links (#38274)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit bcdd076200a4caf1f7f1533e1d2f5dddaff2fb56
Author: Jed Cunningham <66...@users.noreply.github.com>
AuthorDate: Mon Mar 18 16:17:58 2024 -0600

    Fix filtered TI links (#38274)
    
    We have links to the graph, filtered down to a specific TI. This was
    accidentally broken in #38096.
    
    (cherry picked from commit 8ea95e778a1a0b90aaeecd156d6924915a6f1c27)
---
 airflow/www/utils.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/airflow/www/utils.py b/airflow/www/utils.py
index 389d9e25ca..6f7f9c5945 100644
--- a/airflow/www/utils.py
+++ b/airflow/www/utils.py
@@ -435,6 +435,7 @@ def task_instance_link(attr):
         "Airflow.grid",
         dag_id=dag_id,
         task_id=task_id,
+        root=task_id,
         dag_run_id=run_id,
         tab="graph",
         map_index=attr.get("map_index", -1),


(airflow) 03/07: Fix a bug where scheduler heartrate parameter were not used (#37992)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 8c4f10427cac2c679bdab5063d1fde84c88a5f5b
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Fri Mar 8 14:31:46 2024 +0100

    Fix a bug where scheduler heartrate parameter were not used (#37992)
    
    Sinc #30255 scheduler heartrate has not been properly calculated.
    We missed the check for SchedulerJob type and setting heartrate
    value from `scheduler_health_check_threshold`.
    
    This PR fixes it.
    
    Fix: #37971
    (cherry picked from commit 01e40abc759a219cc359fab6ca73434cca55901a)
---
 airflow/jobs/job.py                  |  2 ++
 airflow/jobs/scheduler_job_runner.py |  1 -
 tests/jobs/test_base_job.py          |  9 ++++++---
 tests/jobs/test_scheduler_job.py     | 10 ++++++++++
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/airflow/jobs/job.py b/airflow/jobs/job.py
index 0afbb2a026..0bd81e0c80 100644
--- a/airflow/jobs/job.py
+++ b/airflow/jobs/job.py
@@ -264,6 +264,8 @@ class Job(Base, LoggingMixin):
     def _heartrate(job_type: str) -> float:
         if job_type == "TriggererJob":
             return conf.getfloat("triggerer", "JOB_HEARTBEAT_SEC")
+        elif job_type == "SchedulerJob":
+            return conf.getfloat("scheduler", "SCHEDULER_HEARTBEAT_SEC")
         else:
             # Heartrate used to be hardcoded to scheduler, so in all other
             # cases continue to use that value for back compat
diff --git a/airflow/jobs/scheduler_job_runner.py b/airflow/jobs/scheduler_job_runner.py
index bf5a28cb5b..eddd742571 100644
--- a/airflow/jobs/scheduler_job_runner.py
+++ b/airflow/jobs/scheduler_job_runner.py
@@ -151,7 +151,6 @@ class SchedulerJobRunner(BaseJobRunner, LoggingMixin):
     """
 
     job_type = "SchedulerJob"
-    heartrate: int = conf.getint("scheduler", "SCHEDULER_HEARTBEAT_SEC")
 
     def __init__(
         self,
diff --git a/tests/jobs/test_base_job.py b/tests/jobs/test_base_job.py
index 8f7237ffc6..62e0369791 100644
--- a/tests/jobs/test_base_job.py
+++ b/tests/jobs/test_base_job.py
@@ -97,9 +97,12 @@ class TestJob:
     )
     def test_heart_rate_after_fetched_from_db(self, job_runner, job_type, job_heartbeat_sec):
         """Ensure heartrate is set correctly after jobs are queried from the DB"""
-        with create_session() as session, conf_vars(
-            {(job_type.lower(), "job_heartbeat_sec"): job_heartbeat_sec}
-        ):
+        if job_type == "scheduler":
+            config_name = "scheduler_heartbeat_sec"
+        else:
+            config_name = "job_heartbeat_sec"
+
+        with create_session() as session, conf_vars({(job_type.lower(), config_name): job_heartbeat_sec}):
             job = Job()
             job_runner(job=job)
             session.add(job)
diff --git a/tests/jobs/test_scheduler_job.py b/tests/jobs/test_scheduler_job.py
index 8e745e1e08..e5de64ee9d 100644
--- a/tests/jobs/test_scheduler_job.py
+++ b/tests/jobs/test_scheduler_job.py
@@ -193,6 +193,16 @@ class TestSchedulerJob:
                 not scheduler_job.is_alive()
             ), "Completed jobs even with recent heartbeat should not be alive"
 
+    @pytest.mark.parametrize(
+        "heartrate",
+        [10, 5],
+    )
+    def test_heartrate(self, heartrate):
+        with conf_vars({("scheduler", "scheduler_heartbeat_sec"): str(heartrate)}):
+            scheduler_job = Job(executor=self.null_exec)
+            _ = SchedulerJobRunner(job=scheduler_job)
+            assert scheduler_job.heartrate == heartrate
+
     def run_single_scheduler_loop_with_no_dags(self, dags_folder):
         """
         Utility function that runs a single scheduler loop without actually


(airflow) 01/07: Fix hash caching in `ObjectStoragePath` (#37769)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 07b32f04fe1dc5b568f954e68960ecba50a71f80
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Wed Feb 28 17:05:58 2024 +0400

    Fix hash caching in `ObjectStoragePath` (#37769)
    
    (cherry picked from commit 382a9618ed15403766ec7d1bcbe41ed955b3e60d)
---
 airflow/io/path.py    | 6 +++---
 tests/io/test_path.py | 9 +++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/airflow/io/path.py b/airflow/io/path.py
index bd7c320653..40a9e49e52 100644
--- a/airflow/io/path.py
+++ b/airflow/io/path.py
@@ -17,7 +17,6 @@
 from __future__ import annotations
 
 import contextlib
-import functools
 import os
 import shutil
 import typing
@@ -149,9 +148,10 @@ class ObjectStoragePath(CloudPath):
 
         return cls._from_parts(args_list, url=parsed_url, conn_id=conn_id, **kwargs)  # type: ignore
 
-    @functools.lru_cache
     def __hash__(self) -> int:
-        return hash(str(self))
+        if not (_hash := getattr(self, "_hash", None)):
+            self._hash = _hash = hash(str(self))
+        return _hash
 
     def __eq__(self, other: typing.Any) -> bool:
         return self.samestore(other) and str(self) == str(other)
diff --git a/tests/io/test_path.py b/tests/io/test_path.py
index 7c97c7b2b9..7f250825ce 100644
--- a/tests/io/test_path.py
+++ b/tests/io/test_path.py
@@ -306,3 +306,12 @@ class TestFs:
         finally:
             # Reset the cache to avoid side effects
             _register_filesystems.cache_clear()
+
+    def test_hash(self):
+        file_uri_1 = f"file:///tmp/{str(uuid.uuid4())}"
+        file_uri_2 = f"file:///tmp/{str(uuid.uuid4())}"
+        s = set()
+        for _ in range(10):
+            s.add(ObjectStoragePath(file_uri_1))
+            s.add(ObjectStoragePath(file_uri_2))
+        assert len(s) == 2


(airflow) 02/07: Add padding to prevent grid horizontal scroll overlapping tasks (#37942)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit c44f5396be0b2d7a01cc08ccf03cf29fbf1c8b48
Author: Brent Bovenzi <br...@astronomer.io>
AuthorDate: Wed Mar 6 14:02:02 2024 -0500

    Add padding to prevent grid horizontal scroll overlapping tasks (#37942)
    
    (cherry picked from commit 0c9487f9466587f6cbc443ab2c9dc17d35c98f5d)
---
 airflow/www/static/js/dag/grid/index.tsx | 1 +
 1 file changed, 1 insertion(+)

diff --git a/airflow/www/static/js/dag/grid/index.tsx b/airflow/www/static/js/dag/grid/index.tsx
index b7299e5ba3..079837d087 100644
--- a/airflow/www/static/js/dag/grid/index.tsx
+++ b/airflow/www/static/js/dag/grid/index.tsx
@@ -167,6 +167,7 @@ const Grid = ({
         position="relative"
         mt={8}
         overscrollBehavior="auto"
+        pb={4}
       >
         <Table borderRightWidth="16px" borderColor="transparent">
           <Thead>


(airflow) 04/07: Fix task instances list link (#38096)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 0e60195448d6a8b0dca6a72e279b1e41efe37c35
Author: Brent Bovenzi <br...@astronomer.io>
AuthorDate: Wed Mar 13 09:46:07 2024 -0400

    Fix task instances list link (#38096)
    
    (cherry picked from commit 43d7f6d3da0192c3abd07c9f0dab54e6da605621)
---
 airflow/www/utils.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/airflow/www/utils.py b/airflow/www/utils.py
index 16d0950989..389d9e25ca 100644
--- a/airflow/www/utils.py
+++ b/airflow/www/utils.py
@@ -422,6 +422,7 @@ def task_instance_link(attr):
     """Generate a URL to the Graph view for a TaskInstance."""
     dag_id = attr.get("dag_id")
     task_id = attr.get("task_id")
+    run_id = attr.get("run_id")
     execution_date = attr.get("dag_run.execution_date") or attr.get("execution_date") or timezone.utcnow()
     url = url_for(
         "Airflow.task",
@@ -431,13 +432,18 @@ def task_instance_link(attr):
         map_index=attr.get("map_index", -1),
     )
     url_root = url_for(
-        "Airflow.graph", dag_id=dag_id, root=task_id, execution_date=execution_date.isoformat()
+        "Airflow.grid",
+        dag_id=dag_id,
+        task_id=task_id,
+        dag_run_id=run_id,
+        tab="graph",
+        map_index=attr.get("map_index", -1),
     )
     return Markup(
         """
         <span style="white-space: nowrap;">
         <a href="{url}">{task_id}</a>
-        <a href="{url_root}" title="Filter on this task and upstream">
+        <a href="{url_root}" title="Filter on this task">
         <span class="material-icons" style="margin-left:0;"
             aria-hidden="true">filter_alt</span>
         </a>


(airflow) 05/07: Fix excessive permission changing for log task handler (#38164)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit e6ab8fc158d377f1593fdddf7dd35a9200964d35
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Mon Mar 18 19:28:37 2024 +0100

    Fix excessive permission changing for log task handler (#38164)
    
    When log dir permission was changed by log handler, we've
    implemented also changing permissions of parent folders recursively,
    however it was quite a bit too much to change it for home directory
    where the log folder could have been created - because in some cases
    changing permissions might lead to unexpected side-effects - such
    as loosing ability to login to ssh server.
    
    Fixes: #38137
    (cherry picked from commit 2c1d0f8c4121589e92e4c0ca1665b89a2691d2d8)
---
 airflow/utils/log/file_task_handler.py | 41 ++++++++--------------------------
 tests/utils/test_log_handlers.py       | 28 ++++++++++-------------
 2 files changed, 21 insertions(+), 48 deletions(-)

diff --git a/airflow/utils/log/file_task_handler.py b/airflow/utils/log/file_task_handler.py
index 7e1faca4ec..e6dd540267 100644
--- a/airflow/utils/log/file_task_handler.py
+++ b/airflow/utils/log/file_task_handler.py
@@ -159,31 +159,6 @@ def _ensure_ti(ti: TaskInstanceKey | TaskInstance, session) -> TaskInstance:
         raise AirflowException(f"Could not find TaskInstance for {ti}")
 
 
-def _change_directory_permissions_up(directory: Path, folder_permissions: int):
-    """
-    Change permissions of the given directory and its parents.
-
-    Only attempt to change permissions for directories owned by the current user.
-
-    :param directory: directory to change permissions of (including parents)
-    :param folder_permissions: permissions to set
-    """
-    if directory.stat().st_uid == os.getuid():
-        if directory.stat().st_mode % 0o1000 != folder_permissions % 0o1000:
-            print(f"Changing {directory} permission to {folder_permissions}")
-            try:
-                directory.chmod(folder_permissions)
-            except PermissionError as e:
-                # In some circumstances (depends on user and filesystem) we might not be able to
-                # change the permission for the folder (when the folder was created by another user
-                # before or when the filesystem does not allow to change permission). We should not
-                # fail in this case but rather ignore it.
-                print(f"Failed to change {directory} permission to {folder_permissions}: {e}")
-                return
-        if directory.parent != directory:
-            _change_directory_permissions_up(directory.parent, folder_permissions)
-
-
 class FileTaskHandler(logging.Handler):
     """
     FileTaskHandler is a python log handler that handles and reads task instance logs.
@@ -481,7 +456,8 @@ class FileTaskHandler(logging.Handler):
 
         return logs, metadata_array
 
-    def _prepare_log_folder(self, directory: Path):
+    @staticmethod
+    def _prepare_log_folder(directory: Path, new_folder_permissions: int):
         """
         Prepare the log folder and ensure its mode is as configured.
 
@@ -505,11 +481,9 @@ class FileTaskHandler(logging.Handler):
         sure that the same group is set as default group for both - impersonated user and main airflow
         user.
         """
-        new_folder_permissions = int(
-            conf.get("logging", "file_task_handler_new_folder_permissions", fallback="0o775"), 8
-        )
-        directory.mkdir(mode=new_folder_permissions, parents=True, exist_ok=True)
-        _change_directory_permissions_up(directory, new_folder_permissions)
+        for parent in reversed(directory.parents):
+            parent.mkdir(mode=new_folder_permissions, exist_ok=True)
+        directory.mkdir(mode=new_folder_permissions, exist_ok=True)
 
     def _init_file(self, ti, *, identifier: str | None = None):
         """
@@ -531,7 +505,10 @@ class FileTaskHandler(logging.Handler):
             # if this is true, we're invoked via set_context in the context of
             # setting up individual trigger logging. return trigger log path.
             full_path = self.add_triggerer_suffix(full_path=full_path, job_id=ti.triggerer_job.id)
-        self._prepare_log_folder(Path(full_path).parent)
+        new_folder_permissions = int(
+            conf.get("logging", "file_task_handler_new_folder_permissions", fallback="0o775"), 8
+        )
+        self._prepare_log_folder(Path(full_path).parent, new_folder_permissions)
 
         if not os.path.exists(full_path):
             open(full_path, "a").close()
diff --git a/tests/utils/test_log_handlers.py b/tests/utils/test_log_handlers.py
index 36810506da..6017c761c9 100644
--- a/tests/utils/test_log_handlers.py
+++ b/tests/utils/test_log_handlers.py
@@ -22,7 +22,6 @@ import logging.config
 import os
 import re
 import shutil
-import tempfile
 from pathlib import Path
 from unittest import mock
 from unittest.mock import patch
@@ -42,7 +41,6 @@ from airflow.operators.python import PythonOperator
 from airflow.utils.log.file_task_handler import (
     FileTaskHandler,
     LogType,
-    _change_directory_permissions_up,
     _interleave_logs,
     _parse_timestamps_in_log_file,
 )
@@ -724,28 +722,26 @@ def test_interleave_logs_correct_ordering():
     assert sample_with_dupe == "\n".join(_interleave_logs(sample_with_dupe, "", sample_with_dupe))
 
 
-def test_permissions_for_new_directories():
-    tmp_path = Path(tempfile.mkdtemp())
+def test_permissions_for_new_directories(tmpdir):
+    tmpdir_path = Path(tmpdir)
     try:
         # Set umask to 0o027: owner rwx, group rx-w, other -rwx
         old_umask = os.umask(0o027)
         try:
-            subdir = tmp_path / "subdir1" / "subdir2"
+            base_dir = tmpdir_path / "base"
+            base_dir.mkdir()
+            log_dir = base_dir / "subdir1" / "subdir2"
             # force permissions for the new folder to be owner rwx, group -rxw, other -rwx
             new_folder_permissions = 0o700
             # default permissions are owner rwx, group rx-w, other -rwx (umask bit negative)
             default_permissions = 0o750
-            subdir.mkdir(mode=new_folder_permissions, parents=True, exist_ok=True)
-            assert subdir.exists()
-            assert subdir.is_dir()
-            assert subdir.stat().st_mode % 0o1000 == new_folder_permissions
-            # initially parent permissions are as per umask
-            assert subdir.parent.stat().st_mode % 0o1000 == default_permissions
-            _change_directory_permissions_up(subdir, new_folder_permissions)
-            assert subdir.stat().st_mode % 0o1000 == new_folder_permissions
-            # now parent permissions are as per new_folder_permissions
-            assert subdir.parent.stat().st_mode % 0o1000 == new_folder_permissions
+            FileTaskHandler._prepare_log_folder(log_dir, new_folder_permissions)
+            assert log_dir.exists()
+            assert log_dir.is_dir()
+            assert log_dir.stat().st_mode % 0o1000 == new_folder_permissions
+            assert log_dir.parent.stat().st_mode % 0o1000 == new_folder_permissions
+            assert base_dir.stat().st_mode % 0o1000 == default_permissions
         finally:
             os.umask(old_umask)
     finally:
-        shutil.rmtree(tmp_path)
+        shutil.rmtree(tmpdir_path)


(airflow) 06/07: bump `croniter` to fix an issue with 29 Feb cron expressions (#38198)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 62f636f0d4dc410e9dd366cc605477bbd520c821
Author: Hussein Awala <hu...@awala.fr>
AuthorDate: Sat Mar 16 01:08:40 2024 +0100

    bump `croniter` to fix an issue with 29 Feb cron expressions (#38198)
    
    (cherry picked from commit 2e3b1758246169b278e7d409ecff98532ec18c18)
---
 pyproject.toml           |  2 +-
 tests/models/test_dag.py | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index 001dd86d37..2a3cac3008 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -87,7 +87,7 @@ dependencies = [
     # This limit can be removed after https://github.com/apache/airflow/issues/35234 is fixed
     "connexion[flask]>=2.10.0,<3.0",
     "cron-descriptor>=1.2.24",
-    "croniter>=0.3.17",
+    "croniter>=2.0.2",
     "cryptography>=0.9.3",
     "deprecated>=1.2.13",
     "dill>=0.2.2",
diff --git a/tests/models/test_dag.py b/tests/models/test_dag.py
index 152bed8e94..31a7460704 100644
--- a/tests/models/test_dag.py
+++ b/tests/models/test_dag.py
@@ -2453,6 +2453,19 @@ my_postgres_conn:
         next_subdag_info = subdag.next_dagrun_info(None)
         assert next_subdag_info is None, "SubDags should never have DagRuns created by the scheduler"
 
+    def test_next_dagrun_info_on_29_feb(self):
+        dag = DAG(
+            "test_scheduler_dagrun_29_feb", start_date=timezone.datetime(2024, 1, 1), schedule="0 0 29 2 *"
+        )
+
+        next_info = dag.next_dagrun_info(None)
+        assert next_info and next_info.logical_date == timezone.datetime(2024, 2, 29)
+
+        next_info = dag.next_dagrun_info(next_info.data_interval)
+        assert next_info.logical_date == timezone.datetime(2028, 2, 29)
+        assert next_info.data_interval.start == timezone.datetime(2028, 2, 29)
+        assert next_info.data_interval.end == timezone.datetime(2032, 2, 29)
+
     def test_replace_outdated_access_control_actions(self):
         outdated_permissions = {
             "role1": {permissions.ACTION_CAN_READ, permissions.ACTION_CAN_EDIT},