Skip to content
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

ref(eap): Move V0 implementations to their own directory #6329

Closed
wants to merge 3 commits into from
Closed
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
49 changes: 34 additions & 15 deletions snuba/web/rpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,41 @@
)

from snuba.utils.metrics.timer import Timer
from snuba.web.rpc.span_samples import span_samples_query
from snuba.web.rpc.timeseries import timeseries_query
from snuba.web.rpc.trace_item_attribute_list import trace_item_attribute_list_query
from snuba.web.rpc.trace_item_attribute_values import trace_item_attribute_values_query
from snuba.web.rpc.v1alpha.span_samples import span_samples_query
from snuba.web.rpc.v1alpha.timeseries import timeseries_query
from snuba.web.rpc.v1alpha.trace_item_attribute_list import (
trace_item_attribute_list_query,
)
from snuba.web.rpc.v1alpha.trace_item_attribute_values import (
trace_item_attribute_values_query,
)

Version = str
EndpointName = str

ALL_RPCS: Mapping[
str, Tuple[Callable[[Any, Timer], ProtobufMessage], type[ProtobufMessage]]
Version,
Mapping[
EndpointName,
Tuple[Callable[[Any, Timer], ProtobufMessage], type[ProtobufMessage]],
],
] = {
"AggregateBucketRequest": (timeseries_query, AggregateBucketRequest),
"SpanSamplesRequest": (span_samples_query, SpanSamplesRequest),
"TraceItemAttributesRequest": (
trace_item_attribute_list_query,
TraceItemAttributesRequest,
),
"AttributeValuesRequest": (
trace_item_attribute_values_query,
AttributeValuesRequest,
),
"v1alpha": {
"AggregateBucketRequest": (timeseries_query, AggregateBucketRequest),
"SpanSamplesRequest": (span_samples_query, SpanSamplesRequest),
"TraceItemAttributesRequest": (
trace_item_attribute_list_query,
TraceItemAttributesRequest,
),
"AttributeValuesRequest": (
trace_item_attribute_values_query,
AttributeValuesRequest,
),
}
}


def get_rpc_endpoint(
name: str, version: str
) -> Tuple[Callable[[Any, Timer], ProtobufMessage], type[ProtobufMessage]]:
return ALL_RPCS[version][name]
Empty file.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions snuba/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from snuba.web.converters import DatasetConverter, EntityConverter, StorageConverter
from snuba.web.delete_query import DeletesNotEnabledError, delete_from_storage
from snuba.web.query import parse_and_run_query
from snuba.web.rpc import ALL_RPCS
from snuba.web.rpc import get_rpc_endpoint
from snuba.web.rpc.exceptions import BadSnubaRPCRequestException
from snuba.writer import BatchWriterEncoderWrapper, WriterTableRow

Expand Down Expand Up @@ -272,11 +272,11 @@ def unqualified_query_view(*, timer: Timer) -> Union[Response, str, WerkzeugResp
assert False, "unexpected fallthrough"


@application.route("/rpc/<name>", methods=["POST"])
@util.time_request("timeseries")
def rpc(*, name: str, timer: Timer) -> Response:
@application.route("/rpc/<name>/<version>", methods=["POST"])
@util.time_request("rpc")
def rpc(*, name: str, version: str, timer: Timer) -> Response:
try:
endpoint, req_class = ALL_RPCS[name]
endpoint, req_class = get_rpc_endpoint(name, version)

req = req_class()
req.ParseFromString(http_request.data)
Expand Down
4 changes: 2 additions & 2 deletions tests/web/rpc/test_span_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from snuba.datasets.storages.factory import get_storage
from snuba.datasets.storages.storage_key import StorageKey
from snuba.web.rpc.span_samples import span_samples_query
from snuba.web.rpc.v1alpha.span_samples import span_samples_query
from tests.base import BaseApiTest
from tests.helpers import write_raw_unprocessed_events

Expand Down Expand Up @@ -141,7 +141,7 @@ def test_basic(self) -> None:
limit=10,
)
response = self.app.post(
"/rpc/SpanSamplesRequest", data=message.SerializeToString()
"/rpc/SpanSamplesRequest/v1alpha", data=message.SerializeToString()
)
assert response.status_code == 200, response.text

Expand Down
4 changes: 2 additions & 2 deletions tests/web/rpc/test_timeseries_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from snuba.datasets.storages.factory import get_storage
from snuba.datasets.storages.storage_key import StorageKey
from snuba.web.rpc.timeseries import timeseries_query
from snuba.web.rpc.v1alpha.timeseries import timeseries_query
from tests.base import BaseApiTest
from tests.helpers import write_raw_unprocessed_events

Expand Down Expand Up @@ -127,7 +127,7 @@ def test_basic(self) -> None:
granularity_secs=60,
)
response = self.app.post(
"/rpc/AggregateBucketRequest", data=message.SerializeToString()
"/rpc/AggregateBucketRequest/v1alpha", data=message.SerializeToString()
)
assert response.status_code == 200

Expand Down
6 changes: 4 additions & 2 deletions tests/web/rpc/test_trace_item_attribute_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

from snuba.datasets.storages.factory import get_storage
from snuba.datasets.storages.storage_key import StorageKey
from snuba.web.rpc.trace_item_attribute_list import trace_item_attribute_list_query
from snuba.web.rpc.v1alpha.trace_item_attribute_list import (
trace_item_attribute_list_query,
)
from tests.base import BaseApiTest
from tests.helpers import write_raw_unprocessed_events

Expand Down Expand Up @@ -99,7 +101,7 @@ def test_basic(self) -> None:
offset=20,
)
response = self.app.post(
"/rpc/TraceItemAttributesRequest", data=message.SerializeToString()
"/rpc/TraceItemAttributesRequest/v1alpha", data=message.SerializeToString()
)
assert response.status_code == 200

Expand Down
4 changes: 3 additions & 1 deletion tests/web/rpc/test_trace_item_attribute_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

from snuba.datasets.storages.factory import get_storage
from snuba.datasets.storages.storage_key import StorageKey
from snuba.web.rpc.trace_item_attribute_values import trace_item_attribute_values_query
from snuba.web.rpc.v1alpha.trace_item_attribute_values import (
trace_item_attribute_values_query,
)
from tests.base import BaseApiTest
from tests.helpers import write_raw_unprocessed_events

Expand Down
Loading