Owen-CH-Leung commented on code in PR #63519: URL: https://github.com/apache/airflow/pull/63519#discussion_r2931747268
########## airflow-e2e-tests/tests/airflow_e2e_tests/remote_log_elasticsearch_tests/test_remote_logging_elasticsearch.py: ########## @@ -0,0 +1,104 @@ +# 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 time +from datetime import datetime, timezone + +import pytest + +from airflow_e2e_tests.e2e_test_utils.clients import AirflowClient, get_elasticsearch_session + + +class TestRemoteLoggingElasticsearch: + airflow_client = AirflowClient() + dag_id = "example_xcom_test" + task_id = "bash_pull" + retry_interval_in_seconds = 5 + max_retries = 12 + target_index = "airflow-e2e-logs" + expected_message = "finished" + elasticsearch_url = "http://localhost:9200" + expected_log_id_prefix = f"{dag_id}-{task_id}-" + + def test_remote_logging_elasticsearch(self): + """Test that a DAG using remote logging to Elasticsearch completes successfully.""" + + self.airflow_client.un_pause_dag(TestRemoteLoggingElasticsearch.dag_id) + + resp = self.airflow_client.trigger_dag( + TestRemoteLoggingElasticsearch.dag_id, + json={"logical_date": datetime.now(timezone.utc).isoformat()}, + ) + run_id = resp["dag_run_id"] + state = self.airflow_client.wait_for_dag_run( + dag_id=TestRemoteLoggingElasticsearch.dag_id, + run_id=run_id, + ) + + assert state == "success", ( + f"DAG {TestRemoteLoggingElasticsearch.dag_id} did not complete successfully. Final state: {state}" + ) + + elasticsearch_session = get_elasticsearch_session() + matching_logs = [] + for _ in range(self.max_retries): + response = elasticsearch_session.post( + f"{self.elasticsearch_url}/{self.target_index}/_search", + json={ + "size": 200, + "query": {"match_all": {}}, + }, + ) + if response.status_code == 404: + time.sleep(self.retry_interval_in_seconds) + continue Review Comment: I don’t think we should manually handle 5xx in the polling loop. The request session already has retry configured for transient HTTP failures like 500/502/503/504. The loop here is for a different case: Elasticsearch can return a successful response, but the index or the expected log documents may not be ready yet. That is why I add handling logic for 404 and retry for "200 but no matching hits yet" -- 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]
