-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eap): add virtual column support (#6292)
Add support for virtual columns to allow for sorting by project name or semver release (as opposed to release id).
- Loading branch information
Showing
4 changed files
with
180 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from sentry_protos.snuba.v1alpha.trace_item_attribute_pb2 import ( | ||
AttributeKey, | ||
AttributeValue, | ||
VirtualColumnContext, | ||
) | ||
from sentry_protos.snuba.v1alpha.trace_item_filter_pb2 import ( | ||
ComparisonFilter, | ||
|
@@ -24,6 +25,8 @@ | |
from tests.base import BaseApiTest | ||
from tests.helpers import write_raw_unprocessed_events | ||
|
||
_RELEASE_TAG = "[email protected]+c45b49caed1e5fcbf70097ab3f434b487c359b6b" | ||
|
||
|
||
def gen_message(dt: datetime) -> Mapping[str, Any]: | ||
return { | ||
|
@@ -34,7 +37,7 @@ def gen_message(dt: datetime) -> Mapping[str, Any]: | |
"is_segment": True, | ||
"data": { | ||
"sentry.environment": "development", | ||
"sentry.release": "[email protected]+c45b49caed1e5fcbf70097ab3f434b487c359b6b", | ||
"sentry.release": _RELEASE_TAG, | ||
"thread.name": "uWSGIWorker1Core0", | ||
"thread.id": "8522009600", | ||
"sentry.segment.name": "/api/0/relays/projectconfigs/", | ||
|
@@ -62,7 +65,7 @@ def gen_message(dt: datetime) -> Mapping[str, Any]: | |
"environment": "development", | ||
"op": "http.server", | ||
"platform": "python", | ||
"release": "[email protected]+c45b49caed1e5fcbf70097ab3f434b487c359b6b", | ||
"release": _RELEASE_TAG, | ||
"sdk.name": "sentry.python.django", | ||
"sdk.version": "2.7.0", | ||
"status": "ok", | ||
|
@@ -166,7 +169,6 @@ def test_with_data(self, setup_teardown: Any) -> None: | |
) | ||
], | ||
limit=61, | ||
attribute_key_transform_context=None, | ||
) | ||
response = span_samples_query(message) | ||
assert [ | ||
|
@@ -222,7 +224,6 @@ def test_booleans_and_number_compares(self, setup_teardown: Any) -> None: | |
) | ||
], | ||
limit=61, | ||
attribute_key_transform_context=None, | ||
) | ||
response = span_samples_query(message) | ||
assert [ | ||
|
@@ -231,3 +232,103 @@ def test_booleans_and_number_compares(self, setup_teardown: Any) -> None: | |
) | ||
for x in response.span_samples | ||
] == [{"is_segment": True, "span_id": "123456781234567d"} for _ in range(60)] | ||
|
||
def test_with_virtual_columns(self, setup_teardown: Any) -> None: | ||
ts = Timestamp(seconds=int(BASE_TIME.timestamp())) | ||
hour_ago = int((BASE_TIME - timedelta(hours=1)).timestamp()) | ||
message = SpanSamplesRequest( | ||
meta=RequestMeta( | ||
project_ids=[1, 2, 3], | ||
organization_id=1, | ||
cogs_category="something", | ||
referrer="something", | ||
start_timestamp=Timestamp(seconds=hour_ago), | ||
end_timestamp=ts, | ||
), | ||
filter=TraceItemFilter( | ||
exists_filter=ExistsFilter( | ||
key=AttributeKey(type=AttributeKey.TYPE_STRING, name="category") | ||
) | ||
), | ||
keys=[ | ||
AttributeKey(type=AttributeKey.TYPE_STRING, name="project_name"), | ||
AttributeKey(type=AttributeKey.TYPE_STRING, name="release_version"), | ||
AttributeKey(type=AttributeKey.TYPE_STRING, name="sentry.sdk.name"), | ||
], | ||
order_by=[ | ||
SpanSamplesRequest.OrderBy( | ||
key=AttributeKey( | ||
type=AttributeKey.TYPE_STRING, name="project_name" | ||
), | ||
) | ||
], | ||
limit=61, | ||
virtual_column_context=[ | ||
VirtualColumnContext( | ||
from_column_name="project_id", | ||
to_column_name="project_name", | ||
value_map={"1": "sentry", "2": "snuba"}, | ||
), | ||
VirtualColumnContext( | ||
from_column_name="release", | ||
to_column_name="release_version", | ||
value_map={_RELEASE_TAG: "4.2.0.69"}, | ||
), | ||
], | ||
) | ||
response = span_samples_query(message) | ||
assert [ | ||
dict((k, x.results[k].val_str) for k in x.results) | ||
for x in response.span_samples | ||
] == [ | ||
{ | ||
"project_name": "sentry", | ||
"sentry.sdk.name": "sentry.python.django", | ||
"release_version": "4.2.0.69", | ||
} | ||
for _ in range(60) | ||
] | ||
|
||
def test_order_by_virtual_columns(self, setup_teardown: Any) -> None: | ||
ts = Timestamp(seconds=int(BASE_TIME.timestamp())) | ||
hour_ago = int((BASE_TIME - timedelta(hours=1)).timestamp()) | ||
message = SpanSamplesRequest( | ||
meta=RequestMeta( | ||
project_ids=[1, 2, 3], | ||
organization_id=1, | ||
cogs_category="something", | ||
referrer="something", | ||
start_timestamp=Timestamp(seconds=hour_ago), | ||
end_timestamp=ts, | ||
), | ||
filter=TraceItemFilter( | ||
exists_filter=ExistsFilter( | ||
key=AttributeKey(type=AttributeKey.TYPE_STRING, name="category") | ||
) | ||
), | ||
keys=[ | ||
AttributeKey(type=AttributeKey.TYPE_STRING, name="special_color"), | ||
], | ||
order_by=[ | ||
SpanSamplesRequest.OrderBy( | ||
key=AttributeKey( | ||
type=AttributeKey.TYPE_STRING, name="special_color" | ||
) | ||
) | ||
], | ||
limit=61, | ||
virtual_column_context=[ | ||
VirtualColumnContext( | ||
from_column_name="color", | ||
to_column_name="special_color", | ||
value_map={"red": "1", "green": "2", "blue": "3"}, | ||
), | ||
], | ||
) | ||
response = span_samples_query(message) | ||
result_dicts = [ | ||
dict((k, x.results[k].val_str) for k in x.results) | ||
for x in response.span_samples | ||
] | ||
colors = [d["special_color"] for d in result_dicts] | ||
assert sorted(colors) == colors |