Skip to content

Commit 1d3e2fd

Browse files
committed
test: Add Airflow 3.2.1
Note: The metrics test broke because airflow no longer exports metrics from the webserver role. Instead, we check completion via the API.
1 parent aa855ab commit 1d3e2fd

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

tests/templates/kuttl/commons/metrics.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ def assert_metric(role, role_group, metric):
2525
return metric in metric_response.text
2626

2727

28+
# Check if dag run state is "success"
29+
# TODO: in future, we could wait on it.
30+
# See: https://airflow.apache.org/docs/apache-airflow/3.1.6/stable-rest-api-ref.html#operation/wait_dag_run_until_finished
31+
def assert_completion(rest_url, headers, dag_id, dag_run_id):
32+
dag_run_response = requests.get(
33+
f"{rest_url}/dags/{dag_id}/dagRuns/{dag_run_id}", headers=headers
34+
)
35+
dag_run_state = dag_run_response.json()["state"]
36+
print(f"DAG RUN STATE: {dag_run_state}")
37+
return dag_run_state == "success"
38+
39+
2840
def metrics_v3(role_group: str) -> None:
2941
now = datetime.now(timezone.utc)
3042
ts = now.strftime("%Y-%m-%dT%H:%M:%S.%f") + now.strftime("%z")
@@ -66,10 +78,14 @@ def metrics_v3(role_group: str) -> None:
6678
response = requests.patch(
6779
f"{rest_url}/dags/{dag_id}", headers=headers, json={"is_paused": False}
6880
)
81+
6982
# trigger DAG
7083
response = requests.post(
7184
f"{rest_url}/dags/{dag_id}/dagRuns", headers=headers, json=dag_data
7285
)
86+
dag_run_id = response.json()["dag_run_id"]
87+
88+
print(f"DAG RUN ID: {dag_run_id}")
7389

7490
# Test the DAG in a loop. Each time we call the script a new job will be started: we can avoid
7591
# or minimize this by looping over the check instead.
@@ -79,24 +95,13 @@ def metrics_v3(role_group: str) -> None:
7995
assert response.status_code == 200, "DAG run could not be triggered."
8096
# Wait for the metrics to be consumed by the statsd-exporter
8197
time.sleep(5)
82-
# (disable line-break flake checks)
98+
heartbeat_metric = "airflow_scheduler_heartbeat"
99+
dag_run_success_count_metric = f"airflow_dagrun_duration_success_{dag_id}_count"
83100
if (
84-
(assert_metric("scheduler", role_group, "airflow_scheduler_heartbeat"))
85-
and (
86-
assert_metric(
87-
"webserver",
88-
role_group,
89-
"airflow_task_instance_created_BashOperator",
90-
)
91-
) # noqa: W503, W504
92-
and (
93-
assert_metric(
94-
"scheduler",
95-
role_group,
96-
"airflow_dagrun_duration_success_example_trigger_target_dag_count",
97-
)
98-
)
99-
): # noqa: W503, W504
101+
assert_completion(rest_url, headers, dag_id, dag_run_id)
102+
and assert_metric("scheduler", role_group, heartbeat_metric)
103+
and assert_metric("scheduler", role_group, dag_run_success_count_metric)
104+
):
100105
break
101106
time.sleep(10)
102107
loop += 1

tests/test-definition.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ dimensions:
1010
- 2.9.3
1111
- 3.0.6
1212
- 3.1.6
13+
- 3.2.1
1314
# To use a custom image, add a comma and the full name after the product version
1415
# - x.x.x,oci.stackable.tech/sandbox/airflow:x.x.x-stackable0.0.0-dev
1516
- name: airflow-latest
1617
values:
17-
- 3.1.6
18+
- 3.2.1
1819
# To use a custom image, add a comma and the full name after the product version
1920
# - x.x.x,oci.stackable.tech/sandbox/airflow:x.x.x-stackable0.0.0-dev
2021
- name: opa-latest

0 commit comments

Comments
 (0)