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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
