Page MenuHomePhabricator

Upgrade airflow-wikidata 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 wikidata instance, as defined in Gitlab in airflow-dags/wikidata and Gerrit in deployment-charts/.../airflow-wikidata.

Most of the changes are tracked as subtasks of T423248.

Stages

  • Ensure that all DAGs are serialisable in Airflow 3
  • Code upgrades to make sure most of the airflow-dags codebase is working
    • Code uses SLA, upgrade and test T434642
  • Testing the Dags in airflow-devenv to figure out the scope (see Accessing Airflow 3).
    • wdqs_external_queries_rollup_daily: failed on permissions, I take it as positive signal, as we need to successfully run Spark to get to this error (will retry after copying test tables to my hdfs user)
    • table_maintenance_iceberg_monthly
    • wdqs_wikidata_data_reload: disabled for now
  • Switchover (planned)
  • Revalidation of the wikidata instance in prod

PoCs for the wikidata instance are:

Details

Event Timeline

atsuko triaged this task as Medium priority.
atsuko changed the task status from Open to In Progress.Oct 14 2026, 11:00 AM

@trueg @lerickson I'm planning to upgrade airfow-wikidata on Airlfow 3 soon. For the upgrade, we are generally want to test that DAGs are operating normally in airflow-devenv before actually upgrading the instance. Can you please advise me if there is the way to test wdqs_external_queries_rollup_daily and wdqs_wikidata_data_reload DAGs without modifying production data?

Hi @atsuko !
For wdqs_wikidata_data_reload, no, there is no way to test it in dev. However, its output isn't used for anything just yet, so running it in prod is not risky.

For wdqs_external_queries_rollup_daily, yes, this should be possible. I'll get back to you later today with exactly what to do.

Hi again @atsuko , following up from earlier:

I created some toy tables in HDFS with fake data that you can use for testing this DAG. You'll need to update a couple of the DagProperties variables in the UI to use them. Here's the fully updated Val field in the variables editor that I'd recommend using:

{
  "hive_event_wdqs_external_sparql_query": "lerickson.fake_logs_table",
  "iceberg_wikidata_wdqs_external_queries_by_user_agent_daily": "lerickson.wdqs_external_queries_by_user_agent_daily",
  "hql_wdqs_external_queries_by_user_agent_daily": "https://gitlab.discovery.wmnet:8443/repos/wikidata-platform/analytics/-/raw/e64d193db0d3fe73e63cc1dcba7e0b67f0d73ffb/hql/airflow/wdqs_external_queries_by_user_agent_daily.hql",
  "start_date": "2025-12-22T00:00:00",
  "sla": "P2D",
  "alerts_email": "lerickson@wikimedia.org",
  "success_email_recipient_list": [
    "lerickson@wikimedia.org"
  ],
  "tags": [
    "daily",
    "requires_event_wdqs_external_sparql_query",
    "uses_hql"
  ]
}

(You can use my email address in alerts_email and success_email_recipient_list, I don't mind, or you can change it to your own.)

The important things to override are hive_event_wdqs_external_sparql_query and iceberg_wikidata_wdqs_external_queries_by_user_agent_daily. Depending on whether I've merged https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2765 by the time you run this, you may or may not need to update hql_wdqs_external_queries_by_user_agent_daily (that MR sets it to this value).

The source table lerickson.fake_logs_table just has a few totally fake entries in it, feel free to add more if you like. I can give you more of the SQL invocations if you need so you don't need to reverse-engineer them, just let me know if you want any of the commands I used.

Unfortunately no data will actually get copied over to the destination because the query in question only copies over data for user-agents with >1000 queries and I didn't generate that many test data entries. But let me know if you want me to. If you're just checking that the DAG runs successfully, then maybe the actual spark data transfer isn't important to validate.

Let me know if you need anything else!

DO NOT UNPAUSE or TEST wdqs_wikidata_data_reload

Tested wdqs_external_queries_rollup_daily and table_maintenance_iceberg_* with a temporary table.

Hey @atsuko

@trueg @lerickson I'm planning to upgrade airfow-wikidata on Airlfow 3 soon. For the upgrade, we are generally want to test that DAGs are operating normally in airflow-devenv before actually upgrading the instance. Can you please advise me if there is the way to test wdqs_external_queries_rollup_daily and wdqs_wikidata_data_reload DAGs without modifying production data?

We chatted about this at collab. You can test (parts) of wdqs_wikidata_data_reload on an airflow dev instance, but it's cumbersome. The tricky part could be an RDF export bit than spins up mediawiki PODs in the dumps legacy namespace. Not sure how/if that'd work from dev.

Other than that, it'd require setting up an s3 connection in airflow and manually creating supporting tables in metastore, with the appropriate HDFS write rights for the dev user. Holler if you need to run this test, and we can see how to prioritize support if it's a blocker for you (we need to document the process anyway, since it relies on muscle memory).

For my own education, may I ask what specifically you are testing, that requires executing the dag and not just testing its serialization with a new version of airflow? Having all DAGs runnable in the dev env sounds like a good thing. I wonder if it’s a requirement we should set as an AC for new DAGs.

For my own education, may I ask what specifically you are testing, that requires executing the dag and not just testing its serialization with a new version of airflow?

There are generally three types of the code paths that are not tested by serialisation that we've found:

  1. jinja templating, it most of the times can be tested with our test suite
  2. operators code, e.g. in case of changed API or imports, again, might be tested with our test suite if there are test for operators and they are not disabled (see below)
  3. caling to external services from updated libraries, might or might not be tested, e.g. we had lots of problems with calling to spark because of versions mismatch

We have disabled some tests, see T440709, as the new Airflow API makes testing operators and DAGs less trivial that Airflow 2. It mostly affects main instance tho.

@gmodena @trueg @lerickson As the wdqs_external_queries_rollup_daily is tested, and wdqs_wikidata_data_reload is not in production, we can actually go with the upgrade to Airflow 3, and then fix wdqs_wikidata_data_reload in-place if needed.

I can do it after figuring T434642, e.g. on Monday, 26th of October. How does it sound?

@atsuko just for our own knowledge, what is the nature of the work that might be needed after the upgrade once we unpause the wdqs_wikidata_data_reload DAG? Have changes in other DAGs generally been necessary or has it worked pretty well so far?

@atsuko just for our own knowledge, what is the nature of the work that might be needed after the upgrade once we unpause the wdqs_wikidata_data_reload DAG? Have changes in other DAGs generally been necessary or has it worked pretty well so far?

If something breaks, it will be mostly mismatched signatures or changed imports. E.g. for dumps I'm now fixing this changed function signature. Or it could be something like the case where Skein job were failing because wmf_airflow_common depends on private APIs that was changed.

In any case, I am here to help you with any breakage, and there are high chances that I'll be making the patch for you, not other way around.

Thanks! Sounds great, we will be in touch when we're ready to re-enable the DAG.

Tentatively scheduling the upgrade for 11:00 UTC on Wednesday

Tentatively scheduling the upgrade for 11:00 UTC on Wednesday

Ack. Do you need someone from Wikidata Platform Team in standby? Is there a coordination thread on slack/irc we should follow?

@gmodena I'll be doing an upgrade thread in slack #wikidata-platform-sre. It generally takes 10 minutes. Having someone within one working day is good, having someone on stand-by is not neccesary.

Change #1359783 had a related patch set uploaded (by Atsuko; author: Atsuko):

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

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

Pre-requisite

Upgrade

  • Disable all DAGs
kube-env airflow-wikidata-deploy dse-k8s-eqiad
kubectl exec "$SCHED" -c airflow-production -- airflow dags pause -y --treat-dag-id-as-regex '.*'
kubectl exec "$SCHED" -c airflow-production -- airflow dags list
  • 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-wikidata diff
charlie --services_dir dse-k8s-services --service airflow-wikidata apply
kubectl get pods -w
  • Drop old sessions
SCHED=$(kubectl get pod -l app=airflow,component=scheduler --no-headers -o custom-columns=":metadata.name"); echo "$SCHED"
kubectl exec "$SCHED" -c airflow-production -- python3 -c 'from wmf_airflow_common.tasks.db_cleanup import _exec_sql_no_return; _exec_sql_no_return("DELETE from session;")'

Cleanup

  • Re-enable the other previously enabled DAGs

Change #1359783 merged by jenkins-bot:

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

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