Skip to content

Commit

Permalink
added nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Davis committed Sep 3, 2020
1 parent e8d8949 commit ee9838e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion superset/models/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def alert(self) -> RelationshipProperty:
backref=backref("validators", cascade="all, delete-orphan"),
)

def __str__(self) -> str:
def pretty_print(self) -> str:
""" String representing the comparison that will trigger a validator """
config = json.loads(self.config)

Expand Down
16 changes: 8 additions & 8 deletions superset/tasks/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AlertContent(NamedTuple):
label: str # alert name
sql: str # sql statement for alert
observation_value: str # value from observation that triggered the alert
validation_str: str # a string of the comparison that triggered an alert
validation_error_message: str # a string of the comparison that triggered an alert
alert_url: str # url to alert details
image_data: Optional[ScreenshotData] # data for the alert screenshot

Expand Down Expand Up @@ -575,8 +575,8 @@ def deliver_alert(
# where an alert might not have a validator
recipients = recipients or alert.recipients
slack_channel = slack_channel or alert.slack_channel
validation_str = (
str(alert.observations[-1].value) + " " + str(alert.validators[0])
validation_error_message = (
str(alert.observations[-1].value) + " " + alert.validators[0].pretty_print()
if alert.validators
else ""
)
Expand All @@ -586,7 +586,7 @@ def deliver_alert(
alert.label,
alert.sql_observer[0].sql,
str(alert.observations[-1].value),
validation_str,
validation_error_message,
_get_url_path("AlertModelView.show", user_friendly=True, pk=alert_id),
_get_slice_screenshot(alert.slice.id),
)
Expand All @@ -596,7 +596,7 @@ def deliver_alert(
alert.label,
alert.sql_observer[0].sql,
str(alert.observations[-1].value),
validation_str,
validation_error_message,
_get_url_path("AlertModelView.show", user_friendly=True, pk=alert_id),
None,
)
Expand Down Expand Up @@ -626,7 +626,7 @@ def deliver_email_alert(alert_content: AlertContent, recipients: str) -> None:
label=alert_content.label,
sql=alert_content.sql,
observation_value=alert_content.observation_value,
validation_str=alert_content.validation_str,
validation_error_message=alert_content.validation_error_message,
image_url=image_url,
)

Expand All @@ -645,7 +645,7 @@ def deliver_slack_alert(alert_content: AlertContent, slack_channel: str) -> None
label=alert_content.label,
sql=alert_content.sql,
observation_value=alert_content.observation_value,
validation_str=alert_content.validation_str,
validation_error_message=alert_content.validation_error_message,
url=alert_content.image_data.url,
alert_url=alert_content.alert_url,
)
Expand All @@ -656,7 +656,7 @@ def deliver_slack_alert(alert_content: AlertContent, slack_channel: str) -> None
label=alert_content.label,
sql=alert_content.sql,
observation_value=alert_content.observation_value,
validation_str=alert_content.validation_str,
validation_error_message=alert_content.validation_error_message,
alert_url=alert_content.alert_url,
)

Expand Down
2 changes: 1 addition & 1 deletion superset/templates/email/alert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p><b>Query:</b></p>
<code><mark style="background-color: LightGrey; font-size: 1.1em">{{sql}}</mark></code></p>
<p><b>Result</b>: {{observation_value}}</p>
<p><b>Reason</b>: {{validation_str}}</p>
<p><b>Reason</b>: {{validation_error_message}}</p>
<p><a href="{{alert_url}}">View Alert Details</a></p>
<p>Click <a href="{{image_url}}">here</a> or the image below to view the chart related to this alert.</p>
<a href="{{image_url}}">
Expand Down
2 changes: 1 addition & 1 deletion superset/templates/slack/alert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
*Triggered Alert: {{label}} :redalert:*
*Query*:```{{sql}}```
*Result*: {{observation_value}}
*Reason*: {{validation_str}}
*Reason*: {{validation_error_message}}
<{{alert_url}}|View Alert Details>
<{{url}}|*Explore in Superset*>
2 changes: 1 addition & 1 deletion superset/templates/slack/alert_no_screenshot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
*Triggered Alert: {{label}} :redalert:*
*Query*:```{{sql}}```
*Result*: {{observation_value}}
*Reason*: {{validation_str}}
*Reason*: {{validation_error_message}}
<{{alert_url}}|View Alert Details>
2 changes: 1 addition & 1 deletion tests/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def test_deliver_alert_screenshot(
"initial_comment": f"\n*Triggered Alert: {alert.label} :redalert:*\n"
f"*Query*:```{alert.sql_observer[0].sql}```\n"
f"*Result*: {alert.observations[-1].value}\n"
f"*Reason*: {alert.observations[-1].value} {str(alert.validators[0])}\n"
f"*Reason*: {alert.observations[-1].value} {alert.validators[0].pretty_print()}\n"
f"<http://0.0.0.0:8080/alert/show/{alert.id}"
f"|View Alert Details>\n<http://0.0.0.0:8080/superset/slice/{alert.slice_id}/"
"|*Explore in Superset*>",
Expand Down

0 comments on commit ee9838e

Please sign in to comment.