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

chore(trace-item-types): throw an error if no trace item type is specified #6777

Merged
merged 6 commits into from
Jan 16, 2025
Merged
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
6 changes: 3 additions & 3 deletions snuba/web/rpc/v1/endpoint_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def _execute(self, in_msg: TimeSeriesRequest) -> TimeSeriesResponse:
)
_enforce_no_duplicate_labels(in_msg)
_validate_time_buckets(in_msg)
# NOTE: EAP spans was the first TraceItem, we didn't enforce a trace item name originally so we default to it
# for backwards compatibility
if in_msg.meta.trace_item_type == TraceItemType.TRACE_ITEM_TYPE_UNSPECIFIED:
in_msg.meta.trace_item_type = TraceItemType.TRACE_ITEM_TYPE_SPAN
raise BadSnubaRPCRequestException(
"This endpoint requires meta.trace_item_type to be set (are you requesting spans? logs?)"
)
resolver = self.get_resolver(in_msg.meta.trace_item_type)
return resolver.resolve(in_msg)
6 changes: 3 additions & 3 deletions snuba/web/rpc/v1/endpoint_trace_item_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def _execute(self, in_msg: TraceItemTableRequest) -> TraceItemTableResponse:
in_msg.meta.request_id = getattr(in_msg.meta, "request_id", None) or str(
uuid.uuid4()
)
# NOTE: EAP spans was the first TraceItem, we didn't enforce a trace item name originally so we default to it
# for backwards compatibility
if in_msg.meta.trace_item_type == TraceItemType.TRACE_ITEM_TYPE_UNSPECIFIED:
in_msg.meta.trace_item_type = TraceItemType.TRACE_ITEM_TYPE_SPAN
raise BadSnubaRPCRequestException(
"This endpoint requires meta.trace_item_type to be set (are you requesting spans? logs?)"
)
resolver = self.get_resolver(in_msg.meta.trace_item_type)
return resolver.resolve(in_msg)
2 changes: 2 additions & 0 deletions tests/manual_jobs/test_scrub_ips_from_eap_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PageToken,
RequestMeta,
ResponseMeta,
TraceItemType,
)
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey, AttributeValue
from sentry_protos.snuba.v1.trace_item_filter_pb2 import ExistsFilter, TraceItemFilter
Expand Down Expand Up @@ -212,6 +213,7 @@ def _generate_request(
start_timestamp=Timestamp(seconds=hour_ago),
end_timestamp=ts,
request_id="be3123b3-2e5d-4eb9-bb48-f38eaa9e8480",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
filter=TraceItemFilter(
exists_filter=ExistsFilter(
Expand Down
2 changes: 2 additions & 0 deletions tests/manual_jobs/test_scrub_users_from_eap_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PageToken,
RequestMeta,
ResponseMeta,
TraceItemType,
)
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey, AttributeValue
from sentry_protos.snuba.v1.trace_item_filter_pb2 import ExistsFilter, TraceItemFilter
Expand Down Expand Up @@ -211,6 +212,7 @@ def _generate_request(
start_timestamp=Timestamp(seconds=hour_ago),
end_timestamp=ts,
request_id="be3123b3-2e5d-4eb9-bb48-f38eaa9e8480",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
filter=TraceItemFilter(
exists_filter=ExistsFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TraceItemAttributeValuesRequest,
TraceItemAttributeValuesResponse,
)
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey

from snuba.datasets.storages.factory import get_storage
Expand Down Expand Up @@ -254,6 +254,7 @@ def get_attributes(key: str) -> TraceItemAttributeValuesResponse:
referrer="something",
start_timestamp=START_TS,
end_timestamp=END_TS,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
)


Expand Down
3 changes: 2 additions & 1 deletion tests/subscriptions/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CreateSubscriptionRequest as CreateSubscriptionRequestProto,
)
from sentry_protos.snuba.v1.endpoint_time_series_pb2 import TimeSeriesRequest
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -60,6 +60,7 @@ def build_rpc_subscription_data_from_proto(
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
4 changes: 3 additions & 1 deletion tests/subscriptions/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CreateSubscriptionRequest as CreateSubscriptionRequestProto,
)
from sentry_protos.snuba.v1.endpoint_time_series_pb2 import TimeSeriesRequest
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -112,6 +112,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -142,6 +143,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
3 changes: 2 additions & 1 deletion tests/subscriptions/test_scheduler_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CreateSubscriptionRequest as CreateSubscriptionRequestProto,
)
from sentry_protos.snuba.v1.endpoint_time_series_pb2 import TimeSeriesRequest
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -187,6 +187,7 @@ def test_scheduler_consumer_rpc_subscriptions(tmpdir: LocalPath) -> None:
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
3 changes: 2 additions & 1 deletion tests/subscriptions/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CreateSubscriptionRequest as CreateSubscriptionRequestProto,
)
from sentry_protos.snuba.v1.endpoint_time_series_pb2 import TimeSeriesRequest
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -355,6 +355,7 @@ def test(self) -> None:
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
8 changes: 7 additions & 1 deletion tests/web/rpc/v1/test_create_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from sentry_protos.snuba.v1.endpoint_time_series_pb2 import TimeSeriesRequest
from sentry_protos.snuba.v1.error_pb2 import Error
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -41,6 +41,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand All @@ -67,6 +68,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand All @@ -93,6 +95,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -127,6 +130,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
group_by=[
AttributeKey(type=AttributeKey.TYPE_STRING, name="device.class")
Expand Down Expand Up @@ -156,6 +160,7 @@
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -195,6 +200,7 @@ def test_create_valid_subscription(self) -> None:
organization_id=1,
cogs_category="something",
referrer="something",
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
3 changes: 2 additions & 1 deletion tests/web/rpc/v1/test_debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Column,
TraceItemTableRequest,
)
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey
from sentry_protos.snuba.v1.trace_item_filter_pb2 import ExistsFilter, TraceItemFilter

Expand Down Expand Up @@ -36,6 +36,7 @@ def _create_trace_item_table_request(debug: bool = False) -> TraceItemTableReque
end_timestamp=ts,
request_id=request_id,
debug=debug,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
filter=TraceItemFilter(
exists_filter=ExistsFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
TimeSeriesRequest,
)
from sentry_protos.snuba.v1.error_pb2 import Error
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta
from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta, TraceItemType
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import (
AttributeAggregation,
AttributeKey,
Expand Down Expand Up @@ -139,6 +139,7 @@ def test_basic(self) -> None:
referrer="something",
start_timestamp=tstart,
end_timestamp=ts,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -166,6 +167,38 @@ def test_basic(self) -> None:
error.ParseFromString(response.data)
assert response.status_code == 200, (error.message, error.details)

def test_errors_without_type(self) -> None:
ts = Timestamp()
ts.GetCurrentTime()
tstart = Timestamp(seconds=ts.seconds - 3600)
message = TimeSeriesRequest(
meta=RequestMeta(
project_ids=[1, 2, 3],
organization_id=1,
cogs_category="something",
referrer="something",
start_timestamp=tstart,
end_timestamp=ts,
),
aggregations=[
AttributeAggregation(
aggregate=Function.FUNCTION_COUNT,
key=AttributeKey(
type=AttributeKey.TYPE_FLOAT, name="sentry.duration"
),
label="count",
),
],
granularity_secs=60,
)
response = self.app.post(
"/rpc/EndpointTimeSeries/v1", data=message.SerializeToString()
)
error = Error()
if response.status_code != 200:
error.ParseFromString(response.data)
assert response.status_code == 400, error

def test_sum(self) -> None:
# store a a test metric with a value of 1, every second of one hour
granularity_secs = 300
Expand All @@ -187,6 +220,7 @@ def test_sum(self) -> None:
end_timestamp=Timestamp(
seconds=int(BASE_TIME.timestamp() + query_duration)
),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -259,6 +293,7 @@ def test_with_group_by(self) -> None:
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp() + 60 * 30)),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -339,6 +374,7 @@ def test_with_non_string_group_by(self) -> None:
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp() + 60 * 30)),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -392,6 +428,7 @@ def test_with_no_data_present(self) -> None:
end_timestamp=Timestamp(
seconds=int(BASE_TIME.timestamp() + query_duration)
),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -469,6 +506,7 @@ def test_with_filters(self) -> None:
seconds=int(BASE_TIME.timestamp() + query_duration)
),
debug=True,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -558,6 +596,7 @@ def test_with_unaligned_granularities(self) -> None:
seconds=int(BASE_TIME.timestamp()) + query_duration
),
debug=True,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -609,6 +648,7 @@ def test_start_time_not_divisible_by_time_buckets_returns_valid_data(self) -> No
end_timestamp=Timestamp(
seconds=int(BASE_TIME.timestamp() + query_duration + 1)
),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -644,6 +684,7 @@ def test_with_non_existent_attribute(self) -> None:
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp() + 60 * 30)),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down Expand Up @@ -685,6 +726,7 @@ def test_no_duplicate_labels(self) -> None:
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
debug=True,
),
aggregations=[
Expand Down Expand Up @@ -729,6 +771,7 @@ def test_bad_granularity(
start_timestamp=Timestamp(seconds=int(start_ts.timestamp())),
end_timestamp=Timestamp(seconds=int(end_ts.timestamp())),
debug=True,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand All @@ -754,6 +797,7 @@ def test_adjust_buckets(self) -> None:
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp()) + 65),
debug=True,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
Expand Down
Loading
Loading