seanghaeli commented on code in PR #73580:
URL: https://github.com/apache/airflow/pull/73580#discussion_r4215189260


##########
airflow-core/src/airflow/utils/log/callback_log_reader.py:
##########
@@ -0,0 +1,110 @@
+# 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.
+"""Reader for callback execution logs stored in remote or local storage."""
+
+from __future__ import annotations
+
+import os
+import re
+from collections.abc import Generator
+from contextlib import suppress
+from pathlib import Path
+from typing import TYPE_CHECKING
+
+from airflow.configuration import conf
+from airflow.utils.log.file_task_handler import (
+    FileTaskHandler,
+    StructuredLogMessage,
+    _get_compatible_log_stream,
+    _interleave_logs,
+)
+
+if TYPE_CHECKING:
+    from airflow._shared.logging.remote import LogSourceInfo, RawLogStream, 
StreamingLogResponse
+
+_SAFE_PATH_COMPONENT = re.compile(r"[A-Za-z0-9._:+\-~@]+")
+
+
+def validate_log_path_component(component: str) -> str:
+    """Validate a single log path component, raising ValueError if it could 
escape the log folder."""
+    if component in (".", "..") or not 
_SAFE_PATH_COMPONENT.fullmatch(component):
+        raise ValueError(f"Invalid log path component: {component!r}")
+    return component
+
+
+def read_callback_log(

Review Comment:
   > Just to be sure I understand because I think this is important. You are 
using the task log if it is available to log the callback logs, and as a 
fallback use the local system (a file). Am I correct?
   
   Correct
   
   I see your point about generalizing the mechanism of `read_callback_log`. 
I've now called that generalized mechanism `read_logs_at_paths`. I think it's a 
fairly light change so for now I'm keeping it within this PR, but let me know 
if you prefer that I split it out into another PR.



-- 
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]

Reply via email to