Skip to content

Commit

Permalink
fix(eap): Remove column processor preventing the use of an index (#6932)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Mar 5, 2025
1 parent 5eba344 commit 1ebc451
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ allocation_policies:

query_processors:
- processor: UniqInSelectAndHavingProcessor
- processor: UUIDColumnProcessor
args:
columns: [trace_id]
- processor: PrewhereProcessor
args:
prewhere_candidates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ allocation_policies:

query_processors:
- processor: UniqInSelectAndHavingProcessor
- processor: UUIDColumnProcessor
args:
columns: [trace_id]
- processor: PrewhereProcessor
args:
prewhere_candidates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ query_processors:
- processor: UniqInSelectAndHavingProcessor
- processor: UUIDColumnProcessor
args:
columns: [transaction_id, trace_id, profile_id]
columns: [transaction_id, profile_id]
- processor: HexIntColumnProcessor
args:
columns: [span_id, parent_span_id, segment_id]
Expand Down
2 changes: 2 additions & 0 deletions snuba/web/rpc/v1/endpoint_get_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def _convert_results(
] = defaultdict(TraceAttribute)
for attribute in request.attributes:
value = row[_ATTRIBUTES[attribute.key][0]]
if attribute.key == TraceAttribute.Key.KEY_TRACE_ID:
value = uuid.UUID(value).hex
type = _ATTRIBUTES[attribute.key][1]
values[attribute.key] = TraceAttribute(
key=attribute.key,
Expand Down
8 changes: 6 additions & 2 deletions snuba/web/rpc/v1/resolvers/R_eap_spans/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from snuba.query import Query
from snuba.query.dsl import Functions as f
from snuba.query.dsl import column, literal, literals_array
from snuba.query.expressions import Expression, SubscriptableReference
from snuba.query.expressions import Expression, FunctionCall, SubscriptableReference
from snuba.web.rpc.common.exceptions import BadSnubaRPCRequestException

# These are the columns which aren't stored in attr_str_ nor attr_num_ in clickhouse
Expand Down Expand Up @@ -51,7 +51,11 @@ def _build_label_mapping_key(attr_key: AttributeKey) -> str:

if attr_key.name == "sentry.trace_id":
if attr_key.type == AttributeKey.Type.TYPE_STRING:
return f.CAST(column("trace_id"), "String", alias=alias)
return FunctionCall(
alias,
"toUUID",
(column("trace_id"),),
)
raise BadSnubaRPCRequestException(
f"Attribute {attr_key.name} must be requested as a string, got {attr_key.type}"
)
Expand Down
11 changes: 5 additions & 6 deletions snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_get_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from snuba.datasets.pluggable_dataset import PluggableDataset
from snuba.query import OrderBy, OrderByDirection, SelectedExpression
from snuba.query.data_source.simple import Entity
from snuba.query.dsl import Functions as f
from snuba.query.dsl import and_cond, column, equals, literal
from snuba.query.expressions import FunctionCall
from snuba.query.logical import Query
Expand Down Expand Up @@ -128,12 +127,12 @@ def _build_query(request: GetTraceRequest) -> Query:
request.meta.end_timestamp.seconds,
),
equals(
f.cast(
column("trace_id"),
"String",
alias="trace_id",
column("trace_id"),
FunctionCall(
None,
"toUUID",
(literal(request.trace_id),),
),
literal(request.trace_id),
),
),
order_by=[
Expand Down
2 changes: 1 addition & 1 deletion tests/web/rpc/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_expression_trace_id(self) -> None:
type=AttributeKey.TYPE_STRING,
name="sentry.trace_id",
),
) == f.CAST(column("trace_id"), "String", alias="sentry.trace_id_TYPE_STRING")
) == f.toUUID(column("trace_id"), alias="sentry.trace_id_TYPE_STRING")

def test_timestamp_columns(self) -> None:
for col in [
Expand Down
1 change: 0 additions & 1 deletion tests/web/rpc/v1/test_endpoint_get_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ def test_with_data_and_filter(self, setup_teardown: Any) -> None:
def test_with_data_and_aggregated_fields_all_keys(
self, setup_teardown: Any
) -> None:

ts = Timestamp(seconds=int(_BASE_TIME.timestamp()))
three_hours_later = int((_BASE_TIME + timedelta(hours=3)).timestamp())
start_timestamp_per_trace_id: dict[str, float] = defaultdict(lambda: 2 * 1e10)
Expand Down

0 comments on commit 1ebc451

Please sign in to comment.