Skip to content

Commit 110de8b

Browse files
edwardgou-sentrycmanallen
authored andcommitted
feat(discover): Update EAP dataset and entity key for discover builders (#78967)
Updates EAP dataset to correctly be `events_analytics_platform` and add entity key for `eap_spans`. Also updates discover builders to stop using `_get_dataset_name` and start using `_get_entity_name` instead. This is needed because the AlertRule model obtains and stores it's `dataset` from the UI via POST api call. We need to use the proper `events_analytics_platform` dataset string so we can pass validation when creating the snuba subscription. With these changes, we will also be able to pass any discover builder validation when creating the query from the AlertRule.
1 parent ca88cd9 commit 110de8b

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

Diff for: src/sentry/search/events/builder/base.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
SnubaParams,
5757
WhereType,
5858
)
59-
from sentry.snuba.dataset import Dataset
59+
from sentry.snuba.dataset import Dataset, EntityKey
6060
from sentry.snuba.metrics.utils import MetricMeta
6161
from sentry.snuba.query_sources import QuerySource
6262
from sentry.users.services.user.service import user_service
@@ -75,6 +75,12 @@
7575
)
7676
from sentry.utils.validators import INVALID_ID_DETAILS, INVALID_SPAN_ID, WILDCARD_NOT_ALLOWED
7777

78+
DATASET_TO_ENTITY_MAP: Mapping[Dataset, EntityKey] = {
79+
Dataset.Events: EntityKey.Events,
80+
Dataset.Transactions: EntityKey.Transactions,
81+
Dataset.EventsAnalyticsPlatform: EntityKey.EAPSpans,
82+
}
83+
7884

7985
class BaseQueryBuilder:
8086
requires_organization_condition: bool = False
@@ -1497,17 +1503,19 @@ def get_public_alias(self, function: CurriedFunction) -> str:
14971503
"""
14981504
return self.function_alias_map[function.alias].field
14991505

1500-
def _get_dataset_name(self) -> str:
1506+
def _get_entity_name(self) -> str:
1507+
if self.dataset in DATASET_TO_ENTITY_MAP:
1508+
return DATASET_TO_ENTITY_MAP[self.dataset].value
15011509
return self.dataset.value
15021510

15031511
def get_snql_query(self) -> Request:
15041512
self.validate_having_clause()
15051513

15061514
return Request(
1507-
dataset=self._get_dataset_name(),
1515+
dataset=self.dataset.value,
15081516
app_id="default",
15091517
query=Query(
1510-
match=Entity(self.dataset.value, sample=self.sample_rate),
1518+
match=Entity(self._get_entity_name(), sample=self.sample_rate),
15111519
select=self.columns,
15121520
array_join=self.array_join,
15131521
where=self.where,

Diff for: src/sentry/search/events/builder/discover.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ def select(self) -> list[SelectType]:
221221

222222
def get_snql_query(self) -> Request:
223223
return Request(
224-
dataset=self._get_dataset_name(),
224+
dataset=self.dataset.value,
225225
app_id="default",
226226
query=Query(
227-
match=Entity(self.dataset.value),
227+
match=Entity(self._get_entity_name()),
228228
select=self.select,
229229
where=self.where,
230230
having=self.having,

Diff for: src/sentry/search/events/builder/spans_indexed.py

-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
)
1212
from sentry.search.events.fields import custom_time_processor
1313
from sentry.search.events.types import SelectType
14-
from sentry.snuba.dataset import Dataset
1514

1615
SPAN_UUID_FIELDS = {
1716
"trace",
@@ -69,11 +68,6 @@ class SpansEAPQueryBuilder(SpansIndexedQueryBuilderMixin, BaseQueryBuilder):
6968
def __init__(self, *args, **kwargs):
7069
super().__init__(*args, **kwargs)
7170

72-
def _get_dataset_name(self) -> str:
73-
if self.dataset == Dataset.SpansEAP:
74-
return "events_analytics_platform"
75-
return self.dataset.value
76-
7771
def resolve_field(self, raw_field: str, alias: bool = False) -> Column:
7872
# try the typed regex first
7973
if len(raw_field) <= 200:

Diff for: src/sentry/snuba/dataset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Dataset(Enum):
5252
indexed spans are similar to indexed transactions in the fields available to search
5353
"""
5454

55-
SpansEAP = "eap_spans"
55+
EventsAnalyticsPlatform = "events_analytics_platform"
5656

5757
MetricsSummaries = "metrics_summaries"
5858
"""
@@ -66,6 +66,7 @@ class EntityKey(Enum):
6666
Events = "events"
6767
Sessions = "sessions"
6868
Spans = "spans"
69+
EAPSpans = "eap_spans"
6970
Transactions = "transactions"
7071
MetricsSets = "metrics_sets"
7172
MetricsCounters = "metrics_counters"

Diff for: src/sentry/snuba/spans_eap.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def query(
5252
enable_rpc: bool | None = False,
5353
):
5454
builder = SpansEAPQueryBuilder(
55-
Dataset.SpansEAP,
55+
Dataset.EventsAnalyticsPlatform,
5656
{},
5757
snuba_params=snuba_params,
5858
query=query,
@@ -105,7 +105,7 @@ def timeseries_query(
105105

106106
with sentry_sdk.start_span(op="spans_indexed", name="TimeseriesSpanIndexedQueryBuilder"):
107107
querybuilder = TimeseriesSpanEAPIndexedQueryBuilder(
108-
Dataset.SpansEAP,
108+
Dataset.EventsAnalyticsPlatform,
109109
{},
110110
rollup,
111111
snuba_params=snuba_params,
@@ -185,7 +185,7 @@ def top_events_timeseries(
185185
)
186186

187187
top_events_builder = TopEventsSpanEAPQueryBuilder(
188-
Dataset.SpansEAP,
188+
Dataset.EventsAnalyticsPlatform,
189189
{},
190190
rollup,
191191
top_events["data"],
@@ -202,7 +202,7 @@ def top_events_timeseries(
202202
)
203203
if len(top_events["data"]) == limit and include_other:
204204
other_events_builder = TopEventsSpanEAPQueryBuilder(
205-
Dataset.SpansEAP,
205+
Dataset.EventsAnalyticsPlatform,
206206
{},
207207
rollup,
208208
top_events["data"],

Diff for: src/sentry/utils/snuba.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def log_snuba_info(content):
290290
Dataset.MetricsSummaries: METRICS_SUMMARIES_COLUMN_MAP,
291291
Dataset.PerformanceMetrics: METRICS_COLUMN_MAP,
292292
Dataset.SpansIndexed: SPAN_COLUMN_MAP,
293-
Dataset.SpansEAP: SPAN_EAP_COLUMN_MAP,
293+
Dataset.EventsAnalyticsPlatform: SPAN_EAP_COLUMN_MAP,
294294
Dataset.IssuePlatform: ISSUE_PLATFORM_MAP,
295295
Dataset.Replays: {},
296296
}
@@ -305,7 +305,7 @@ def log_snuba_info(content):
305305
Dataset.Sessions: SESSIONS_FIELD_LIST,
306306
Dataset.IssuePlatform: list(ISSUE_PLATFORM_MAP.values()),
307307
Dataset.SpansIndexed: list(SPAN_COLUMN_MAP.values()),
308-
Dataset.SpansEAP: list(SPAN_EAP_COLUMN_MAP.values()),
308+
Dataset.EventsAnalyticsPlatform: list(SPAN_EAP_COLUMN_MAP.values()),
309309
Dataset.MetricsSummaries: list(METRICS_SUMMARIES_COLUMN_MAP.values()),
310310
}
311311

@@ -1422,7 +1422,7 @@ def _resolve_column(col):
14221422
if isinstance(col, int) or isinstance(col, float):
14231423
return col
14241424
if (
1425-
dataset != Dataset.SpansEAP
1425+
dataset != Dataset.EventsAnalyticsPlatform
14261426
and isinstance(col, str)
14271427
and (col.startswith("tags[") or QUOTED_LITERAL_RE.match(col))
14281428
):
@@ -1433,7 +1433,7 @@ def _resolve_column(col):
14331433

14341434
if isinstance(col, (list, tuple)) or col in ("project_id", "group_id"):
14351435
return col
1436-
elif dataset == Dataset.SpansEAP:
1436+
elif dataset == Dataset.EventsAnalyticsPlatform:
14371437
if isinstance(col, str) and col.startswith("sentry_tags["):
14381438
# Replace the first instance of sentry tags with attr str instead
14391439
return col.replace("sentry_tags", "attr_str", 1)
@@ -1465,7 +1465,7 @@ def _resolve_column(col):
14651465
span_op_breakdown_name = get_span_op_breakdown_name(col)
14661466
if "span_op_breakdowns_key" in DATASETS[dataset] and span_op_breakdown_name:
14671467
return f"span_op_breakdowns[{span_op_breakdown_name}]"
1468-
if dataset == Dataset.SpansEAP:
1468+
if dataset == Dataset.EventsAnalyticsPlatform:
14691469
return f"attr_str[{col}]"
14701470
return f"tags[{col}]"
14711471

0 commit comments

Comments
 (0)