Skip to content

Fix broken dag_processing.total_parse_time metric#62128

Merged
kaxil merged 1 commit into
apache:mainfrom
nickstenning:fix-dag-processor-metrics
Feb 20, 2026
Merged

Fix broken dag_processing.total_parse_time metric#62128
kaxil merged 1 commit into
apache:mainfrom
nickstenning:fix-dag-processor-metrics

Conversation

@nickstenning

@nickstenning nickstenning commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

DagFileProcessorManager has been emitting a nonsense value for dag_processing.total_parse_time since 8774f28, which reversed the order in which emit_metrics and prepare_file_queue (then called prepare_file_path_queue) were called.

As prepare_file_queue was responsible for resetting the value of self._parsing_start_time, the assumption made by emit_metrics was that it would be called once the file queue had been cleared, but crucially before prepare_file_queue was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all since the last time the metric was emitted. If no work was due, we'd gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to accidentally break in future:

  • self._parsing_start_time may be reset whenever files are added to the queue, if it was not set already.

  • metrics are emitted when prepare_file_queue is called -- when the queue is empty -- but only if self._parsing_start_time is set, meaning only if we've actually parsed any files since the last time metrics were emitted.

Together, this means we should now emit metrics once per parsing loop. I've added a test which fails on main and passes on this branch.

Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
@nickstenning nickstenning force-pushed the fix-dag-processor-metrics branch from 09fc07d to 45c5d57 Compare February 20, 2026 14:35
@nickstenning

Copy link
Copy Markdown
Contributor Author

Updated with a test and some slightly more invasive fixes, because it turns out this was even more broken than I thought! @kaxil PTAL.

Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
Comment thread airflow-core/src/airflow/dag_processing/manager.py Outdated
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.
@nickstenning nickstenning force-pushed the fix-dag-processor-metrics branch from 45c5d57 to 0c3696a Compare February 20, 2026 20:02
@nickstenning

Copy link
Copy Markdown
Contributor Author

Thanks for re-review @kaxil. Should be ready to merge once CI passes.

@kaxil kaxil added this to the Airflow 3.1.8 milestone Feb 20, 2026
@nickstenning

Copy link
Copy Markdown
Contributor Author

If someone could rerun the tests that would be ace. Looks like a flake to me.

@kaxil kaxil merged commit 57a7c64 into apache:main Feb 20, 2026
69 of 70 checks passed
@nickstenning nickstenning deleted the fix-dag-processor-metrics branch February 21, 2026 16:17
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.
vatsrahul1001 pushed a commit that referenced this pull request Mar 3, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)
vatsrahul1001 pushed a commit that referenced this pull request Mar 3, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)
vatsrahul1001 pushed a commit that referenced this pull request Mar 3, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)
vatsrahul1001 pushed a commit that referenced this pull request Mar 3, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Mar 3, 2026
vatsrahul1001 added a commit that referenced this pull request Mar 3, 2026
…) (#62764)

* Fix broken `dag_processing.total_parse_time` metric (#62128)

DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)

* fix static checks

---------

Co-authored-by: Nick Stenning <nick@whiteink.com>
vatsrahul1001 added a commit that referenced this pull request Mar 4, 2026
…) (#62764)

* Fix broken `dag_processing.total_parse_time` metric (#62128)

DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.

(cherry picked from commit 57a7c64)

* fix static checks

---------

Co-authored-by: Nick Stenning <nick@whiteink.com>
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 2026
DagFileProcessorManager has been emitting a nonsense value for
`dag_processing.total_parse_time` since 8774f28, which reversed the
order in which `emit_metrics` and `prepare_file_queue` (then called
`prepare_file_path_queue`) were called.

As `prepare_file_path_queue` was responsible for resetting the value of
`self._parsing_start_time`, the assumption made by `emit_metrics` was
that it would be called once the file queue had been cleared, but
crucially before `prepare_file_queue` was called to refill the queue.

Additionally, there was no guarantee that we'd parsed any files at all
since the last time the metric was emitted. If no work was due, we'd
gladly emit near-zero metrics every time around the while loop.

I've rearranged things in such a way that I hope will be harder to
accidentally break in future:

- `self._parsing_start_time` may be reset whenever files are added to
  the queue, if it was not set already.

- metrics are emitted when `prepare_file_queue` is called -- when the
  queue is empty -- but only if `self._parsing_start_time` is set,
  meaning only if we've actually parsed any files since the last time
  metrics were emitted.

Together, this means we should now emit metrics once per parsing loop.
I've added a test which fails on main and passes on this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants