-
Notifications
You must be signed in to change notification settings - Fork 54
Use Airflow variable to omit DAGs from any Slack notification #644
Conversation
Considering doing some additional refactoring so that adding a DAG to Edit: done, more information in PR description. |
I'm going to pick this back up as part of milestone v1.3.2 👍 |
c06106e
to
5fa08e9
Compare
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 rad, and it's fantastic that you've made it generic for both notifications and alerts 😻 Since we do already use "notifications" and "alerts" as specific and distinct names for certain kinds of Slack pings, would you be OK with changing silenced_slack_notifications
to something more generic like silenced_slack_messages
? That way it's a bit clearer (or at least hopefully less confusing) that this covers both notifications & alerts.
@@ -65,6 +65,20 @@ | |||
log = logging.getLogger(__name__) | |||
|
|||
|
|||
class SilencedSlackNotification(TypedDict): |
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.
Nice typed dict!
openverse_catalog/dags/maintenance/check_silenced_dags/check_silenced_dags.py
Outdated
Show resolved
Hide resolved
"test_dag_id": [ | ||
{ | ||
"issue": "https://github.com/WordPress/openverse/issues/1", | ||
"predicate": "kEYErrOR", |
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.
I ran all of the testing steps supplied and they worked great until the [2022-09-14, 05:02:31 UTC] {taskinstance.py:1909} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/airflow/.local/lib/python3.10/site-packages/airflow/operators/python.py", line 171, in execute
return_value = self.execute_callable()
File "/usr/local/airflow/.local/lib/python3.10/site-packages/airflow/operators/python.py", line 189, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/usr/local/airflow/openverse_catalog/dags/maintenance/check_silenced_dags/check_silenced_dags.py", line 61, in check_configuration
send_alert(message, username="Silenced DAG Check", unfurl_links=False)
TypeError: send_alert() missing 1 required positional argument: 'dag_id' |
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 updated 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 |
…ifications as well as alerts
65d2e89
to
dba529b
Compare
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 looks great! All of the testing steps succeeded, and I love all the documentation. This will for sure be useful 🚀
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.
lovely. lgtm
Co-authored-by: Zack Krida <[email protected]>
Fixes
Description
This is an extension of #643, which added an Airflow variable (
silenced_slack_alerts
) to conditionally omit DAGs from Slack alerts. This PR extends that logic to allow omitting DAGs from notifications (rather than just alerts).The driving use case for this one is the backfill of Europeana (discussed in WordPress/openverse#1642). Now that we have enabled
catchup
on this DAG, when we turn it on in production it will immediately start backfilling years of missing DagRuns. This will cause our notifications Slack channel to be flooded with messages for each of these runs. We'd like to be able to be able to temporarily turn this off and on without requiring a code change each time.Implementation notes
Originally, I added a second Airflow variable (
silenced_slack_notifications
) that worked identically tosilenced_slack_alerts
, but for notifications. I scrapped this in favor of changing the existing Airflow variable to allow it to skip Slack messages of any type. The new variable is namedsilenced_slack_notifications
and looks like this:It is a dictionary of DAG ids to lists of
SilencedSlackNotifications
, themselves a dict mapping a GitHub issue to a singlepredicate
string.predicate
matches against Slack message body OR the message username. This allows us to do things like silence allKeyError
alerts, or for example the notifications sent onreport_load_completion
(by targeting the user name).Note for Deploying
It is safe to simply merge this code, although it changes the shape of the Airflow variables, because:
Testing Instructions
Make sure you have the
slack_message_override
set to True in your Airflow variables. I used the testing configuration for Cleveland in the notes section above, to populate the Airflowsilenced_slack_notifications
variable (Admin -> Variables -> New).You're encouraged to play around with different configurations, and adjust the testing expectations accordingly. For Cleveland, I:
pull_data
, no Slack message was sent. You can also see a message in the logs ("Skipping Slack notification for cleveland_museum_workflow")report_load_completion
task passed, but the slack message was not sent. This is also recorded in the logs.report_load_completion
message IS sent for another DAG.And now check the
check_silenced_dags
DAG:Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin