Page MenuHomePhabricator

Upgrade airflow-analytics-test to 3.3.x
Closed, ResolvedPublic

Description

We are upgrading Airflow to version 3.3.x, mostly for security reasons, as Airflow 2.x is not supported anymore. Unfortunately, there are lots of APIs changes. This task is tracking the upgrade of analytics-test instance, as defined in Gitlab in airflow-dags/analytics_test and Gerrit in deployment-charts/.../airflow-analytics-test.

Most of the changes are tracked as subtasks of T423248.

Stages

[] Testing the Dags in airflow-devenv to figure out the scope (see Accessing Airflow 3).
[] Code upgrades to make sure most of the airflow-dags codebase is working
[] Validation of the analytics-test instance in airflow-devenv
[] Planning the switchover

PoCs for the analytics-test instance are:

Random cleanup

  • Delete annotate_oomed_skein_task_instances (no longer needed)

Details

Related Changes in Gerrit:
Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
Refine: scope map_index_template to mapped tasksrepos/data-engineering/airflow-dags!2774ryankemperT435477-refine-map-indexmain_airflow_3.3
Customize query in GitLab

Event Timeline

atsuko triaged this task as Medium priority.
atsuko changed the task status from Open to In Progress.Aug 21 2026, 5:58 PM
atsuko added a subscriber: xcollazo.

@xcollazo:
most folks from DPE could help on this.

The great thing about analytics-test is that it runs on its own isolated Hadoop instance (has its own HDFS / Yarn / etc.) so anything you do there will not affect anything in production.

Thus, I would image that you could attempt to upgrade that instance fully to Airflow 3 first to get many bugs taken care of before moving to other instances. All other instances are production, with the exception of test-k8s which is a hybrid, although I think the dump jobs have been moved elsewhere?

I’m on OpsWeek most of next week so happy to help with anything else.

More info on Hadoop Test cluster at https://wikitech.wikimedia.org/wiki/Data_Platform/Systems/Hadoop/Test

RKemper subscribed.

Met with Atsuko to get the rundown; I'll be handling the DPE SRE side of this

Spun up airflow-devenv like so: airflow-devenv create --branch main_airflow_3.3 --extra-values values-airflow3.yaml -d analytics_test

11 dags import fine, 2 files have parse/import errors:

  • analytics_test/dags/maintenance/db_cleaner_dag.py fails at import bc wmf_airflow_common/factories/db_cleaner_dag_factory.py does from airflow.settings import engine, but settings.engine is gone in airflow 3 (T434896)
  • analytics_test/dags/refine/refine_to_hive_hourly_dag.py fails bc our pool helper reads the database during DAG parsing, whereas airflow 3 parses DAG files w/o DB access
    • this issue is broader than analytics-test so I'll post a more detailed breakdown to T434283

Moving on to the DAGs themselves, I started with annotate_oomed_skein_task_instances; it died with RuntimeError: Direct database access via the ORM is not allowed in Airflow 3.0, also predicted by T434896

Haven't ran any of the other DAGs yet

annotate_oomed_skein_task_instances can be dropped I think. It was more a thought experiment than anything else.

annotate_oomed_skein_task_instances can be dropped I think. It was more a thought experiment than anything else.

Great, I'll make that part of this task.

(FWIW, it's not causing any extra work on our end, the DB failure was already known to us, and has to be fixed anyway. But sounds like we want to yeet this DAG regardless)

This comment was removed by atsuko.

Tested test_docker_image_fsspec in the Airflow 3.3.1 devenv. Both HDFS sensors and the DAG run succeeded

One setup issue: airflow-devenv create -d analytics_test still selected production Hadoop configuration. I applied values-analytics-test.yaml to the existing devenv and verified test-cluster routing before the successful run

Tried aqs_hourly_test yesterday, the shared sensor helpers still import airflow_client.client.model and airflow_client.client.model_utils

e.g.:

ModuleNotFoundError: No module named 'airflow_client.client.model' and ModuleNotFoundError: No module named 'airflow_client.client.model_utils'

This is the same issue in https://phabricator.wikimedia.org/T436269

@RKemper Can you please post traceback? .model is removed from apache-airflow-client==3.3.1. I have this problem as well, I'll post the guidance how to unblock in meanwhile.

@atsuko

DAG: aqs_hourly_test
File: dags/aqs/aqs_hourly_dag.py
Airflow: 3.3.1
apache-airflow-client: 3.3.1

Traceback:

  File "/opt/airflow/dags/airflow_dags/wmf_airflow_common/sensors/rest_external_task.py", line 13, in <module>
    from wmf_airflow_common.sensors.rest_helper import (
  File "/opt/airflow/dags/airflow_dags/wmf_airflow_common/sensors/rest_helper.py", line 8, in <module>
    from airflow_client.client.model.dag import DAG
ModuleNotFoundError: No module named 'airflow_client.client.model'

@RKemper this error with airflow_client.client.model should be fixed now in main_airflow_3.3.

Pool patch merged and working in my local devenv. I also tried refine_to_hive_hourly_test which was previously blocked on the pool issue, and it gets past that step now. I did hit a separate LocalExecutor vs KubernetesExecutor mismatch in the devenv, but that occurs after the pool creation

@RKemper do you know what is the safe way to test the job? there are options how to go with it in T435172. We can try fixing the job options, or I maybe will be able to update the version for every job.

Pool patch merged and working in my local devenv. I also tried refine_to_hive_hourly_test which was previously blocked on the pool issue, and it gets past that step now. I did hit a separate LocalExecutor vs KubernetesExecutor mismatch in the devenv, but that occurs after the pool creation

@RKemper do you know what is the safe way to test the job? there are options how to go with it in T435172. We can try fixing the job options, or I maybe will be able to update the version for every job.

AFAICT the spark stuff won't be an issue (launches through skein which will take the cluster's Spark 3.1.2)

Next steps are overriding output_database / output_tables_base_location to point to my own hive db/path so I can test the hive/hdfs side is working without clobbering the airflow-analytics-test instance's writes to hive/hdfs, then run the DAG on one hour of data (else with catchup=True it's going to try to process a massive backlog)

Now that we know that

  1. most of the code passing the tests correctly as CI is unblocked,
  2. Pools are upgraded,
  3. analytics-test runs on its own isolated Hadoop instance (has its own HDFS / Yarn / etc.) so anything you do there will not affect anything in production

we can probably attempt upgrading it to Airflow 3 without full validation in devenv, and with the benefit of having working database we can validate the DAGs in it, which will unblock analytics and main clusters.

@RKemper @xcollazo what do you think? it might require a few days of semi-intensive fixing forward, but I think I can take on this in my timezone. Meanwhile, Ryan can collaborate with Xabriel in the US timezones.

atsuko updated the task description. (Show Details)

@RKemper @xcollazo what do you think? it might require a few days of semi-intensive fixing forward, but I think I can take on this in my timezone. Meanwhile, Ryan can collaborate with Xabriel in the US timezones.

+1 from my side. Happy to jump on calls as needed.

Note: @BTullis is doing a demo on airflow-analytics-test on Tuesday, will need to provide some way to run old version in devenv.

Note: @BTullis is doing a demo on airflow-analytics-test on Tuesday, will need to provide some way to run old version in devenv.

Might be easier to just keep it unupgraded for european Tuesday and then we just start the cutover in (my) tuesday morning?

Yup, let's start cutover after the demo. I was mostly testing dumps today.

Change #1357219 had a related patch set uploaded (by Ryan Kemper; author: Ryan Kemper):

[operations/deployment-charts@master] airflow-analytics-test: upgrade to Airflow 3.3

https://gerrit.wikimedia.org/r/1357219

Upgrade plan

Pre-requisite

Upgrade

  • Disable all DAGs
  • Remove webserver and scheduler deployments
kube-env airflow-analytics-test-deploy dse-k8s-eqiad
kubectl delete deployment airflow-webserver
kubectl delete deployment airflow-scheduler

Cleanup

  • It will be impossible to login with old cookie, remove the old cookie from browser
  • Re-enable DAGs
  • Delete Kerberos service users

Mentioned in SAL (#wikimedia-operations) [2026-10-20T15:48:30Z] <ryankemper> T435477 [airflow-analytics-test] gearing up to start upgrade to Airflow 3.3, pausing all associated DAGs shortly

Mentioned in SAL (#wikimedia-operations) [2026-10-20T15:54:22Z] <ryankemper> T435477 [airflow-analytics-test] all associated DAGs paused

Change #1357219 merged by jenkins-bot:

[operations/deployment-charts@master] airflow-analytics-test: upgrade to Airflow 3.3

https://gerrit.wikimedia.org/r/1357219

Mentioned in SAL (#wikimedia-operations) [2026-10-20T17:02:57Z] <ryankemper> T435477 [airflow-analytics-test] upgrade complete; all previously-unpaused DAGs have been unpaused again. ofc, we'll still watch for anything weird that breaks over the next couple days

This phase is done. I think Needs Review is probably the most logical workboard state, since this ticket doesn't feel done-done until we have ran in the new airflow 3.3 configuration for a day or two

Upgrade commands

(Partially a log of what we ran, and partially a guide for future instances' upgrades to airflow 3.3)

The commands of course run on deploy1003

Pre-requisite

  • Review airflow-analytics-test: upgrade to Airflow 3.3. For another instance it's the same change: a symlink to _airflow_common_/values-airflow3-production.yaml and one line in the instance's helmfile.yaml
  • Note what DAGs are enabled
kube_env airflow-analytics-test-deploy dse-k8s-eqiad
SCHED=$(kubectl get pods -o name | grep scheduler | head -1 | cut -d/ -f2); echo "$SCHED"
kubectl exec "$SCHED" -c airflow-production -- airflow dags list -o json > ~/dags-before.json
jq -r '.[] | select(.is_paused == "False") | .dag_id' ~/dags-before.json > ~/dags-enabled.txt

(On 2.11 is_paused is the string "False", not a boolean)

Upgrade

kubectl exec "$SCHED" -c airflow-production -- airflow dags pause -y --treat-dag-id-as-regex '.*'
kubectl exec "$SCHED" -c airflow-production -- airflow dags list

Pausing doesn't stop runs that are already going. We didn't wait for them, and they picked up again on 3.3 after the upgrade

  • Remove webserver and scheduler deployments
kubectl delete deployment airflow-webserver airflow-scheduler
git -C /srv/deployment-charts log -1 --oneline
charlie --services_dir dse-k8s-services --service airflow-analytics-test diff
charlie --services_dir dse-k8s-services --service airflow-analytics-test apply
kubectl get pods -w

The first command checks that the merged change has reached deploy1003. The webserver pod runs airflow db migrate and the other pods wait for it. The kerberos pod doesn't wait, so it restarted twice before the migration finished and then came up fine

Cleanup

  • It will be impossible to login with old cookie, remove the old cookie from browser
  • Check the new version, import errors and DAG list (the scheduler pod has a new name)
SCHED=$(kubectl get pods -o name | grep scheduler | head -1 | cut -d/ -f2); echo "$SCHED"
kubectl exec "$SCHED" -c airflow-production -- airflow version
kubectl exec "$SCHED" -c airflow-production -- airflow dags list-import-errors
kubectl exec "$SCHED" -c airflow-production -- airflow dags list
  • Re-enable DAGs. Unpause by name, since the regex would also unpause the DAGs that were off before
kubectl exec "$SCHED" -c airflow-production -- airflow dags unpause <dag_id>

We went one at a time, starting with the DAGs that had runs in flight. To do them all at once:

for d in $(cat ~/dags-enabled.txt); do kubectl exec "$SCHED" -c airflow-production -- airflow dags unpause "$d"; done
  • Announce the end in #data-engineering-team slack and SAL
  • Delete Kerberos service users (the airflow users created so services could call the 2.11 API with kerberos; 3.3 doesn't use them)