-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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(alert/report): add ALERTS_ATTACH_REPORTS feature flags + feature #13894
Merged
willbarrett
merged 6 commits into
apache:master
from
preset-io:lily/alert-link-only-feature-flag
Apr 1, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -750,6 +750,10 @@ def test_email_dashboard_report_fails( | |
) | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
@patch("superset.utils.screenshots.ChartScreenshot.get_screenshot") | ||
@patch.dict( | ||
"superset.extensions.feature_flag_manager._feature_flags", | ||
ALERTS_ATTACH_REPORTS=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some tests for the inverse so we have confidence that everything works as expected with the feature flag disabled as well. |
||
) | ||
def test_slack_chart_alert(screenshot_mock, email_mock, create_alert_email_chart): | ||
""" | ||
ExecuteReport Command: Test chart slack alert | ||
|
@@ -773,6 +777,34 @@ def test_slack_chart_alert(screenshot_mock, email_mock, create_alert_email_chart | |
assert_log(ReportState.SUCCESS) | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"load_birth_names_dashboard_with_slices", "create_alert_email_chart" | ||
) | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
@patch.dict( | ||
"superset.extensions.feature_flag_manager._feature_flags", | ||
ALERTS_ATTACH_REPORTS=False, | ||
) | ||
def test_slack_chart_alert_no_attachment(email_mock, create_alert_email_chart): | ||
""" | ||
ExecuteReport Command: Test chart slack alert | ||
""" | ||
# setup screenshot mock | ||
|
||
with freeze_time("2020-01-01T00:00:00Z"): | ||
AsyncExecuteReportScheduleCommand( | ||
test_id, create_alert_email_chart.id, datetime.utcnow() | ||
).run() | ||
|
||
notification_targets = get_target_from_report_schedule(create_alert_email_chart) | ||
# Assert the email smtp address | ||
assert email_mock.call_args[0][0] == notification_targets[0] | ||
# Assert the there is no attached image | ||
assert email_mock.call_args[1]["images"] is None | ||
# Assert logs are correct | ||
assert_log(ReportState.SUCCESS) | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"load_birth_names_dashboard_with_slices", "create_report_slack_chart" | ||
) | ||
|
@@ -859,6 +891,10 @@ def test_soft_timeout_alert(email_mock, create_alert_email_chart): | |
) | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
@patch("superset.utils.screenshots.ChartScreenshot.get_screenshot") | ||
@patch.dict( | ||
"superset.extensions.feature_flag_manager._feature_flags", | ||
ALERTS_ATTACH_REPORTS=True, | ||
) | ||
def test_soft_timeout_screenshot(screenshot_mock, email_mock, create_alert_email_chart): | ||
""" | ||
ExecuteReport Command: Test soft timeout on screenshot | ||
|
@@ -882,11 +918,11 @@ def test_soft_timeout_screenshot(screenshot_mock, email_mock, create_alert_email | |
|
||
|
||
@pytest.mark.usefixtures( | ||
"load_birth_names_dashboard_with_slices", "create_alert_email_chart" | ||
"load_birth_names_dashboard_with_slices", "create_report_email_chart" | ||
) | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
@patch("superset.utils.screenshots.ChartScreenshot.get_screenshot") | ||
def test_fail_screenshot(screenshot_mock, email_mock, create_alert_email_chart): | ||
def test_fail_screenshot(screenshot_mock, email_mock, create_report_email_chart): | ||
""" | ||
ExecuteReport Command: Test soft timeout on screenshot | ||
""" | ||
|
@@ -896,10 +932,10 @@ def test_fail_screenshot(screenshot_mock, email_mock, create_alert_email_chart): | |
screenshot_mock.side_effect = Exception("Unexpected error") | ||
with pytest.raises(ReportScheduleScreenshotFailedError): | ||
AsyncExecuteReportScheduleCommand( | ||
test_id, create_alert_email_chart.id, datetime.utcnow() | ||
test_id, create_report_email_chart.id, datetime.utcnow() | ||
).run() | ||
|
||
notification_targets = get_target_from_report_schedule(create_alert_email_chart) | ||
notification_targets = get_target_from_report_schedule(create_report_email_chart) | ||
# Assert the email smtp address, asserts a notification was sent with the error | ||
assert email_mock.call_args[0][0] == notification_targets[0] | ||
|
||
|
@@ -908,6 +944,32 @@ def test_fail_screenshot(screenshot_mock, email_mock, create_alert_email_chart): | |
) | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"load_birth_names_dashboard_with_slices", "create_alert_email_chart" | ||
) | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
@patch.dict( | ||
"superset.extensions.feature_flag_manager._feature_flags", | ||
ALERTS_ATTACH_REPORTS=False, | ||
) | ||
def test_email_disable_screenshot(email_mock, create_alert_email_chart): | ||
""" | ||
ExecuteReport Command: Test soft timeout on screenshot | ||
""" | ||
|
||
AsyncExecuteReportScheduleCommand( | ||
test_id, create_alert_email_chart.id, datetime.utcnow() | ||
).run() | ||
|
||
notification_targets = get_target_from_report_schedule(create_alert_email_chart) | ||
# Assert the email smtp address, asserts a notification was sent with the error | ||
assert email_mock.call_args[0][0] == notification_targets[0] | ||
# Assert the there is no attached image | ||
assert email_mock.call_args[1]["images"] is None | ||
|
||
assert_log(ReportState.SUCCESS) | ||
|
||
|
||
@pytest.mark.usefixtures("create_invalid_sql_alert_email_chart") | ||
@patch("superset.reports.notifications.email.send_email_smtp") | ||
def test_invalid_sql_alert(email_mock, create_invalid_sql_alert_email_chart): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: would be nice to have a small explanation here
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.
another nit, does it make sense for this to be a feature flag? I mean
ALERT_REPORTS
is a feature flag, with lot's of other configuration options that live outside the feature flag dict. Also it may be more clear to call this flagALERTS_ATTACH_SCREENSHOT