Skip to content

Wrong try_number after rescheduling makes remote logging store all the logs with wrong log_id #18080

Closed as not planned

Description

@johnny0120

Apache Airflow version

2.1.3 (latest released)

Operating System

Debian GNU/Linux 10 (buster)

Versions of Apache Airflow Providers

apache-airflow-providers-elasticsearch==2.0.2

Deployment

Other Docker-based deployment

Deployment details

1 master node with webserver, scheduler, flower and etc.
4 worker node, each with a celery worker process;
filebeat 7.6.2 as sidecar reading logs with pattern /opt/airflow/logs/**/*.log from the official docker image container

What happened

I have set up filebeat and elasticsearch for remote logging and it works well with normal operator or tasks.

But when I tried ExternalTaskSensor with mode='reschedule' and poke_interval=300 option, the log view from the webpage showed something like the following.

...
[2021-09-08 15:10:03,392] {taskinstance.py:1094} INFO - 
[2021-09-08 15:20:07,030] {taskinstance.py:1094} INFO - 
[2021-09-08 15:15:04,941] {taskinstance.py:1094} INFO - 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
[2021-09-08 15:10:03,392] {taskinstance.py:1095} INFO - Starting attempt 1 of 4
[2021-09-08 15:20:07,030] {taskinstance.py:1095} INFO - Starting attempt 1 of 4
[2021-09-08 15:15:04,941] {taskinstance.py:1095} INFO - Starting attempt 1 of 4
[2021-09-08 15:20:07,030] {taskinstance.py:1096} INFO - 
[2021-09-08 15:10:03,392] {taskinstance.py:1096} INFO - 
[2021-09-08 15:15:04,941] {taskinstance.py:1096} INFO - 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
[2021-09-08 15:10:03,402] {taskinstance.py:1114} INFO - Executing <Task(ExternalTaskSensor): 
[2021-09-08 15:20:07,041] {taskinstance.py:1114} INFO - Executing <Task(ExternalTaskSensor): 
[2021-09-08 15:15:04,950] {taskinstance.py:1114} INFO - Executing <Task(ExternalTaskSensor):
...

Apparently, the logs from different runs on different worker node, got pulled together, because they share the same try_number: 1, which means the log_id used to retrieve logs from remote storage are the same.

What you expected to happen

Option 1: Update or increase try_number after a task has been marked as up_for_reschedule, so that the log_id would be different by runs. This will probably solve some relevant issues from reschedule/try_number and log_id

Option 2: Fix the sensor mode, and do not use up_for_reschedule, maybe up_for_retry? But this would change the behaviors of all the sensor operator, seems like a big change

Option 3: Update the log location and its log_id, maybe include a reschedule_number besides the try_number, but this will need to change the log_id template, also seems like a big change

How to reproduce

Essential components

  1. filebeat and working elasticsearch cluster
  2. multiple worker nodes so that the logs with the same try_number may be created on different nodes
  3. Use ExternalTaskSensor with mode='reschedule' to sense an upperstream task that needs multiple reschedules to succeed

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. boring-cyborg commented on Sep 8, 2021

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  2. tanvn commented on Nov 11, 2021

    @tanvn
    Contributor

    I got the same issue today with version 2.2.1 (the latest)
    because the try_number is not changed when the task is marked as UP_FOR_SCHEDULE,
    my ExternalTaskSensor with a retries = 3 does not stop after 3 times and on_failure_callback never got called.
    (It ran until being marked as SUCCESS and the on_success_callback got called).
    I think the cause is the below code.

            # set state
            self.state = State.UP_FOR_RESCHEDULE
    
            # Decrement try_number so subsequent runs will use the same try number and write
            # to same log file.
            self._try_number -= 1
    

    https://github.com/apache/airflow/blob/main/airflow/models/taskinstance.py#L1673-L1678

    And IMHO, 👍 + 1 for

    Option 1: Update or increase try_number after a task has been marked as up_for_reschedule, so that the log_id would be different by runs. This will probably solve some relevant issues from reschedule/try_number and log_id

  3. uranusjr commented on Nov 15, 2021

    @uranusjr
    Member

    Does anyone happen to know if this is a recent regression? The -= 1 line referenced above is over three years old, so if this is a recent bug, it should likely be fixed elsewhere.

  4. potiuk commented on Nov 17, 2021

    @potiuk
    Member

    I think it might be regression. I am not very confident in this part of the code, but I do remember, that somewhere in airlfow internals try_num was actually one higher that it should have been for some obscure reasons and it was manually decreased in some cases. So if the "obscurity" has been fixed in one of the recent refactors/fixes - this might be the side effect.

  5. potiuk commented on Nov 17, 2021

    @potiuk
    Member

    @ashb @mik-laj - maybe you remember better ?

  6. ashb commented on Nov 17, 2021

    @ashb
    Member

    @ephraimbuddy ring any bells? I think we talked about this a while back

    Is it fixed already do you know?

  7. eladkal commented on Nov 5, 2022

    @eladkal
    Contributor

    I do remember, that somewhere in airlfow internals try_num was actually one higher that it should have been for some obscure reasons

    it's due to the difference between running task vs non running task see #26993 (comment)

  8. github-actions commented on Nov 6, 2023

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.

  9. github-actions commented on Dec 10, 2023

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions