Skip to content

Commit 1aac828

Browse files
authored
fix(on-demand): Fix p100 and percentiles (#58511)
1 parent 621ea23 commit 1aac828

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

Diff for: src/sentry/search/events/builder/metrics.py

-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ def _on_demand_metric_spec(self) -> Optional[OnDemandMetricSpec]:
126126
if not field:
127127
return None
128128

129-
if self.query is None:
130-
return None
131-
132129
if not should_use_on_demand_metrics(self.dataset, field, self.query):
133130
return None
134131

Diff for: src/sentry/snuba/metrics/extraction.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"p75": "p75",
119119
"p95": "p95",
120120
"p99": "p99",
121-
"p100": "p100"
121+
# p100 is not supported in the metrics layer, so we convert to max which is equivalent.
122+
"p100": "max"
122123
# generic percentile is not supported by metrics layer.
123124
}
124125

@@ -311,7 +312,6 @@ def _get_aggregate_supported_by(aggregate: str) -> SupportedBy:
311312
return SupportedBy.neither()
312313

313314
match = fields.is_function(aggregate)
314-
315315
if not match:
316316
raise InvalidSearchQuery(f"Invalid characters in field {aggregate}")
317317

@@ -320,7 +320,6 @@ def _get_aggregate_supported_by(aggregate: str) -> SupportedBy:
320320
args_support = _get_args_support(function, args)
321321

322322
return SupportedBy.combine(function_support, args_support)
323-
324323
except InvalidSearchQuery:
325324
logger.error(f"Failed to parse aggregate: {aggregate}", exc_info=True)
326325

@@ -348,7 +347,7 @@ def _get_percentile_support(args: Sequence[str]) -> SupportedBy:
348347
if not _get_percentile_op(args):
349348
return SupportedBy.neither()
350349

351-
return SupportedBy(standard_metrics=False, on_demand_metrics=True)
350+
return SupportedBy.both()
352351

353352

354353
def _get_percentile_op(args: Sequence[str]) -> Optional[MetricOperationType]:
@@ -924,6 +923,7 @@ def _process_query(self) -> Optional[RuleCondition]:
924923
# derived metrics have their conditions injected in the tags
925924
if self._get_op(parsed_field.function, parsed_field.arguments) in _DERIVED_METRICS:
926925
return None
926+
927927
raise Exception("This query should not use on demand metrics")
928928

929929
return aggregate_conditions
@@ -963,10 +963,7 @@ def _parse_arguments(
963963
raise Exception(f"The operation {op} supports one or more parameters")
964964

965965
arguments = parsed_field.arguments
966-
map_argument = op not in _MULTIPLE_ARGS_METRICS
967-
968-
first_argument = arguments[0]
969-
return [_map_field_name(first_argument)] if map_argument else arguments
966+
return [_map_field_name(arguments[0])] if op not in _MULTIPLE_ARGS_METRICS else arguments
970967

971968
@staticmethod
972969
def _get_op(function: str, args: Sequence[str]) -> MetricOperationType:
@@ -995,7 +992,6 @@ def _get_metric_type(function: str) -> str:
995992
def _parse_field(value: str) -> Optional[FieldParsingResult]:
996993
try:
997994
match = fields.is_function(value)
998-
999995
if not match:
1000996
raise InvalidSearchQuery(f"Invalid characters in field {value}")
1001997

0 commit comments

Comments
 (0)