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

nit: include query_extra for metric alert notifications #73325

Merged
merged 9 commits into from
Jun 25, 2024

Conversation

nhsiehgit
Copy link
Contributor

@nhsiehgit nhsiehgit commented Jun 25, 2024

we're constructing query_extra in a few spots now.

This consolidates the query_extra string all to utilize a single method to derive the query extra from the existing snuba_query and subscription

NOTE:

There are a handful of areas where we are referencing snuba_query.query without taking into account the query_extra

This might possibly lead to discrepancies if we are updating the snuba_query query, comparing queries, or executing one off snuba queries 🤔

eg.

  • snuba/tasks.py::update_subscription_in_snuba
  • incidents/logic.py::update_alert_rule
  • subscription_processor.py::get_comparison_aggregation_value
    etc.etc.

TODO: we may want to audit all uses and determine whether we should be constructing the query from the subscription rather than the snuba_query 🤔

@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Jun 25, 2024
Copy link
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@@ -162,8 +163,7 @@ def build_metric_alert_chart(
end: str | None = None,
user: Optional["User"] = None,
size: ChartSize | None = None,
query_extra: str | None = None,
project_id: int | None = None,
subscription: QuerySubscription | None = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rather than passing query_extra here and relying on implementations to construct the query_extra, instead we accept the subscription and construct the query_extra within the chart builder.

@@ -217,6 +221,8 @@ def metric_alert_attachment_info(
if latest_incident:
last_triggered_date = latest_incident.date_started

activation = selected_incident.activation
# TODO: determine whether activated alert data is useful for integration messages
Copy link
Contributor Author

Choose a reason for hiding this comment

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

preemptively include activated alert data into the metric alert attachment info

@nhsiehgit nhsiehgit marked this pull request as ready for review June 25, 2024 21:45
@nhsiehgit nhsiehgit requested review from a team as code owners June 25, 2024 21:45
@nhsiehgit nhsiehgit changed the title nit: move build_query_extra into snuba utils nit: include query_extra for metric alert notifications Jun 25, 2024
@@ -77,6 +77,7 @@ function MetricAlertActivity({organization, incident}: MetricAlertActivityProps)
}/releases/${encodeURIComponent(activation.activator)}/`,
query: {project: project},
}}
style={{textOverflow: 'ellipsis', overflowX: 'inherit'}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. this is an unrelated change to make the alert row slightly nicer.

shouldn't have any effect on the rest of the PR...

I can break this out if anyone feels strongly

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

:shipit: thanks for doing this, i feel like this is a really great cleanup pr and does a great job of DRYing up the code.

@@ -32,3 +33,13 @@

def get_dataset(dataset_label: str) -> Any | None:
return DATASET_OPTIONS.get(dataset_label)


def build_query_extra(subscription: QuerySubscription | None, snuba_query: SnubaQuery) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be nice to add some tests to this as we break it out.

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.01%. Comparing base (131822f) to head (a3ab9b1).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #73325      +/-   ##
==========================================
- Coverage   78.03%   78.01%   -0.02%     
==========================================
  Files        6632     6632              
  Lines      296035   296117      +82     
  Branches    50994    50997       +3     
==========================================
+ Hits       231002   231024      +22     
- Misses      58750    58806      +56     
- Partials     6283     6287       +4     
Files Coverage Δ
src/sentry/incidents/action_handlers.py 87.16% <ø> (+1.74%) ⬆️
src/sentry/incidents/charts.py 85.41% <100.00%> (-0.16%) ⬇️
...entry/integrations/discord/actions/metric_alert.py 35.71% <ø> (ø)
src/sentry/integrations/metric_alerts.py 96.66% <ø> (-0.08%) ⬇️
.../sentry/integrations/slack/unfurl/metric_alerts.py 88.40% <ø> (ø)
...c/sentry/integrations/slack/utils/notifications.py 86.81% <ø> (ø)
src/sentry/snuba/tasks.py 93.69% <ø> (-0.28%) ⬇️
src/sentry/snuba/utils.py 100.00% <100.00%> (ø)
...ews/alerts/rules/metric/details/metricActivity.tsx 62.50% <ø> (ø)

... and 48 files with indirect coverage changes

@nhsiehgit nhsiehgit merged commit 028e31a into master Jun 25, 2024
52 checks passed
@nhsiehgit nhsiehgit deleted the nhsieh/build_chart_query_extra branch June 25, 2024 23:30
@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants