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(alerts): on demand metric timeseries support #53053

Merged
merged 27 commits into from
Jul 21, 2023

Conversation

obostjancic
Copy link
Member

@obostjancic obostjancic commented Jul 18, 2023

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 18, 2023
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Merging #53053 (5f7a13d) into master (fb560b5) will decrease coverage by 1.73%.
The diff coverage is 93.54%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #53053      +/-   ##
==========================================
- Coverage   79.52%   77.80%   -1.73%     
==========================================
  Files        4939     4938       -1     
  Lines      208076   208088      +12     
  Branches    35477    35498      +21     
==========================================
- Hits       165481   161899    -3582     
- Misses      37558    41145    +3587     
- Partials     5037     5044       +7     
Impacted Files Coverage Δ
src/sentry/snuba/discover.py 75.30% <ø> (ø)
src/sentry/snuba/functions.py 64.40% <ø> (ø)
src/sentry/snuba/issue_platform.py 62.22% <ø> (ø)
src/sentry/snuba/metrics_enhanced_performance.py 57.14% <ø> (ø)
src/sentry/snuba/metrics_performance.py 58.65% <ø> (ø)
src/sentry/snuba/profiles.py 90.00% <ø> (ø)
src/sentry/snuba/spans_indexed.py 25.00% <ø> (ø)
src/sentry/snuba/spans_metrics.py 46.80% <ø> (ø)
...ponents/events/interfaces/frame/stacktraceLink.tsx 86.66% <ø> (ø)
static/app/stores/tagStore.tsx 100.00% <ø> (ø)
... and 6 more

... and 290 files with indirect coverage changes

@obostjancic obostjancic marked this pull request as ready for review July 19, 2023 15:35
@obostjancic obostjancic requested review from a team as code owners July 19, 2023 15:35
@obostjancic obostjancic requested a review from a team July 19, 2023 15:35
Copy link
Contributor

@RaduW RaduW left a comment

Choose a reason for hiding this comment

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

Could only review it at a superficial level since I don't have the necessary context.
As far as I can see it looks good.

@@ -250,6 +252,10 @@ def _get_aggregate_fields(aggregate: str) -> Sequence[str]:
return []


def is_standard_metrics_query(query: Optional[str] = "") -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Could we expose just one out of is_on_demand_query and this? This is a misleading function for a public interface, because in order to check for a compatible query you always have to check for both the selected aggregates AND the query (due to countIf).

# On-demand metrics are implicitly transaction metrics. Remove the
# filters from the query that can't be translated to a RuleCondition.
query = re.sub(r"event\.type:transaction\s*", "", query)
query = re.sub(r"project:\w+\s*", "", query)
Copy link
Member

Choose a reason for hiding this comment

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

Can the project be quoted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, handled with 2ea5a82

Comment on lines 2108 to 2109
assert query.on_demand_metrics_enabled
assert not query._on_demand_spec
Copy link
Member

Choose a reason for hiding this comment

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

This tests class internals, is there some public effect we could observe instead? Such as a call to a (mocked) utility or a flag returned?


meta = result["meta"]

assert len(meta) == 2
Copy link
Member

Choose a reason for hiding this comment

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

There should be an is_metrics_data flag in there, can you assert this and check if the current way it's set makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, that flag is always set by the callers of query builders, after they receive results such as in

results["meta"]["isMetricsData"] = True

The result itself here contains only "meta" and "data"

spec = self._on_demand_spec

# TimeseriesQueryBuilder specific parameters
if self.is_timeseries_query:
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be easier to just check if isinstance(self, TimeSeriesQueryBuilder)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Done in 25d8adb

@obostjancic obostjancic enabled auto-merge (squash) July 21, 2023 07:43
@obostjancic obostjancic merged commit 9edcbea into master Jul 21, 2023
55 checks passed
@obostjancic obostjancic deleted the ogi/feat/on-demand-alerts-chart branch July 21, 2023 07:53
@sentry-io
Copy link

sentry-io bot commented Jul 21, 2023

Suspect Issues

This pull request has been deployed and Sentry has observed the following issues:

  • ‼️ AttributeError: 'NoneType' object has no attribute 'mri' /api/0/projects/{organization_slug}/alert-rules/ View Issue
  • ‼️ AttributeError: 'NoneType' object has no attribute 'mri' /api/0/projects/{organization_slug}/ View Issue
  • ‼️ AttributeError: 'NoneType' object has no attribute 'mri' sentry.snuba.tasks.delete_subscription_from_snuba View Issue
  • ‼️ AttributeError: 'NoneType' object has no attribute 'mri' SlackEventEndpoint View Issue
  • ‼️ AttributeError: 'NoneType' object has no attribute 'mri' sentry.incidents.tasks.handle_trigger_action View Issue

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants