Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
feat(slack-alerts): update to use new percent change (from expected)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyak2 committed Sep 26, 2022
1 parent 0bf49ef commit 6cf67d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
2 changes: 1 addition & 1 deletion chaos_genius/alerts/email_templates/common.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{% set include_kpi_name = kpi_link_prefix is not none %}

{% if point.percent_change is string %}
<strong>Anomaly detected</strong>
<strong style="color: orange;">Anomaly detected</strong>
{% elif point.percent_change >= 0 %}
<strong style="color: rgb(6, 182, 212);">↑ {{ point.percent_change_formatted }} higher </strong> <span style="{{ non_important_text }}">than expected</span>
{% else %}
Expand Down
61 changes: 15 additions & 46 deletions chaos_genius/alerts/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,57 +268,26 @@ def anomaly_point_formatting(

include_kpi_name = kpi_link_prefix is not None

if point.previous_value is None or point.y == point.previous_value:
if isinstance(point.percent_change, str):
out += "- :black_circle_for_record: Anomalous behavior"

if include_kpi_name:
out += f" in *{kpi_name_link(kpi_link_prefix, point)}* "
if point.is_subdim:
out += f"{subdim_name_link(point)} "
else:
out += " detected "
if point.is_subdim:
out += f"in {subdim_name_link(point)} "

if point.previous_value is None:
out += f"- changed to *{point.y_readable}*"
if point.is_hourly:
out += f" at {point.anomaly_time_only}"
else:
if point.is_hourly:
out += (
f"- with constant value *{point.y_readable}*"
+ f" from {point.previous_point_time_only}"
+ f" to {point.anomaly_time_only}"
)
else:
out += f"- with same value *{point.y_readable}* as previous day"

elif point.percent_change >= 0:
out += f"- :arrow_up: {point.percent_change_formatted} higher than expected"
else:
if point.y > point.previous_value:
out += f"- :arrow_up: {point.formatted_change_percent} Spike"
elif point.y < point.previous_value:
out += f"- :arrow_down_small: {point.formatted_change_percent} Drop"

if include_kpi_name:
out += f" in *{kpi_name_link(kpi_link_prefix, point)}* "
if point.is_subdim:
out += f"{subdim_name_link(point)} "
else:
out += " detected "
if point.is_subdim:
out += f"in {subdim_name_link(point)} "
out += (
f"- :arrow_down_small: {point.percent_change_formatted} lower than expected"
)

out += " - "

out += f"- changed to *{point.y_readable}*"
if include_kpi_name:
out += f"*{kpi_name_link(kpi_link_prefix, point)}* "

if point.previous_value_readable is not None:
out += f" from {point.previous_value_readable}"
if point.is_subdim:
out += f"{subdim_name_link(point)} "

if point.is_hourly:
out += (
f" from {point.previous_point_time_only}"
+ f" to {point.anomaly_time_only}"
)
out += f"changed to *{point.y_readable}*"
if point.is_hourly:
out += f" at {point.anomaly_time_only}"

if point.relevant_subdims:
out += "\n - Reasons for change: "
Expand Down

0 comments on commit 6cf67d5

Please sign in to comment.