You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "isaiahiruoha (via GitHub)" <gi...@apache.org> on 2025/08/01 23:08:39 UTC
[PR] Add system test for Lambda executor Dead Letter Queue (DLQ) processing [airflow]
isaiahiruoha opened a new pull request, #54042:
URL: https://github.com/apache/airflow/pull/54042
This PR adds a system test for AWS Lambda executor's Dead Letter Queue (DLQ) functionality, addressing a gap in test coverage for Lambda service-level failures.
Before, all Lambda executor system tests only covered the "happy path" where tasks execute successfully (whether the test ultimately passes or fails). However, the Lambda executor has unique handling for cases where the Lambda service itself fails to complete invocation (timeouts, memory limits, crashes, etc.). In these scenarios:
1. **Normal path**: Lambda completes → sends result to results queue → executor processes
2. **DLQ path**: Lambda fails at service level → AWS sends message to DLQ → executor processes DLQ message → marks task as failed
The test uses `executor_config` functionality (from [#53994](https://github.com/apache/airflow/pull/53994)) to implement a "poison pill" pattern:
1. **Task definition**: Uses `@task(executor_config={"poison_pill": True})` to flag a task for intentional failure
2. **Lambda handler**: Checks for poison pill flag and raises RuntimeError before any task execution
3. **DLQ trigger**: RuntimeError causes Lambda service failure → message sent to DLQ
4. **Verification**: Polls CloudWatch SQS metrics to confirm DLQ processing occurred
**Testing:** Tested locally on Lambda executor: Confirms complete DLQ flow works correctly
<!--
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-docs/05_pull_requests.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 [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/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
Re: [PR] Add system test for Lambda executor Dead Letter Queue (DLQ) processing [airflow]
Posted by "isaiahiruoha (via GitHub)" <gi...@apache.org>.
isaiahiruoha commented on code in PR #54042:
URL: https://github.com/apache/airflow/pull/54042#discussion_r2254796037
##########
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py:
##########
@@ -0,0 +1,121 @@
+# 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.
+from __future__ import annotations
+
+import os
+import time
+from datetime import datetime, timedelta, timezone
+from urllib.parse import urlparse
+
+import boto3
+
+from airflow.utils.trigger_rule import TriggerRule
+
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+ from airflow.sdk import DAG, chain, task
+else:
+ from airflow.decorators import task # type: ignore[attr-defined,no-redef]
+ from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef]
+ from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment]
+
+from system.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+DAG_ID = "test_lambda_executor_dlq"
+
+
+@task
+def verify_test_setup():
+ """Verify Lambda executor DLQ configuration is available"""
+ dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL")
+ print(f"Lambda executor DLQ URL: {dlq_url}")
+
+ parsed_url = urlparse(dlq_url)
+ dlq_queue_name = parsed_url.path.split("/")[-1]
+ return dlq_queue_name
+
+
+@task(executor_config={"poison_pill": True})
+def cause_lambda_failure():
+ return "This task is designed to fail at Lambda service level, injected within the function handler"
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def verify_dlq_activity(dlq_queue_name: str):
+ """Verify DLQ processing occurred by checking CloudWatch metrics"""
+
+ cloudwatch = boto3.client("cloudwatch")
+ # Try for up to 10 attempts (5 minutes total)
+ for attempt in range(10):
+ end_time = datetime.now(timezone.utc)
+ start_time = end_time - timedelta(minutes=5)
+ try:
+ received_response = cloudwatch.get_metric_statistics(
+ Namespace="AWS/SQS",
+ MetricName="NumberOfMessagesDeleted",
+ Dimensions=[{"Name": "QueueName", "Value": dlq_queue_name}],
+ StartTime=start_time,
+ EndTime=end_time,
+ Period=300,
+ Statistics=["Sum"],
+ )
+
+ total_deleted = sum(point["Sum"] for point in received_response["Datapoints"])
+ print(f"Messages deleted from DLQ: {total_deleted}")
+
+ if total_deleted > 0:
+ return "DLQ Processing Confirmed"
+ if attempt < 9:
+ time.sleep(30)
+ except Exception as e:
+ print(f"Error checking DLQ metrics: {e}")
+ raise AssertionError("FAIL: No DLQ activity detected after 5 minutes of polling")
+
+
+default_args = {
+ "execution_timeout": timedelta(minutes=15),
+}
Review Comment:
This is correct, after looking into it further, it do not need this functionality anymore. Because the poison pill function will simply return if it has failed to break the lambda function and then the verification task will fail afterwards. There is no need for a timeout argument.
--
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
Re: [PR] Add system test for Lambda executor Dead Letter Queue (DLQ) processing [airflow]
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on code in PR #54042:
URL: https://github.com/apache/airflow/pull/54042#discussion_r2249003630
##########
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py:
##########
@@ -0,0 +1,121 @@
+# 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.
+from __future__ import annotations
+
+import os
+import time
+from datetime import datetime, timedelta, timezone
+from urllib.parse import urlparse
+
+import boto3
+
+from airflow.utils.trigger_rule import TriggerRule
+
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+ from airflow.sdk import DAG, chain, task
+else:
+ from airflow.decorators import task # type: ignore[attr-defined,no-redef]
+ from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef]
+ from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment]
+
+from system.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+DAG_ID = "test_lambda_executor_dlq"
+
+
+@task
+def verify_test_setup():
+ """Verify Lambda executor DLQ configuration is available"""
+ dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL")
+ print(f"Lambda executor DLQ URL: {dlq_url}")
+
+ parsed_url = urlparse(dlq_url)
+ dlq_queue_name = parsed_url.path.split("/")[-1]
+ return dlq_queue_name
+
+
+@task(executor_config={"poison_pill": True})
+def cause_lambda_failure():
+ return "This task is designed to fail at Lambda service level, injected within the function handler"
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def verify_dlq_activity(dlq_queue_name: str):
+ """Verify DLQ processing occurred by checking CloudWatch metrics"""
+
+ cloudwatch = boto3.client("cloudwatch")
+ # Try for up to 10 attempts (5 minutes total)
+ for attempt in range(10):
+ end_time = datetime.now(timezone.utc)
+ start_time = end_time - timedelta(minutes=5)
+ try:
+ received_response = cloudwatch.get_metric_statistics(
+ Namespace="AWS/SQS",
+ MetricName="NumberOfMessagesDeleted",
+ Dimensions=[{"Name": "QueueName", "Value": dlq_queue_name}],
+ StartTime=start_time,
+ EndTime=end_time,
+ Period=300,
+ Statistics=["Sum"],
+ )
+
+ total_deleted = sum(point["Sum"] for point in received_response["Datapoints"])
+ print(f"Messages deleted from DLQ: {total_deleted}")
+
+ if total_deleted > 0:
+ return "DLQ Processing Confirmed"
+ if attempt < 9:
+ time.sleep(30)
+ except Exception as e:
+ print(f"Error checking DLQ metrics: {e}")
+ raise AssertionError("FAIL: No DLQ activity detected after 5 minutes of polling")
+
+
+default_args = {
+ "execution_timeout": timedelta(minutes=15),
+}
Review Comment:
This is applied to all tasks, we really just need it on the `cause_lambda_failure` task right?
##########
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py:
##########
@@ -0,0 +1,121 @@
+# 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.
+from __future__ import annotations
+
+import os
+import time
+from datetime import datetime, timedelta, timezone
+from urllib.parse import urlparse
+
+import boto3
+
+from airflow.utils.trigger_rule import TriggerRule
+
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+ from airflow.sdk import DAG, chain, task
+else:
+ from airflow.decorators import task # type: ignore[attr-defined,no-redef]
+ from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef]
+ from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment]
+
+from system.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+DAG_ID = "test_lambda_executor_dlq"
+
+
+@task
+def verify_test_setup():
+ """Verify Lambda executor DLQ configuration is available"""
+ dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL")
+ print(f"Lambda executor DLQ URL: {dlq_url}")
+
+ parsed_url = urlparse(dlq_url)
+ dlq_queue_name = parsed_url.path.split("/")[-1]
+ return dlq_queue_name
+
+
+@task(executor_config={"poison_pill": True})
+def cause_lambda_failure():
+ return "This task is designed to fail at Lambda service level, injected within the function handler"
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def verify_dlq_activity(dlq_queue_name: str):
+ """Verify DLQ processing occurred by checking CloudWatch metrics"""
+
+ cloudwatch = boto3.client("cloudwatch")
+ # Try for up to 10 attempts (5 minutes total)
+ for attempt in range(10):
+ end_time = datetime.now(timezone.utc)
+ start_time = end_time - timedelta(minutes=5)
+ try:
+ received_response = cloudwatch.get_metric_statistics(
+ Namespace="AWS/SQS",
+ MetricName="NumberOfMessagesDeleted",
+ Dimensions=[{"Name": "QueueName", "Value": dlq_queue_name}],
+ StartTime=start_time,
+ EndTime=end_time,
+ Period=300,
+ Statistics=["Sum"],
+ )
+
+ total_deleted = sum(point["Sum"] for point in received_response["Datapoints"])
+ print(f"Messages deleted from DLQ: {total_deleted}")
+
+ if total_deleted > 0:
+ return "DLQ Processing Confirmed"
Review Comment:
```suggestion
if total_deleted > 0:
print(f"Messages deleted from DLQ: {total_deleted}")
return "DLQ Processing Confirmed"
print(f"No messages detected in DLQ yet")
```
##########
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py:
##########
@@ -0,0 +1,121 @@
+# 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.
+from __future__ import annotations
+
+import os
+import time
+from datetime import datetime, timedelta, timezone
+from urllib.parse import urlparse
+
+import boto3
+
+from airflow.utils.trigger_rule import TriggerRule
+
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+ from airflow.sdk import DAG, chain, task
+else:
+ from airflow.decorators import task # type: ignore[attr-defined,no-redef]
+ from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef]
+ from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment]
+
+from system.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+DAG_ID = "test_lambda_executor_dlq"
+
+
+@task
+def verify_test_setup():
+ """Verify Lambda executor DLQ configuration is available"""
+ dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL")
+ print(f"Lambda executor DLQ URL: {dlq_url}")
+
+ parsed_url = urlparse(dlq_url)
+ dlq_queue_name = parsed_url.path.split("/")[-1]
+ return dlq_queue_name
+
+
+@task(executor_config={"poison_pill": True})
+def cause_lambda_failure():
+ return "This task is designed to fail at Lambda service level, injected within the function handler"
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def verify_dlq_activity(dlq_queue_name: str):
+ """Verify DLQ processing occurred by checking CloudWatch metrics"""
+
+ cloudwatch = boto3.client("cloudwatch")
+ # Try for up to 10 attempts (5 minutes total)
+ for attempt in range(10):
+ end_time = datetime.now(timezone.utc)
+ start_time = end_time - timedelta(minutes=5)
+ try:
+ received_response = cloudwatch.get_metric_statistics(
+ Namespace="AWS/SQS",
+ MetricName="NumberOfMessagesDeleted",
+ Dimensions=[{"Name": "QueueName", "Value": dlq_queue_name}],
+ StartTime=start_time,
+ EndTime=end_time,
+ Period=300,
+ Statistics=["Sum"],
+ )
+
+ total_deleted = sum(point["Sum"] for point in received_response["Datapoints"])
+ print(f"Messages deleted from DLQ: {total_deleted}")
+
+ if total_deleted > 0:
+ return "DLQ Processing Confirmed"
+ if attempt < 9:
+ time.sleep(30)
+ except Exception as e:
+ print(f"Error checking DLQ metrics: {e}")
Review Comment:
Just let the exception bubble up I reckon, this log doesn't add too much extra/useful context.
##########
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py:
##########
@@ -0,0 +1,121 @@
+# 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.
+from __future__ import annotations
+
+import os
+import time
+from datetime import datetime, timedelta, timezone
+from urllib.parse import urlparse
+
+import boto3
+
+from airflow.utils.trigger_rule import TriggerRule
+
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+ from airflow.sdk import DAG, chain, task
+else:
+ from airflow.decorators import task # type: ignore[attr-defined,no-redef]
+ from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef]
+ from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment]
+
+from system.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+DAG_ID = "test_lambda_executor_dlq"
+
+
+@task
+def verify_test_setup():
+ """Verify Lambda executor DLQ configuration is available"""
+ dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL")
+ print(f"Lambda executor DLQ URL: {dlq_url}")
+
+ parsed_url = urlparse(dlq_url)
+ dlq_queue_name = parsed_url.path.split("/")[-1]
+ return dlq_queue_name
+
+
+@task(executor_config={"poison_pill": True})
Review Comment:
Maybe leave a comment above that our Lambda app.py handler code is configured to look for this poison pill.
--
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
Re: [PR] Add system test for Lambda executor Dead Letter Queue (DLQ) processing [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #54042:
URL: https://github.com/apache/airflow/pull/54042
--
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