Skip to content

Fix: metrics fix + queue timeout increase - #499

Open
ividito wants to merge 3 commits into
devfrom
fix/airflow3-autoscaling-is-stale
Open

Fix: metrics fix + queue timeout increase#499
ividito wants to merge 3 commits into
devfrom
fix/airflow3-autoscaling-is-stale

Conversation

@ividito

@ividito ividito commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Fix a deprecation in the metrics container. Also increase the default queue timeout - this was impacting backfill tasks, which were taking extra time as a result of migrating in the middle of a fires ingest. There will be an upstream PR to align the SQS settings with this new value - NASA-IMPACT/self-managed-apache-airflow#40

The timeout change has already been applied to dev via the console.

Airflow 3 removed the DagModel.is_active column, so the autoscaling loop in
put_airflow_worker_autoscaling_metric_data.py raised AttributeError on its
first iteration and the metrics ECS service crash-looped (exit 1 every ~100s).

The script scales the worker service directly rather than publishing a metric,
so both scale-up and scale-down were dead and workers stayed pinned at
desired=1. Observed on both sm2a-dev and sm2a-sit.

is_stale is the inverse of the old is_active: a DAG no longer present in its
bundle is marked stale.

Note: only valid on Airflow 3 - do not merge to a branch still on 2.10.5.
SQS made messages visible again after 30s (the AWS default, which the sm2a
module leaves unset on aws_sqs_queue). Any task running longer than that was
redelivered, and a second worker attempted to start the same task instance.

On Airflow 2 the duplicate was tolerated. On Airflow 3 the Task Execution API
rejects the second start with `invalid_state`, the Celery executor reports the
task as failed, and the scheduler kills the still-healthy original run. Observed
on sm2a-dev: vector-eis-fedsoutput-lfarchive/ingest_vector_task failed at the
30s mark while actively processing, having succeeded on 2.10.5 at 11 minutes.

Because predefined_queues is configured, kombu does not create the queue, so
this setting must be paired with raising the SQS queue's VisibilityTimeout
attribute - that is what actually governs redelivery here.
Matches the value applied to the sm2a-dev SQS queue attribute, and lines up
with Celery's own documented default. Long enough for the observed worst case
(vector ingest at ~11m) with headroom.
@ividito
ividito deployed to development August 14, 2026 19:08 — with GitHub Actions Active
@ividito
ividito force-pushed the fix/airflow3-autoscaling-is-stale branch from bf181c2 to 8302f1c Compare August 14, 2026 19:08
@ividito
ividito deployed to development August 14, 2026 19:09 — with GitHub Actions Active
@ividito
ividito requested a review from a team August 14, 2026 19:18
# Must exceed the longest task runtime, or SQS redelivers mid-run and the duplicate
# delivery fails the task on Airflow 3. The queue's own VisibilityTimeout attribute
# must match, since predefined_queues means kombu does not create the queue.
VISIBILITY_TIMEOUT = 1800 # 30m; SQS allows up to 43200

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NASA-IMPACT/self-managed-apache-airflow#40 is what addresses this through Terraform

@ividito
ividito deployed to development August 14, 2026 20:31 — with GitHub Actions Active
DagModel.is_active.is_(True),
# Airflow 3 removed the DagModel.is_active column; is_stale is its
# inverse (a DAG missing from its bundle is marked stale).
DagModel.is_stale.is_(False),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Not sure where that method gets used, but it looks like it returns return not self.is_stale. DagModel.is_active is definitely gone.

@botanical botanical left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question but non-blocking

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants