Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snuba(devexp): Migrate meta queries to use storage direct queries #70794

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,13 @@
"sentry-metrics.indexer.reconstruct.enable-orjson", default=0.0, flags=FLAG_AUTOMATOR_MODIFIABLE
)

# Option to enable direct storage queries for meta queries in the metrics layer
register(
"sentry-metrics.metrics-layer.use-storage-direct-meta-queries",
default=0.0,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

# Global and per-organization limits on the writes to the string indexer's DB.
#
# Format is a list of dictionaries of format {
Expand Down
69 changes: 48 additions & 21 deletions src/sentry/snuba/metrics_layer/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
OrderBy,
Query,
Request,
Storage,
Timeseries,
)
from snuba_sdk.formula import FormulaParameterGroup
from snuba_sdk.mql.mql import parse_mql

from sentry.exceptions import InvalidParams
from sentry.features.rollout import in_random_rollout
from sentry.sentry_metrics.use_case_id_registry import UseCaseID
from sentry.sentry_metrics.utils import (
bulk_reverse_resolve,
Expand Down Expand Up @@ -584,19 +586,34 @@ def _query_meta_table(
if extra_condition:
conditions.append(extra_condition)

counters_query = (
Query(Entity("generic_metrics_counters_meta"))
.set_select([Column("project_id"), Column(column_name)])
.set_groupby([Column("project_id"), Column(column_name)])
.set_where(conditions)
.set_orderby(
[
OrderBy(Column("project_id"), Direction.ASC),
OrderBy(Column(column_name), Direction.ASC),
]
if in_random_rollout("sentry-metrics.metrics-layer.use-storage-direct-meta-queries"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where you able to run the CI tests using the storage-direct-meta-queries on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on CI with flag enabled 👍

counters_query = (
Query(Storage("generic_metrics_counters_meta"))
.set_select([Column("project_id"), Column(column_name)])
.set_groupby([Column("project_id"), Column(column_name)])
.set_where(conditions)
.set_orderby(
[
OrderBy(Column("project_id"), Direction.ASC),
OrderBy(Column(column_name), Direction.ASC),
]
)
.set_limit(1000)
)
else:
counters_query = (
Query(Entity("generic_metrics_counters_meta"))
.set_select([Column("project_id"), Column(column_name)])
.set_groupby([Column("project_id"), Column(column_name)])
.set_where(conditions)
.set_orderby(
[
OrderBy(Column("project_id"), Direction.ASC),
OrderBy(Column(column_name), Direction.ASC),
]
)
.set_limit(1000)
)
.set_limit(1000)
)

def build_request(query: Query) -> Request:
return Request(
Expand Down Expand Up @@ -649,7 +666,7 @@ def fetch_metric_tag_values(
if parsed_mri is None:
raise InvalidParams(f"'{mri}' is not a valid MRI")

entity = {
metric_type = {
"c": "counters",
"d": "distributions",
"g": "gauges",
Expand All @@ -672,14 +689,24 @@ def fetch_metric_tag_values(
if tag_value_prefix:
conditions.append(Condition(Column("tag_value"), Op.LIKE, f"{tag_value_prefix}%"))

tag_values_query = (
Query(Entity(f"generic_metrics_{entity}_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)
)
if in_random_rollout("sentry-metrics.metrics-layer.use-storage-direct-meta-queries"):
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)
)
else:
tag_values_query = (
Query(Entity(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",
Expand Down
Loading