|
@@ -6,7 +6,18 @@ import os
|
|
|
from collections.abc import Callable, Sequence
|
|
|
from dataclasses import dataclass
|
|
|
from enum import Enum
|
|
|
-from typing import Any, Literal, NamedTuple, NotRequired, Optional, TypedDict, TypeVar, Union, cast
|
|
|
+from typing import (
|
|
|
+ Any,
|
|
|
+ Literal,
|
|
|
+ NamedTuple,
|
|
|
+ NotRequired,
|
|
|
+ Optional,
|
|
|
+ Self,
|
|
|
+ TypedDict,
|
|
|
+ TypeVar,
|
|
|
+ Union,
|
|
|
+ cast,
|
|
|
+)
|
|
|
|
|
|
import sentry_sdk
|
|
|
from django.utils.functional import cached_property
|
|
@@ -565,22 +576,22 @@ class SupportedBy:
|
|
|
on_demand_metrics: bool
|
|
|
|
|
|
@classmethod
|
|
|
- def neither(cls):
|
|
|
+ def neither(cls) -> Self:
|
|
|
return cls(standard_metrics=False, on_demand_metrics=False)
|
|
|
|
|
|
@classmethod
|
|
|
- def both(cls):
|
|
|
+ def both(cls) -> Self:
|
|
|
return cls(standard_metrics=True, on_demand_metrics=True)
|
|
|
|
|
|
@classmethod
|
|
|
- def combine(cls, *supported_by):
|
|
|
+ def combine(cls, *supported_by: Self) -> Self:
|
|
|
return cls(
|
|
|
standard_metrics=all(s.standard_metrics for s in supported_by),
|
|
|
on_demand_metrics=all(s.on_demand_metrics for s in supported_by),
|
|
|
)
|
|
|
|
|
|
|
|
|
-def should_use_on_demand_metrics_for_querying(organization: Organization, **kwargs) -> bool:
|
|
|
+def should_use_on_demand_metrics_for_querying(organization: Organization, **kwargs: Any) -> bool:
|
|
|
"""Helper function to check if an organization can query an specific on-demand function"""
|
|
|
components = _extract_aggregate_components(kwargs["aggregate"])
|
|
|
if components is None:
|
|
@@ -1196,7 +1207,7 @@ class OnDemandMetricSpec:
|
|
|
self._arguments = []
|
|
|
self._eager_process()
|
|
|
|
|
|
- def _eager_process(self):
|
|
|
+ def _eager_process(self) -> None:
|
|
|
op, metric_type, arguments = self._process_field()
|
|
|
|
|
|
self.op = op
|
|
@@ -1204,7 +1215,7 @@ class OnDemandMetricSpec:
|
|
|
self._arguments = arguments or []
|
|
|
|
|
|
@property
|
|
|
- def field_to_extract(self):
|
|
|
+ def field_to_extract(self) -> str | None:
|
|
|
if self.op in ("on_demand_apdex", "on_demand_count_web_vitals"):
|
|
|
return None
|
|
|
|
|
@@ -1278,7 +1289,7 @@ class OnDemandMetricSpec:
|
|
|
# In case we have `None` condition, we will use `None` string for hashing, so it's a sentinel value.
|
|
|
return str(_deep_sorted(self.condition))
|
|
|
|
|
|
- def _groupbys_for_hash(self):
|
|
|
+ def _groupbys_for_hash(self) -> str:
|
|
|
# A sorted list of group-bys for the hash, since groupbys will be unique per on_demand metric.
|
|
|
return str(sorted(self.groupbys))
|
|
|
|