Skip to content

Commit

Permalink
cleanup(metrics): remove snuba tag value meta table references (#85193)
Browse files Browse the repository at this point in the history
These tag values tables aren't being accessed and we want to stop
writing to this table to reduce load on the
generic-metrics-distributions cluster in SaaS (see INC-1035)

(not making this change broke integration tests when I tried to merge
getsentry/snuba#6878 and that had to be
reverted)
  • Loading branch information
onewland authored Feb 13, 2025
1 parent cbcb6e7 commit a4a7ddb
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 563 deletions.
6 changes: 0 additions & 6 deletions src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@
OrganizationMetricsCompatibilitySums,
)
from .endpoints.organization_metrics_query import OrganizationMetricsQueryEndpoint
from .endpoints.organization_metrics_tag_details import OrganizationMetricsTagDetailsEndpoint
from .endpoints.organization_metrics_tags import OrganizationMetricsTagsEndpoint
from .endpoints.organization_on_demand_metrics_estimation_stats import (
OrganizationOnDemandMetricsEstimationStatsEndpoint,
Expand Down Expand Up @@ -2093,11 +2092,6 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
OrganizationMetricsTagsEndpoint.as_view(),
name="sentry-api-0-organization-metrics-tags",
),
re_path(
r"^(?P<organization_id_or_slug>[^/]+)/metrics/tags/(?P<tag_name>[^/]+)/$",
OrganizationMetricsTagDetailsEndpoint.as_view(),
name="sentry-api-0-organization-metrics-tag-details",
),
re_path(
r"^(?P<organization_id_or_slug>[^/]+)/profiling/",
include(
Expand Down
14 changes: 4 additions & 10 deletions src/sentry/sentry_metrics/querying/metadata/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sentry.models.organization import Organization
from sentry.models.project import Project
from sentry.sentry_metrics.use_case_id_registry import UseCaseID
from sentry.snuba.metrics_layer.query import fetch_metric_tag_keys, fetch_metric_tag_values
from sentry.snuba.metrics_layer.query import fetch_metric_tag_keys


@dataclass
Expand Down Expand Up @@ -45,14 +45,8 @@ def get_tag_values(
tag_value_prefix: str = "",
) -> list[str]:
"""
DEPRECATED: This query path is not in use in production
Get all available tag values for an MRI and tag key from metrics.
"""
project_ids = [project.id for project in projects]
tag_values: set[str] = set()
for use_case_id in use_case_ids:
use_case_tag_values = fetch_metric_tag_values(
organization.id, project_ids, use_case_id, mri, tag_key, tag_value_prefix
)
tag_values = tag_values.union(use_case_tag_values)

return list(tag_values)
return []
68 changes: 0 additions & 68 deletions src/sentry/snuba/metrics_layer/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from sentry.sentry_metrics.use_case_id_registry import UseCaseID
from sentry.sentry_metrics.utils import (
bulk_reverse_resolve,
resolve_many_weak,
resolve_weak,
reverse_resolve_weak,
string_to_use_case_id,
Expand Down Expand Up @@ -639,70 +638,3 @@ def build_request(query: Query) -> Request:
grouped_results.setdefault(row["project_id"], list()).append(val)

return grouped_results


def fetch_metric_tag_values(
org_id: int,
project_ids: list[int],
use_case_id: UseCaseID,
mri: str,
tag_key: str,
tag_value_prefix: str = "",
app_id: str = "",
) -> list[str]:
"""
Find all the unique tag values for a given MRI and tag key. This will reverse resolve
all the values.
"""
parsed_mri = parse_mri(mri)
if parsed_mri is None:
raise InvalidParams(f"'{mri}' is not a valid MRI")

metric_type = {
"c": "counters",
"d": "distributions",
"g": "gauges",
"s": "sets",
}[parsed_mri.entity]

resolved = resolve_many_weak(use_case_id, org_id, [mri, tag_key])
if len(resolved) != 2:
raise InvalidParams("Unknown metric or tag key")
metric_id, tag_key_id = resolved

conditions = [
Condition(Column("project_id"), Op.IN, project_ids),
Condition(Column("metric_id"), Op.EQ, metric_id),
Condition(Column("tag_key"), Op.EQ, tag_key_id),
Condition(Column("timestamp"), Op.GTE, datetime.now(UTC) - timedelta(days=90)),
Condition(Column("timestamp"), Op.LT, datetime.now(UTC) + timedelta(days=1)),
]

if tag_value_prefix:
conditions.append(Condition(Column("tag_value"), Op.LIKE, f"{tag_value_prefix}%"))

tag_values_query = (
Query(Storage(f"generic_metrics_{metric_type}_meta_tag_values"))
.set_select([Column("tag_value")])
.set_groupby([Column("tag_value")])
.set_where(conditions)
.set_orderby([OrderBy(Column("tag_value"), Direction.ASC)])
.set_limit(1000)
)

request = Request(
dataset="generic_metrics",
app_id=use_case_id.value if app_id == "" else app_id,
query=tag_values_query,
tenant_ids={
"organization_id": org_id,
"referrer": "generic_metrics_meta_tag_values",
},
)

results = bulk_snuba_queries([request], "generic_metrics_meta_tag_values")
values = []
for result in results:
values.extend([row["tag_value"] for row in result["data"]])

return values
22 changes: 9 additions & 13 deletions tests/sentry/api/endpoints/test_organization_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,21 @@


class OrganizationMetricsPermissionTest(APITestCase):
endpoints = (
(
"get",
"sentry-api-0-organization-metrics-details",
),
(
endpoints = [
["get", "sentry-api-0-organization-metrics-details"],
[
"get",
"sentry-api-0-organization-metrics-tags",
),
("get", "sentry-api-0-organization-metrics-tag-details", "foo"),
(
],
[
"get",
"sentry-api-0-organization-metrics-data",
),
(
],
[
"post",
"sentry-api-0-organization-metrics-query",
),
)
],
]

def setUp(self):
self.create_project(name="Bar", slug="bar", teams=[self.team], fire_project_created=True)
Expand Down
123 changes: 0 additions & 123 deletions tests/sentry/api/endpoints/test_organization_metrics_metadata.py

This file was deleted.

This file was deleted.

Loading

0 comments on commit a4a7ddb

Please sign in to comment.