Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemumma committed Mar 5, 2025
1 parent a75ecb0 commit 22344bd
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2868,6 +2868,85 @@ def test_calculate_http_response_rate(self) -> None:
),
]

def test_formula_aggregation(self) -> None:
write_eap_span(BASE_TIME, {"kyles_tag": "a", "const_1": 1}, 10)
write_eap_span(BASE_TIME, {"kyles_tag": "b", "const_1": 1}, 5)
ts = Timestamp(seconds=int(BASE_TIME.timestamp()))
hour_ago = int((BASE_TIME - timedelta(hours=12)).timestamp())
message = TraceItemTableRequest(
meta=RequestMeta(
project_ids=[1, 2, 3],
organization_id=1,
cogs_category="something",
referrer="something",
start_timestamp=Timestamp(seconds=hour_ago),
end_timestamp=ts,
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
columns=[
Column(
label="count / avg",
formula=Column.BinaryFormula(
op=Column.BinaryFormula.OP_DIVIDE,
left=Column(
conditional_aggregation=AttributeConditionalAggregation(
aggregate=Function.FUNCTION_COUNT,
key=AttributeKey(
name="const_1",
type=AttributeKey.TYPE_INT,
),
label="count",
),
),
right=Column(
conditional_aggregation=AttributeConditionalAggregation(
aggregate=Function.FUNCTION_AVERAGE,
key=AttributeKey(
name="const_1",
type=AttributeKey.TYPE_INT,
),
label="avg",
),
),
),
),
Column(
key=AttributeKey(type=AttributeKey.TYPE_STRING, name="kyles_tag")
),
],
filter=TraceItemFilter(
exists_filter=ExistsFilter(
key=AttributeKey(type=AttributeKey.TYPE_STRING, name="kyles_tag")
)
),
group_by=[
AttributeKey(type=AttributeKey.TYPE_STRING, name="kyles_tag"),
],
order_by=[
TraceItemTableRequest.OrderBy(
column=Column(
key=AttributeKey(
type=AttributeKey.TYPE_STRING, name="kyles_tag"
)
)
)
],
)
response = EndpointTraceItemTable().execute(message)
assert response.column_values == [
TraceItemColumnValues(
attribute_name="count / avg",
results=[
AttributeValue(val_double=10),
AttributeValue(val_double=5),
],
),
TraceItemColumnValues(
attribute_name="kyles_tag",
results=[AttributeValue(val_str="a"), AttributeValue(val_str="b")],
),
]


class TestUtils:
def test_apply_labels_to_columns_backward_compat(self) -> None:
Expand Down

0 comments on commit 22344bd

Please sign in to comment.