Skip to content

Commit

Permalink
fix: Move rpc stuff to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
wmak committed Oct 2, 2024
1 parent 9d79b81 commit 1c106d7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 91 deletions.
91 changes: 0 additions & 91 deletions src/sentry/snuba/spans_eap.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import logging
from collections.abc import Mapping, Sequence
from datetime import timedelta
from typing import Any

import sentry_sdk
from snuba_sdk import Column, Condition

from sentry.discover.arithmetic import categorize_columns
from sentry.models.organization import Organization
from sentry.search.eap.types import SearchResolverConfig
from sentry.search.events.builder.spans_indexed import (
SpansEAPQueryBuilder,
TimeseriesSpanEAPIndexedQueryBuilder,
Expand All @@ -19,7 +17,6 @@
from sentry.snuba.dataset import Dataset
from sentry.snuba.metrics.extraction import MetricSpecType
from sentry.snuba.query_sources import QuerySource
from sentry.snuba.referrer import Referrer
from sentry.utils.snuba import SnubaTSResult, bulk_snuba_queries

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -293,91 +290,3 @@ def top_events_timeseries(
)

return top_events_results


"""The run_*_query functions below will replace the ones above, and are the ones which will call the RPC instead of
snql"""


def run_table_query(
params: SnubaParams,
query_string: str,
selected_columns: list[str], # Aggregations & Fields?
orderby: list[str],
offset: int,
limit: int,
referrer: Referrer,
config: SearchResolverConfig,
) -> Any:
pass
"""Make the query"""
# maker = SearchResolver(params)
# columns, contexts = maker.resolve_columns(selected_columns)
# query = maker.resolve_query(query_string)

"""Run the query"""
# rpc = table_RPC(columns=[column.proto_definition for column in columns], query=query)
# result = rpc.run()

"""Process the results"""
# for row in result:
# for column in columns:
# column.process(row)
# return result


def run_timeseries_query(
params: SnubaParams,
query_string: str,
y_axes: list[str],
groupby: list[str],
) -> Any:
pass
"""Make the query"""
# maker = SearchResolver(params)
# groupby, contexts = maker.resolve_columns(groupby)
# yaxes = maker.resolve_aggregate(y_axes)
# query = maker.resolve_query(query_string)

"""Run the query"""
# rpc = timeseries_RPC(columns=[column.proto_definition for column in groupby], query=query)
# result = rpc.run()

"""Process the results"""
# return _process_timeseries(result, columns)


def run_top_events_timeseries_query(
params: SnubaParams,
query_string: str,
y_axes: list[str],
groupby: list[str],
orderby: list[str],
) -> Any:
"""We intentionally duplicate run_timeseries_query code here to reduce the complexity of needing multiple helper
functions that both would call
This is because at time of writing, the query construction is very straightforward, if that changes perhaps we can
change this"""
pass
"""Make the query"""
# maker = SearchResolver(params)
# top_events = run_table_query() with process_results off
# new_conditions = construct conditions based on top_events
# resolved_query = And(new_conditions, maker.resolve_query(query_string))
# groupby, contexts = maker.resolve_columns(groupby)
# yaxes = maker.resolve_aggregate(y_axes)

"""Run the query"""
# rpc = timeseries_RPC(columns=[column.proto_definition for column in groupby], query=query)

"""Process the results"""
# result = rpc.run()
# return _process_timeseries(result, columns)


def _process_timeseries(result, columns):
pass
# for row in result:
# for column in columns:
# column.process(row)
# return result
89 changes: 89 additions & 0 deletions src/sentry/snuba/spans_rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing import Any

from sentry.search.eap.types import SearchResolverConfig
from sentry.search.events.types import SnubaParams
from sentry.snuba.referrer import Referrer


def run_table_query(
params: SnubaParams,
query_string: str,
selected_columns: list[str], # Aggregations & Fields?
orderby: list[str],
offset: int,
limit: int,
referrer: Referrer,
config: SearchResolverConfig,
) -> Any:
pass
"""Make the query"""
# maker = SearchResolver(params)
# columns, contexts = maker.resolve_columns(selected_columns)
# query = maker.resolve_query(query_string)

"""Run the query"""
# rpc = table_RPC(columns=[column.proto_definition for column in columns], query=query)
# result = rpc.run()

"""Process the results"""
# for row in result:
# for column in columns:
# column.process(row)
# return result


def run_timeseries_query(
params: SnubaParams,
query_string: str,
y_axes: list[str],
groupby: list[str],
) -> Any:
pass
"""Make the query"""
# maker = SearchResolver(params)
# groupby, contexts = maker.resolve_columns(groupby)
# yaxes = maker.resolve_aggregate(y_axes)
# query = maker.resolve_query(query_string)

"""Run the query"""
# rpc = timeseries_RPC(columns=[column.proto_definition for column in groupby], query=query)
# result = rpc.run()

"""Process the results"""
# return _process_timeseries(result, columns)


def run_top_events_timeseries_query(
params: SnubaParams,
query_string: str,
y_axes: list[str],
groupby: list[str],
orderby: list[str],
) -> Any:
"""We intentionally duplicate run_timeseries_query code here to reduce the complexity of needing multiple helper
functions that both would call
This is because at time of writing, the query construction is very straightforward, if that changes perhaps we can
change this"""
pass
"""Make the query"""
# maker = SearchResolver(params)
# top_events = run_table_query() with process_results off
# new_conditions = construct conditions based on top_events
# resolved_query = And(new_conditions, maker.resolve_query(query_string))
# groupby, contexts = maker.resolve_columns(groupby)
# yaxes = maker.resolve_aggregate(y_axes)

"""Run the query"""
# rpc = timeseries_RPC(columns=[column.proto_definition for column in groupby], query=query)

"""Process the results"""
# result = rpc.run()
# return _process_timeseries(result, columns)


def _process_timeseries(result, columns):
pass
# for row in result:
# for column in columns:
# column.process(row)
# return result

0 comments on commit 1c106d7

Please sign in to comment.