Skip to content

Commit ef2dcac

Browse files
DominikB2014andrewshie-sentry
authored andcommitted
feat(eap-spans): implement division function (#87500)
closes getsentry/team-visibility#53
1 parent f0256e9 commit ef2dcac

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/sentry/search/eap/spans/formulas.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
)
3939

4040

41+
def division(args: ResolvedArguments) -> Column.BinaryFormula:
42+
dividend = cast(AttributeKey, args[0])
43+
divisor = cast(AttributeKey, args[1])
44+
45+
return Column.BinaryFormula(
46+
left=Column(key=dividend, label="dividend"),
47+
op=Column.BinaryFormula.OP_DIVIDE,
48+
right=Column(key=divisor, label="divisor"),
49+
)
50+
51+
4152
def avg_compare(args: ResolvedArguments) -> Column.BinaryFormula:
4253
attribute = cast(AttributeKey, args[0])
4354
comparison_attribute = cast(AttributeKey, args[1])
@@ -403,4 +414,29 @@ def ttid_contribution_rate(args: ResolvedArguments) -> Column.BinaryFormula:
403414
formula_resolver=avg_compare,
404415
is_aggregate=True,
405416
),
417+
"division": FormulaDefinition(
418+
default_search_type="number",
419+
arguments=[
420+
ArgumentDefinition(
421+
argument_types={
422+
"duration",
423+
"number",
424+
"percentage",
425+
*constants.SIZE_TYPE,
426+
*constants.DURATION_TYPE,
427+
},
428+
),
429+
ArgumentDefinition(
430+
argument_types={
431+
"duration",
432+
"number",
433+
"percentage",
434+
*constants.SIZE_TYPE,
435+
*constants.DURATION_TYPE,
436+
},
437+
),
438+
],
439+
formula_resolver=division,
440+
is_aggregate=True,
441+
),
406442
}

tests/snuba/api/endpoints/test_organization_events_span_indexed.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,6 +3088,41 @@ def test_performance_score(self):
30883088
assert data[0]["performance_score(measurements.score.lcp)"] == 0.06
30893089
assert meta["dataset"] == self.dataset
30903090

3091+
def test_division(self):
3092+
self.store_spans(
3093+
[
3094+
self.create_span(
3095+
{
3096+
"measurements": {
3097+
"frames.total": {"value": 100},
3098+
"frames.slow": {"value": 10},
3099+
"frames.frozen": {"value": 20},
3100+
}
3101+
}
3102+
),
3103+
],
3104+
is_eap=True,
3105+
)
3106+
3107+
response = self.do_request(
3108+
{
3109+
"field": [
3110+
"division(mobile.frames_slow,mobile.frames_total)",
3111+
"division(mobile.frames_frozen,mobile.frames_total)",
3112+
],
3113+
"project": self.project.id,
3114+
"dataset": self.dataset,
3115+
}
3116+
)
3117+
3118+
assert response.status_code == 200, response.content
3119+
data = response.data["data"]
3120+
meta = response.data["meta"]
3121+
assert len(data) == 1
3122+
assert data[0]["division(mobile.frames_slow,mobile.frames_total)"] == 10 / 100
3123+
assert data[0]["division(mobile.frames_frozen,mobile.frames_total)"] == 20 / 100
3124+
assert meta["dataset"] == self.dataset
3125+
30913126
def test_opportunity_score(self):
30923127
self.store_spans(
30933128
[

0 commit comments

Comments
 (0)