Skip to content

Commit

Permalink
make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
volokluev committed Sep 19, 2024
1 parent 6b2e730 commit 4430a84
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 42 deletions.
51 changes: 51 additions & 0 deletions snuba/web/rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import Any, Callable, Mapping, Tuple

from google.protobuf.message import Message as ProtobufMessage
from sentry_protos.snuba.v1alpha.endpoint_aggregate_bucket_pb2 import (
AggregateBucketRequest,
)
from sentry_protos.snuba.v1alpha.endpoint_span_samples_pb2 import SpanSamplesRequest
from sentry_protos.snuba.v1alpha.endpoint_tags_list_pb2 import (
AttributeValuesRequest,
TraceItemAttributesRequest,
)

from snuba.utils.metrics.timer import Timer
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[
Version,
Mapping[
EndpointName,
Tuple[Callable[[Any, Timer], ProtobufMessage], type[ProtobufMessage]],
],
] = {
"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]
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions snuba/web/rpc/v1alpha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
from typing import Any, Callable, Mapping, Tuple

from google.protobuf.message import Message as ProtobufMessage
from sentry_protos.snuba.v1alpha.endpoint_aggregate_bucket_pb2 import (
AggregateBucketRequest,
)
from sentry_protos.snuba.v1alpha.endpoint_span_samples_pb2 import SpanSamplesRequest
from sentry_protos.snuba.v1alpha.endpoint_tags_list_pb2 import (
AttributeValuesRequest,
TraceItemAttributesRequest,
)

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

ALL_RPCS: Mapping[
str, 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,
),
}
8 changes: 4 additions & 4 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/<version>/<name>", methods=["POST"])
@application.route("/rpc/<name>/<version>", methods=["POST"])
@util.time_request("rpc")
def rpc(*, name: str, timer: Timer) -> Response:
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
4 changes: 3 additions & 1 deletion 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
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

0 comments on commit 4430a84

Please sign in to comment.