Skip to content

feat(discover): Update EAP dataset and entity key for discover builders #78967

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

Merged
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
16 changes: 12 additions & 4 deletions src/sentry/search/events/builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
SnubaParams,
WhereType,
)
from sentry.snuba.dataset import Dataset
from sentry.snuba.dataset import Dataset, EntityKey
from sentry.snuba.metrics.utils import MetricMeta
from sentry.snuba.query_sources import QuerySource
from sentry.users.services.user.service import user_service
Expand All @@ -75,6 +75,12 @@
)
from sentry.utils.validators import INVALID_ID_DETAILS, INVALID_SPAN_ID, WILDCARD_NOT_ALLOWED

DATASET_TO_ENTITY_MAP: Mapping[Dataset, EntityKey] = {
Dataset.Events: EntityKey.Events,
Dataset.Transactions: EntityKey.Transactions,
Dataset.EventsAnalyticsPlatform: EntityKey.EAPSpans,
}


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

def _get_dataset_name(self) -> str:
def _get_entity_name(self) -> str:
if self.dataset in DATASET_TO_ENTITY_MAP:
return DATASET_TO_ENTITY_MAP[self.dataset].value
Comment on lines +1506 to +1508
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered adding DATASET_TO_ENTITY_MAP to snuba/dataset.py, but this feels more like a discover detail to me. The relationship between dataset to entity isn't actually 1:1 and the dataset name is not always equal to the entity name either. I think this is good enough for now, but we probably want to refactor this part of the builder in the future.

return self.dataset.value

def get_snql_query(self) -> Request:
self.validate_having_clause()

return Request(
dataset=self._get_dataset_name(),
dataset=self.dataset.value,
app_id="default",
query=Query(
match=Entity(self.dataset.value, sample=self.sample_rate),
match=Entity(self._get_entity_name(), sample=self.sample_rate),
select=self.columns,
array_join=self.array_join,
where=self.where,
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/search/events/builder/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def select(self) -> list[SelectType]:

def get_snql_query(self) -> Request:
return Request(
dataset=self._get_dataset_name(),
dataset=self.dataset.value,
app_id="default",
query=Query(
match=Entity(self.dataset.value),
match=Entity(self._get_entity_name()),
select=self.select,
where=self.where,
having=self.having,
Expand Down
6 changes: 0 additions & 6 deletions src/sentry/search/events/builder/spans_indexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)
from sentry.search.events.fields import custom_time_processor
from sentry.search.events.types import SelectType
from sentry.snuba.dataset import Dataset

SPAN_UUID_FIELDS = {
"trace",
Expand Down Expand Up @@ -69,11 +68,6 @@ class SpansEAPQueryBuilder(SpansIndexedQueryBuilderMixin, BaseQueryBuilder):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def _get_dataset_name(self) -> str:
if self.dataset == Dataset.SpansEAP:
return "events_analytics_platform"
return self.dataset.value

def resolve_field(self, raw_field: str, alias: bool = False) -> Column:
# try the typed regex first
if len(raw_field) <= 200:
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/snuba/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Dataset(Enum):
indexed spans are similar to indexed transactions in the fields available to search
"""

SpansEAP = "eap_spans"
EventsAnalyticsPlatform = "events_analytics_platform"

MetricsSummaries = "metrics_summaries"
"""
Expand All @@ -66,6 +66,7 @@ class EntityKey(Enum):
Events = "events"
Sessions = "sessions"
Spans = "spans"
EAPSpans = "eap_spans"
Transactions = "transactions"
MetricsSets = "metrics_sets"
MetricsCounters = "metrics_counters"
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/snuba/spans_eap.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def query(
enable_rpc: bool | None = False,
):
builder = SpansEAPQueryBuilder(
Dataset.SpansEAP,
Dataset.EventsAnalyticsPlatform,
{},
snuba_params=snuba_params,
query=query,
Expand Down Expand Up @@ -105,7 +105,7 @@ def timeseries_query(

with sentry_sdk.start_span(op="spans_indexed", name="TimeseriesSpanIndexedQueryBuilder"):
querybuilder = TimeseriesSpanEAPIndexedQueryBuilder(
Dataset.SpansEAP,
Dataset.EventsAnalyticsPlatform,
{},
rollup,
snuba_params=snuba_params,
Expand Down Expand Up @@ -185,7 +185,7 @@ def top_events_timeseries(
)

top_events_builder = TopEventsSpanEAPQueryBuilder(
Dataset.SpansEAP,
Dataset.EventsAnalyticsPlatform,
{},
rollup,
top_events["data"],
Expand All @@ -202,7 +202,7 @@ def top_events_timeseries(
)
if len(top_events["data"]) == limit and include_other:
other_events_builder = TopEventsSpanEAPQueryBuilder(
Dataset.SpansEAP,
Dataset.EventsAnalyticsPlatform,
{},
rollup,
top_events["data"],
Expand Down
10 changes: 5 additions & 5 deletions src/sentry/utils/snuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def log_snuba_info(content):
Dataset.MetricsSummaries: METRICS_SUMMARIES_COLUMN_MAP,
Dataset.PerformanceMetrics: METRICS_COLUMN_MAP,
Dataset.SpansIndexed: SPAN_COLUMN_MAP,
Dataset.SpansEAP: SPAN_EAP_COLUMN_MAP,
Dataset.EventsAnalyticsPlatform: SPAN_EAP_COLUMN_MAP,
Dataset.IssuePlatform: ISSUE_PLATFORM_MAP,
Dataset.Replays: {},
}
Expand All @@ -300,7 +300,7 @@ def log_snuba_info(content):
Dataset.Sessions: SESSIONS_FIELD_LIST,
Dataset.IssuePlatform: list(ISSUE_PLATFORM_MAP.values()),
Dataset.SpansIndexed: list(SPAN_COLUMN_MAP.values()),
Dataset.SpansEAP: list(SPAN_EAP_COLUMN_MAP.values()),
Dataset.EventsAnalyticsPlatform: list(SPAN_EAP_COLUMN_MAP.values()),
Dataset.MetricsSummaries: list(METRICS_SUMMARIES_COLUMN_MAP.values()),
}

Expand Down Expand Up @@ -1417,7 +1417,7 @@ def _resolve_column(col):
if isinstance(col, int) or isinstance(col, float):
return col
if (
dataset != Dataset.SpansEAP
dataset != Dataset.EventsAnalyticsPlatform
and isinstance(col, str)
and (col.startswith("tags[") or QUOTED_LITERAL_RE.match(col))
):
Expand All @@ -1428,7 +1428,7 @@ def _resolve_column(col):

if isinstance(col, (list, tuple)) or col in ("project_id", "group_id"):
return col
elif dataset == Dataset.SpansEAP:
elif dataset == Dataset.EventsAnalyticsPlatform:
if isinstance(col, str) and col.startswith("sentry_tags["):
# Replace the first instance of sentry tags with attr str instead
return col.replace("sentry_tags", "attr_str", 1)
Expand Down Expand Up @@ -1460,7 +1460,7 @@ def _resolve_column(col):
span_op_breakdown_name = get_span_op_breakdown_name(col)
if "span_op_breakdowns_key" in DATASETS[dataset] and span_op_breakdown_name:
return f"span_op_breakdowns[{span_op_breakdown_name}]"
if dataset == Dataset.SpansEAP:
if dataset == Dataset.EventsAnalyticsPlatform:
return f"attr_str[{col}]"
return f"tags[{col}]"

Expand Down
Loading