You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vincbeck (via GitHub)" <gi...@apache.org> on 2023/08/08 20:12:47 UTC

[GitHub] [airflow] vincbeck opened a new pull request, #33231: Improve fetching logs form AWS

vincbeck opened a new pull request, #33231:
URL: https://github.com/apache/airflow/pull/33231

   Fetching logs from AWS CloudWatch can take a lot of times or even fail when the log stream is old and no time boundary is specified when querying CloudWatch.
   
   Example: if you try to look at the logs of an old task on the Airflow UI, it can be very slow or even fail doing so.
   
   By setting `start_time` and `end_time` (`end_time` is the most important), it improves drastically the latency. I tested it with a 10 days old task and I could experience an improvement from 5 seconds to 1 second when fetching task logs from the UI.
   
   <!--
    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.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] vincbeck commented on a diff in pull request #33231: Improve fetching logs from AWS

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #33231:
URL: https://github.com/apache/airflow/pull/33231#discussion_r1288954740


##########
airflow/providers/amazon/aws/hooks/logs.py:
##########
@@ -60,6 +61,7 @@ def get_log_events(
         log_group: str,
         log_stream_name: str,
         start_time: int = 0,
+        end_time: int | None = None,

Review Comment:
   I can add one but to me, it is not necessary, we are just passing the value down to `get_cloudwatch_logs`. But since it had been called out by @o-nikolas as well, I'll add one



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] vincbeck commented on a diff in pull request #33231: Improve fetching logs from AWS

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #33231:
URL: https://github.com/apache/airflow/pull/33231#discussion_r1289070433


##########
airflow/providers/amazon/aws/hooks/logs.py:
##########
@@ -60,6 +61,7 @@ def get_log_events(
         log_group: str,
         log_stream_name: str,
         start_time: int = 0,
+        end_time: int | None = None,

Review Comment:
   Done
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] vandonr-amz commented on a diff in pull request #33231: Improve fetching logs from AWS

Posted by "vandonr-amz (via GitHub)" <gi...@apache.org>.
vandonr-amz commented on code in PR #33231:
URL: https://github.com/apache/airflow/pull/33231#discussion_r1288948715


##########
airflow/providers/amazon/aws/log/cloudwatch_task_handler.py:
##########
@@ -103,17 +106,29 @@ def _read(self, task_instance, try_number, metadata=None):
             log += local_log
             return log, metadata
 
-    def get_cloudwatch_logs(self, stream_name: str) -> str:
+    def get_cloudwatch_logs(self, stream_name: str, task_instance: TaskInstance) -> str:
         """
         Return all logs from the given log stream.
 
         :param stream_name: name of the Cloudwatch log stream to get all logs from
+        :param task_instance: the task instance to get logs about
         :return: string of all logs from the given log stream
         """
+        start_time = (
+            None if task_instance.start_date is None else datetime_to_epoch_utc_ms(task_instance.start_date)

Review Comment:
   nit: `start_time = None` violates type annotations (it's supposed to be an `int`, not an `int | None`)



##########
airflow/providers/amazon/aws/hooks/logs.py:
##########
@@ -72,7 +74,9 @@ def get_log_events(
 
         :param log_group: The name of the log group.
         :param log_stream_name: The name of the specific stream.
-        :param start_time: The time stamp value to start reading the logs from (default: 0).
+        :param start_time: The timestamp value to start reading the logs from (default: 0).

Review Comment:
   ```suggestion
           :param start_time: The timestamp value in ms to start reading the logs from (default: 0).
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] vincbeck commented on pull request #33231: Improve fetching logs form AWS

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #33231:
URL: https://github.com/apache/airflow/pull/33231#issuecomment-1671645608

   > Changes look good! But maybe some unit tests for the changes to `get_cloudwatch_logs` and maybe `get_log_events`?
   
   Good call! I added some unit tests for `get_cloudwatch_logs`. I dont think it is worth adding unit tests for `get_log_events`


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] vincbeck commented on a diff in pull request #33231: Improve fetching logs from AWS

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #33231:
URL: https://github.com/apache/airflow/pull/33231#discussion_r1288965245


##########
airflow/providers/amazon/aws/log/cloudwatch_task_handler.py:
##########
@@ -103,17 +106,29 @@ def _read(self, task_instance, try_number, metadata=None):
             log += local_log
             return log, metadata
 
-    def get_cloudwatch_logs(self, stream_name: str) -> str:
+    def get_cloudwatch_logs(self, stream_name: str, task_instance: TaskInstance) -> str:
         """
         Return all logs from the given log stream.
 
         :param stream_name: name of the Cloudwatch log stream to get all logs from
+        :param task_instance: the task instance to get logs about
         :return: string of all logs from the given log stream
         """
+        start_time = (
+            None if task_instance.start_date is None else datetime_to_epoch_utc_ms(task_instance.start_date)

Review Comment:
   Good call!



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] eladkal commented on a diff in pull request #33231: Improve fetching logs from AWS

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #33231:
URL: https://github.com/apache/airflow/pull/33231#discussion_r1288944532


##########
airflow/providers/amazon/aws/hooks/logs.py:
##########
@@ -60,6 +61,7 @@ def get_log_events(
         log_group: str,
         log_stream_name: str,
         start_time: int = 0,
+        end_time: int | None = None,

Review Comment:
   should there be also an updated test case in `TestAwsLogsHook`?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] o-nikolas merged pull request #33231: Improve fetching logs from AWS

Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas merged PR #33231:
URL: https://github.com/apache/airflow/pull/33231


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org