Skip to content

Commit

Permalink
Revert "fix(metrics): Allow private metrics through metrics data (#53847
Browse files Browse the repository at this point in the history
)"

This reverts commit 7e4b836.

Co-authored-by: iambriccardo <[email protected]>
  • Loading branch information
getsentry-bot and iambriccardo committed Jul 31, 2023
1 parent e5292a1 commit 09d8c7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/sentry/snuba/metrics/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MetricField:
Dict[str, Union[None, str, int, float, Sequence[Tuple[Union[str, int], ...]]]]
] = None
alias: Optional[str] = None
allow_private: bool = False

def __post_init__(self) -> None:
# Validate that it is a valid MRI format
Expand All @@ -50,10 +49,7 @@ def __post_init__(self) -> None:
raise InvalidParams(f"Invalid Metric MRI: {self.metric_mri}")

# Validates that the MRI requested is an MRI the metrics layer exposes
metric_name = f"pm_{self.metric_mri}"
if not self.allow_private:
metric_name = get_public_name_from_mri(self.metric_mri)

metric_name = get_public_name_from_mri(self.metric_mri)
if not self.alias:
key = f"{self.op}({metric_name})" if self.op is not None else metric_name
object.__setattr__(self, "alias", key)
Expand Down
16 changes: 5 additions & 11 deletions src/sentry/snuba/metrics/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@
QUERY_PROJECT_LIMIT = 10


def parse_field(field: str, allow_mri: bool = False, allow_private: bool = False) -> MetricField:
def parse_field(field: str, allow_mri: bool = False) -> MetricField:

if allow_mri:
mri_matches = MRI_SCHEMA_REGEX.match(field) or MRI_EXPRESSION_REGEX.match(field)
if mri_matches:
return parse_mri_field(field, allow_private)
return parse_mri_field(field)

return parse_public_field(field)


def parse_mri_field(field: str, allow_private: bool = False) -> MetricField:
def parse_mri_field(field: str) -> MetricField:
matches = MRI_EXPRESSION_REGEX.match(field)

try:
Expand All @@ -108,8 +108,7 @@ def parse_mri_field(field: str, allow_private: bool = False) -> MetricField:
except (IndexError, TypeError):
operation = None
mri = field

return MetricField(operation, mri, alias=mri, allow_private=allow_private)
return MetricField(operation, mri, alias=mri)


def parse_public_field(field: str) -> MetricField:
Expand Down Expand Up @@ -474,12 +473,7 @@ def __init__(
MetricGroupByField(groupby_col) for groupby_col in query_params.getlist("groupBy", [])
]
self.fields = [
parse_field(
key,
allow_mri=allow_mri,
allow_private=bool(query_params.get("allowPrivate", False)),
)
for key in query_params.getlist("field", [])
parse_field(key, allow_mri=allow_mri) for key in query_params.getlist("field", [])
]
self.orderby = self._parse_orderby(query_params, allow_mri)
self.limit: Optional[Limit] = self._parse_limit(paginator_kwargs)
Expand Down

0 comments on commit 09d8c7d

Please sign in to comment.