|
@@ -76,6 +76,24 @@ class MetricsDatasetConfig(DatasetConfig):
|
|
|
snql_distribution=self._resolve_apdex_function,
|
|
|
default_result_type="number",
|
|
|
),
|
|
|
+ fields.MetricsFunction(
|
|
|
+ "avg",
|
|
|
+ snql_distribution=lambda args, alias: Function(
|
|
|
+ "avgIf",
|
|
|
+ [
|
|
|
+ Column("value"),
|
|
|
+ Function(
|
|
|
+ "equals",
|
|
|
+ [
|
|
|
+ Column("metric_id"),
|
|
|
+ self.resolve_metric("transaction.duration"),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ alias,
|
|
|
+ ),
|
|
|
+ default_result_type="integer",
|
|
|
+ ),
|
|
|
fields.MetricsFunction(
|
|
|
"count_miserable",
|
|
|
required_args=[fields.MetricArg("column", allowed_columns=["user"])],
|
|
@@ -181,14 +199,22 @@ class MetricsDatasetConfig(DatasetConfig):
|
|
|
),
|
|
|
],
|
|
|
calculated_args=[resolve_metric_id],
|
|
|
- snql_distribution=lambda args, alias: Function(
|
|
|
- "maxIf",
|
|
|
- [
|
|
|
- Column("value"),
|
|
|
- Function("equals", [Column("metric_id"), args["metric_id"]]),
|
|
|
- ],
|
|
|
- alias,
|
|
|
- ),
|
|
|
+ snql_distribution=lambda args, alias: self._resolve_percentile(args, alias, 1),
|
|
|
+ default_result_type="duration",
|
|
|
+ ),
|
|
|
+ fields.MetricsFunction(
|
|
|
+ "percentile",
|
|
|
+ required_args=[
|
|
|
+ fields.with_default(
|
|
|
+ "transaction.duration",
|
|
|
+ fields.MetricArg(
|
|
|
+ "column", allowed_columns=constants.METRIC_DURATION_COLUMNS
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ fields.NumberRange("percentile", 0, 1),
|
|
|
+ ],
|
|
|
+ calculated_args=[resolve_metric_id],
|
|
|
+ snql_distribution=self._resolve_percentile,
|
|
|
default_result_type="duration",
|
|
|
),
|
|
|
fields.MetricsFunction(
|
|
@@ -205,6 +231,24 @@ class MetricsDatasetConfig(DatasetConfig):
|
|
|
),
|
|
|
default_result_type="integer",
|
|
|
),
|
|
|
+ fields.MetricsFunction(
|
|
|
+ "count",
|
|
|
+ snql_distribution=lambda args, alias: Function(
|
|
|
+ "countIf",
|
|
|
+ [
|
|
|
+ Column("value"),
|
|
|
+ Function(
|
|
|
+ "equals",
|
|
|
+ [
|
|
|
+ Column("metric_id"),
|
|
|
+ self.resolve_metric("transaction.duration"),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ alias,
|
|
|
+ ),
|
|
|
+ default_result_type="integer",
|
|
|
+ ),
|
|
|
fields.MetricsFunction(
|
|
|
"count_web_vitals",
|
|
|
required_args=[
|
|
@@ -504,21 +548,36 @@ class MetricsDatasetConfig(DatasetConfig):
|
|
|
self,
|
|
|
args: Mapping[str, Union[str, Column, SelectType, int, float]],
|
|
|
alias: str,
|
|
|
- fixed_percentile: float,
|
|
|
+ fixed_percentile: Optional[float] = None,
|
|
|
) -> SelectType:
|
|
|
- return Function(
|
|
|
- "arrayElement",
|
|
|
- [
|
|
|
- Function(
|
|
|
- f"quantilesIf({fixed_percentile})",
|
|
|
- [
|
|
|
- Column("value"),
|
|
|
- Function("equals", [Column("metric_id"), args["metric_id"]]),
|
|
|
- ],
|
|
|
- ),
|
|
|
- 1,
|
|
|
- ],
|
|
|
- alias,
|
|
|
+ if fixed_percentile is None:
|
|
|
+ fixed_percentile = args["percentile"]
|
|
|
+ if fixed_percentile not in constants.METRIC_PERCENTILES:
|
|
|
+ raise IncompatibleMetricsQuery("Custom quantile incompatible with metrics")
|
|
|
+ return (
|
|
|
+ Function(
|
|
|
+ "maxIf",
|
|
|
+ [
|
|
|
+ Column("value"),
|
|
|
+ Function("equals", [Column("metric_id"), args["metric_id"]]),
|
|
|
+ ],
|
|
|
+ alias,
|
|
|
+ )
|
|
|
+ if fixed_percentile == 1
|
|
|
+ else Function(
|
|
|
+ "arrayElement",
|
|
|
+ [
|
|
|
+ Function(
|
|
|
+ f"quantilesIf({fixed_percentile})",
|
|
|
+ [
|
|
|
+ Column("value"),
|
|
|
+ Function("equals", [Column("metric_id"), args["metric_id"]]),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ 1,
|
|
|
+ ],
|
|
|
+ alias,
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
def _key_transaction_filter_converter(self, search_filter: SearchFilter) -> Optional[WhereType]:
|