Skip to content

feat(discover): Allows insight metrics to be used with the avg function in the discover metrics dataset #75870

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/sentry/search/events/datasets/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def field_alias_converter(self) -> Mapping[str, Callable[[str], SelectType]]:
}

def resolve_metric(self, value: str) -> int:
metric_id = self.builder.resolve_metric_index(constants.METRICS_MAP.get(value, value))
# SPAN_METRICS_MAP and METRICS_MAP have some overlapping keys
mri_map = constants.SPAN_METRICS_MAP | constants.METRICS_MAP
metric_id = self.builder.resolve_metric_index(mri_map.get(value, value))
if metric_id is None:
# Maybe this is a custom measurment?
for measurement in self.builder.custom_measurement_map:
Expand Down Expand Up @@ -112,7 +114,8 @@ def function_converter(self) -> Mapping[str, fields.MetricsFunction]:
required_args=[
fields.MetricArg(
"column",
allowed_columns=constants.METRIC_DURATION_COLUMNS,
allowed_columns=constants.SPAN_METRIC_DURATION_COLUMNS
| constants.METRIC_DURATION_COLUMNS,
)
],
calculated_args=[resolve_metric_id],
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/snuba/test_entity_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@ def test_get_entity_subscription_for_insights_queries(self) -> None:
("count()", "span.op:http.client", False),
("count()", "span.description:abc", False),
("performance_score(measurements.score.lcp)", "", False),
("avg(span.self_time)", "", False),
# TODO: The following functions are not supported in the discover metrics dataset yet.
# Uncomment these as we port them over.
# ("spm()", "", False),
# ("cache_miss_rate()", "", False),
# ("http_response_rate()", "", False),
# ("avg(span.self_time)", "", False),
]
for aggregate, query, use_metrics_layer in cases:
entity_subscription = get_entity_subscription(
Expand Down
46 changes: 46 additions & 0 deletions tests/snuba/api/endpoints/test_organization_events_mep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3458,6 +3458,48 @@ def test_filtering_by_org_id_is_not_compatible(self):
)
assert response.status_code == 400, response.content

def test_avg_span_self_time(self):
self.store_span_metric(
1,
timestamp=self.min_ago,
)

self.store_span_metric(
3,
timestamp=self.min_ago,
)

self.store_span_metric(
3,
timestamp=self.min_ago,
)

self.store_span_metric(
4,
timestamp=self.min_ago,
)

self.store_span_metric(
5,
timestamp=self.min_ago,
)

response = self.do_request(
{
"field": [
"avg(span.self_time)",
],
"query": "",
"project": self.project.id,
"dataset": "metrics",
}
)

assert response.status_code == 200, response.content
data = response.data["data"]
assert len(data) == 1
assert data[0]["avg(span.self_time)"] == 3.2


class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithOnDemandMetrics(
MetricsEnhancedPerformanceTestCase
Expand Down Expand Up @@ -3946,3 +3988,7 @@ def test_timestamp_groupby(self):
@pytest.mark.xfail(reason="Not implemented")
def test_on_demand_with_mep(self):
super().test_on_demand_with_mep()

@pytest.mark.xfail(reason="Not implemented")
def test_avg_span_self_time(self):
super().test_avg_span_self_time()
Loading