-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add elasticsearch concurrency tags for Airflow #3921
Conversation
Full-stack documentation: https://docs.openverse.org/_preview/3921 Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again. You can check the GitHub pages deployment action list to see the current status of the deployments. Changed files 🔄: |
cffaa7a
to
5173842
Compare
Pinging @AetherUnbound as well since she asked if something like this was possible on a previous PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic! What a cool way to use tags 😄 🚀 - I tested everything locally and it worked as expected, even failed an ES index creation run when the data refresh was running. Only a few small things, otherwise this is good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a creative solution to potential concurrency conflicts between DAGs! Curiously, it also resembles the concept of pools.
I have some questions. First, what is the expected result of the test instructions showed? In my case, the staging_database_restore
passes the concurrency test, while the create_new_staging_es_index
fails it. The logic you mentioned suggests it should be the other way around, but it may be because the staging_database_restore
DAG starts with the DAG being turned on.
Second, from what I understand, with the current code, all DAGs from the staging_es_concurrency
tag wait for staging_database_restore
, but this one only waits for recreate_full_staging_index
, which is the only one with whom it really has no conflict. This sounds fine to me if we don't want to complicate things too much with many exceptions. An alternative I can think of is to create another staging_db_concurrency
tag for DAGs working at the DB level. Both DAGs can be in that bag while recreate_full_staging_index
retains the staging_es_concurrency
tag. This keeps dependencies straight. What do you think of this approach?
catalog/dags/elasticsearch_cluster/create_new_es_index/create_new_es_index_dag.py
Outdated
Show resolved
Hide resolved
catalog/dags/elasticsearch_cluster/create_new_es_index/create_new_es_index_types.py
Outdated
Show resolved
Hide resolved
catalog/dags/database/staging_database_restore/staging_database_restore_dag.py
Outdated
Show resolved
Hide resolved
It's funny you bring this up -- I just mentioned to @AetherUnbound earlier today that I was thinking of making an issue to do exactly that in the future 😄 The thinking was that for now, it is not actually a problem for any of these DAGs to be slightly over cautious in what DAGs they block on, and we're not introducing dependencies that weren't already hard-coded. Since you also brought it up, though, I'll just go ahead and implement it in this PR; it is the better long-term solution. |
All requested changes have been made, the biggest of which is simply splitting the staging concurrency groups out into separate DB and ES tags. The PR description has been updated, including the testing instructions -- as @krysal pointed out I had forgotten to update the testing instructions after changing the behavior of the |
Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR: @krysal Excluding weekend1 days, this PR was ready for review 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2. @stacimc, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings. Footnotes
|
@krysal will you have an opportunity to review this this week? If not, please go ahead and assign another reviewer. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. This looks great! 💯
Fixes
Fixes #3891 by @stacimc
Description
We now have quite a few DAGs that all operate on Elasticsearch or the underlying databases, and therefore must not run concurrently. We've been using the
prevent_concurrency_with_dags
andwait_for_external_dags
utils to accomplish this in each DAG, by passing in a hard-coded list of the external DAGs we want to either wait on or otherwise prevent concurrency with. Since this list is hard-coded for each DAG, it is extremely easy to miss dependencies especially as DAGs are added and changed. A few were missed in the implementation of the Search Relevancy project so far.This PR introduces
twothree new Tags that are used to identify DAGs as being part of a "concurrency group":production_elasticsearch_concurrency
, andstaging_elasticsearch_concurrency
for DAGs which affect the elasticsearch cluster, andstaging_api_db_concurrency
for DAGs which affect the API DB. Each DAG in these groups have been given the appropriate tag (the groups are listed below). The concurrency tasks have been updated to accept the name of the tag you want to select on, rather than a hard coded list, ie:^ This will select all the DAGs that have the given
tag
, except for the running DAG/the DAG that called the task, and fail immediately if any of them are running.So now if you add a new ES dag, rather than having to manually update a bunch of lists of DAG dependencies on every single other ES dag, you just have to remember to add the appropriate
tag
(s) to your new DAG. The concurrency util will raise an error if you forget, as well.Additional thoughts/alternatives
This comment on the issue explains why it wasn't possible to use the existing feature of Airflow pools to do this. Tags also have the benefit of being very visible in the UI and easy to filter by.
Testing Instructions
These are the intended concurrency groups:
staging_api_db_concurrency
staging_elasticsearch_concurrency
production_elasticsearch_concurrency
Note that
staging_database_restore
is not part of thestaging_elasticsearch_concurrency
group, because it only affects the API database and therefore DAGs that only operate on the staging ES cluster (likecreate_new_staging_es_index
don't need to block on it. Also note thatrecreate_full_staging_index
is part of both thestaging_elasticsearch_concurrency
andstaging_api_db_concurrency
group, as it pulls records from the api db for reindexing.For each DAG, run the DAG and check that the appropriate DAGs were waited on/prevented_concurrency_with. You can do this by looking at the logs for the
get_dags_in_<tag>_group
task, and then checking that the correct number of mapped tasks were made. (Example:create_proportional_by_source_staging_index
is in the staging group which has 4 dags total. It has aprevent_concurrency_with_dag
task generated for each of the 3 DAGs in the group excluding itself). Check the code to see special cases where some dependencies have been excluded for the data refresh.Airflow 2.9 is supposed to include the ability to prove meaningful names for dynamically mapped tasks (instead of just a numerical index), which will make this much easier to read at-a-glance once we upgrade!
Test the actual concurrency utils still works
We should also test the actual concurrency for at least a few options. The easiest way to do this is to trigger them in sequence through the Airflow CLI. Make sure the relevant DAGs are turned on in Airflow, then run
just catalog/shell
and:A general tip for remembering how the concurrency checks should work: scheduled DAGs (data refreshes, staging database restore) will wait if a conflicting DAG is running, and resume once it completes. DAGs that are only run manually (create_new_es_index, create_filtered_index, recreate_full_staging_index) fail immediately if a conflicting DAG is running.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin