-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
feat: add test email functionality to SQL-based email alerts #10476
Conversation
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.
quite good, just a couple nits
superset/tasks/schedules.py
Outdated
@@ -551,7 +551,12 @@ def schedule_alert_query( # pylint: disable=unused-argument | |||
return | |||
|
|||
if report_type == ScheduleType.alert: | |||
if run_alert_query(schedule, dbsession): | |||
# recipients is only specified when task is called from view for a test email |
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.
add additional flag to determine if that is a test run e.g. you already have a flag in the form
superset/views/alerts.py
Outdated
"test_alert": BooleanField( | ||
"Send Test Alert", | ||
default=False, | ||
description="If enabled, a test alert will be sent on the creation / update of active alerts.", |
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.
explain that email will be send only if alert will fail
else: | ||
test_email_recipients = None | ||
|
||
self._extra_data["test_alert"] = form.test_alert.data |
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.
https://github.com/apache/incubator-superset/blob/master/superset/views/schedules.py#L120 could be needed as well, e.g. normalizing the email list
edit_columns = add_columns | ||
related_views = [AlertLogModelView] | ||
|
||
def process_form(self, form: Form, is_created: bool) -> None: | ||
if form.test_email_recipients.data: |
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.
do this instead
test_email_recipients = None
if form.test_email_recipients.data:
test_email_recipients = form.test_email_recipients.data.strip()
|
||
@patch("superset.tasks.schedules.deliver_alert") | ||
@patch("superset.tasks.schedules.run_alert_query") | ||
def test_schedule_alert_query(mock_run_alert, mock_deliver_alert, setup_database): |
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.
it would be nice to add the end to end test as well, it can be done in the separate PR.
Example: https://github.com/apache/incubator-superset/blob/master/tests/core_tests.py#L827
superset/views/alerts.py
Outdated
) | ||
|
||
self._extra_data["test_alert"] = form.test_alert.data | ||
self._extra_data["test_email_recipients"] = test_email_recipients # type: ignore |
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.
mypy was complaining: Incompatible types in assignment (expression has type "Optional[str]", target has type "Optional[bool]")
All other type definitions matched
4205621
to
c398e8c
Compare
superset/views/alerts.py
Outdated
@@ -44,6 +50,7 @@ class AlertModelView(SupersetModelView): # pylint: disable=too-many-ancestors | |||
datamodel = SQLAInterface(Alert) | |||
route_base = "/alert" | |||
include_route_methods = RouteMethod.CRUD_SET | |||
_extra_data = {"test_alert": False, "test_email_recipients": None} |
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.
add typing annotation here
superset/views/alerts.py
Outdated
email_recipients = get_email_address_str(form.test_email_recipients.data) | ||
|
||
self._extra_data["test_alert"] = form.test_alert.data | ||
self._extra_data["test_email_recipients"] = email_recipients # type: ignore |
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.
resolve type: ignore - you can cast
c50a4e2
to
6958ea8
Compare
…10476) * added test email functionality * formatting changes * more formatting * applied requested changes * mypy Co-authored-by: Jason Davis <@dropbox.com>
…10476) * added test email functionality * formatting changes * more formatting * applied requested changes * mypy Co-authored-by: Jason Davis <@dropbox.com>
…10476) * added test email functionality * formatting changes * more formatting * applied requested changes * mypy Co-authored-by: Jason Davis <@dropbox.com>
SUMMARY
Added functionality for users to request a test email to be sent whenever an active SQL-based alert is created or updated.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
In AlertModelView
Before:
After:
TEST PLAN
ADDITIONAL INFORMATION