You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/12/09 09:41:39 UTC
(airflow) branch main updated: Create latest log dir symlink as relative link (#36019)
This is an automated email from the ASF dual-hosted git repository.
potiuk 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 17e91727b2 Create latest log dir symlink as relative link (#36019)
17e91727b2 is described below
commit 17e91727b29448e46470a8dd4b5909a0bdf38eb2
Author: Kevin C <Ka...@users.noreply.github.com>
AuthorDate: Sat Dec 9 01:41:31 2023 -0800
Create latest log dir symlink as relative link (#36019)
So `logs/**/*` is self-contained and the symlink doesn't break for
exporting, build artifact, etc
---
airflow/utils/log/file_processor_handler.py | 7 ++++---
tests/utils/log/test_file_processor_handler.py | 4 ++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/airflow/utils/log/file_processor_handler.py b/airflow/utils/log/file_processor_handler.py
index 95c4ff5960..eade2eadfa 100644
--- a/airflow/utils/log/file_processor_handler.py
+++ b/airflow/utils/log/file_processor_handler.py
@@ -117,18 +117,19 @@ class FileProcessorHandler(logging.Handler):
log_directory = self._get_log_directory()
latest_log_directory_path = os.path.join(self.base_log_folder, "latest")
if os.path.isdir(log_directory):
+ rel_link_target = Path(log_directory).relative_to(Path(latest_log_directory_path).parent)
try:
# if symlink exists but is stale, update it
if os.path.islink(latest_log_directory_path):
- if os.readlink(latest_log_directory_path) != log_directory:
+ if os.path.realpath(latest_log_directory_path) != log_directory:
os.unlink(latest_log_directory_path)
- os.symlink(log_directory, latest_log_directory_path)
+ os.symlink(rel_link_target, latest_log_directory_path)
elif os.path.isdir(latest_log_directory_path) or os.path.isfile(latest_log_directory_path):
logging.warning(
"%s already exists as a dir/file. Skip creating symlink.", latest_log_directory_path
)
else:
- os.symlink(log_directory, latest_log_directory_path)
+ os.symlink(rel_link_target, latest_log_directory_path)
except OSError:
logging.warning("OSError while attempting to symlink the latest log directory")
diff --git a/tests/utils/log/test_file_processor_handler.py b/tests/utils/log/test_file_processor_handler.py
index e11ff35b0c..f50fc619ac 100644
--- a/tests/utils/log/test_file_processor_handler.py
+++ b/tests/utils/log/test_file_processor_handler.py
@@ -80,13 +80,13 @@ class TestFileProcessorHandler:
with time_machine.travel(date1, tick=False):
handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
assert os.path.islink(link)
- assert os.path.basename(os.readlink(link)) == date1
+ assert os.path.basename(os.path.realpath(link)) == date1
assert os.path.exists(os.path.join(link, "log1"))
with time_machine.travel(date2, tick=False):
handler.set_context(filename=os.path.join(self.dag_dir, "log2"))
assert os.path.islink(link)
- assert os.path.basename(os.readlink(link)) == date2
+ assert os.path.basename(os.path.realpath(link)) == date2
assert os.path.exists(os.path.join(link, "log2"))
def test_symlink_latest_log_directory_exists(self):