Skip to content
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

Merged
merged 5 commits into from
Jul 30, 2020

Conversation

JasonD28
Copy link
Contributor

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:
Screen Shot 2020-07-29 at 1 11 09 PM

After:
Screen Shot 2020-07-29 at 1 17 28 PM

TEST PLAN

  • unit test

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

Copy link
Member

@bkyryliuk bkyryliuk left a 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

@@ -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
Copy link
Member

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

"test_alert": BooleanField(
"Send Test Alert",
default=False,
description="If enabled, a test alert will be sent on the creation / update of active alerts.",
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit_columns = add_columns
related_views = [AlertLogModelView]

def process_form(self, form: Form, is_created: bool) -> None:
if form.test_email_recipients.data:
Copy link
Member

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):
Copy link
Member

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

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jul 29, 2020
)

self._extra_data["test_alert"] = form.test_alert.data
self._extra_data["test_email_recipients"] = test_email_recipients # type: ignore
Copy link
Contributor Author

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

@JasonD28 JasonD28 requested a review from bkyryliuk July 29, 2020 22:22
@@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add typing annotation here

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
Copy link
Member

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

@bkyryliuk bkyryliuk merged commit 7a329c2 into apache:master Jul 30, 2020
JasonD28 added a commit to JasonD28/incubator-superset that referenced this pull request Aug 3, 2020
…10476)

* added test email functionality

* formatting changes

* more formatting

* applied requested changes

* mypy

Co-authored-by: Jason Davis <@dropbox.com>
JasonD28 added a commit to JasonD28/incubator-superset that referenced this pull request Aug 3, 2020
…10476)

* added test email functionality

* formatting changes

* more formatting

* applied requested changes

* mypy

Co-authored-by: Jason Davis <@dropbox.com>
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
…10476)

* added test email functionality

* formatting changes

* more formatting

* applied requested changes

* mypy

Co-authored-by: Jason Davis <@dropbox.com>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants