Skip to content

ref(resolvers): inline the trace item stats resolver - #8452

Open
MeredithAnya wants to merge 1 commit into
masterfrom
meredith/convert-resolver-stats
Open

ref(resolvers): inline the trace item stats resolver#8452
MeredithAnya wants to merge 1 commit into
masterfrom
meredith/convert-resolver-stats

Conversation

@MeredithAnya

Copy link
Copy Markdown
Member

Stack

  1. ref(resolvers): remove unused resolver declarations #8451 ref(resolvers): remove unused resolver declarations
  2. → #this ref(resolvers): inline the trace item stats resolver
  3. ref(resolvers): inline the time series resolver
  4. ref(resolvers): inline the trace item table resolver
  5. ref(resolvers): remove the TraceItemDataResolver abstraction

Why

TraceItemDataResolver exists to dispatch an endpoint to a different query implementation per TraceItemType — one for spans, one for logs, one for uptime checks. Those are all gone (76d1fed8f, cfaaad94d, 0077ce42f). ResolverTraceItemStatsEAPItems was the only implementation of ResolverTraceItemStats, registered under TRACE_ITEM_TYPE_UNSPECIFIED, so get_from_trace_item_type could only ever return it.

What

Moves the resolver module body into endpoint_trace_item_stats.py and turns resolve() into _query_trace_item_stats, following the EndpointGetTrace conversion in 76d1fed8f. Pure move — no logic changes.

resolve() took routing_decision as a parameter; the method now reads self.routing_decision, which RPCEndpoint sets before _execute runs. The seer.rpc tier downgrade still happens before the query is built.

Tests

Import/patch-target updates only, no logic changes. pytest tests/web/rpc/v1/test_endpoint_trace_item_stats.py and test_storage_routing.py pass; mypy snuba/web/rpc/ clean.

🤖 Generated with Claude Code

Comment thread snuba/web/rpc/v1/endpoint_trace_item_stats.py
@MeredithAnya
MeredithAnya added this pull request to stack #8456 September 9, 2026 23:52
Comment on lines +328 to +354
if requested_type.attribute_distributions.max_buckets > MAX_BUCKETS:
raise BadSnubaRPCRequestException(f"Max allowed buckets is {MAX_BUCKETS}.")

if len(requested_type.attribute_distributions.attributes) > MAX_REQUEST_ATTRIBUTES:
raise BadSnubaRPCRequestException(
f"Max allowed attributes is {MAX_REQUEST_ATTRIBUTES}."
)

query = _build_attr_distribution_query(
in_msg, requested_type.attribute_distributions
)
treeify_or_and_conditions(query)

snuba_request = _build_snuba_request(in_msg, query, routing_decision)
query_res = run_query(
dataset=PluggableDataset(name="eap", all_entities=[]),
request=snuba_request,
timer=self._timer,
)
routing_decision.routing_context.query_result = query_res

attributes = _transform_attr_distribution_results(
query_res.result.get("data", []), in_msg.meta
)
result.attribute_distributions.CopyFrom(
AttributeDistributions(attributes=attributes)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[non-blocking] I see we have a HeatmapBuilder already, how hard would it be to create/reuse a AttributeDistributionBuilder and keep the pattern between the two branches the same (i.e. foo = xxxBuilder(...).build(); result.blah.copyFrom(foo)?

I'd prefer if we could do that, but if it's not feasible I'm happy with just a TODO comment in here.

Base automatically changed from meredith/convert-resolvers to master September 10, 2026 19:49
ResolverTraceItemStatsEAPItems was the only implementation of
ResolverTraceItemStats, registered under TRACE_ITEM_TYPE_UNSPECIFIED, so
get_from_trace_item_type could only ever return it. Move the resolver
module body into endpoint_trace_item_stats.py and turn resolve() into
_query_trace_item_stats, following the EndpointGetTrace conversion in
76d1fed.

The seer.rpc tier downgrade still runs before the query is built.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MeredithAnya
MeredithAnya force-pushed the meredith/convert-resolver-stats branch from 9baa107 to ae638ef Compare September 10, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants