Skip to content

Commit 5403c10

Browse files
Abdkhan14Abdullah Khan
andauthored
feat(explore-suspect-attrs): Correcting baseline query (#94941)
The baseline query is the query from the search bar AND the negation of the selected region query. If query_1 is '`span.op:db AND timestamp >= 1 AND timestamp <=2`' the query_2 should be '`span.op:db AND (timestamp < 1 OR timestamp > 2)`'. This PR enforces the logic above. Co-authored-by: Abdullah Khan <abdullahkhan@PG9Y57YDXQ.local>
1 parent 8dd2134 commit 5403c10

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

static/app/views/explore/hooks/useSuspectAttributes.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,43 @@ function useSuspectAttributes({
6161
const formattedStartTimestamp = getUtcDateString(startTimestamp);
6262
const formattedEndTimestamp = getUtcDateString(endTimestamp);
6363

64+
const yAxis = chartInfo.yAxes[0];
65+
const parsedFunction = parseFunction(yAxis ?? '');
66+
const plottedFunctionName = parsedFunction?.name;
67+
const plottedFunctionParameter = parsedFunction?.arguments[0];
68+
69+
const useYAxisCoords = plottedFunctionName !== 'count' && plottedFunctionParameter;
70+
6471
// Add the selected region by x-axis to the query, timestamp: [x1, x2]
6572
selectedRegionQuery.addFilterValue(FieldKey.TIMESTAMP, `>=${formattedStartTimestamp}`);
6673
selectedRegionQuery.addFilterValue(FieldKey.TIMESTAMP, `<=${formattedEndTimestamp}`);
6774

75+
// If selected region query is 'timestamp >= x0 and timestamp <= x1 and span.duration >= y0 and span.duration <= y1',
76+
// then the baseline region query should be '((timestamp < x0 or timestamp > x1) or (span.duration < y0 or span.duration > y1))'.
77+
// This is only required if the y-axis aggregate is not count.
78+
if (useYAxisCoords) {
79+
baselineRegionQuery.addOp('(');
80+
}
81+
6882
// Add the baseline region by x-axis to the query, timestamp: <x1 or timestamp:>x2
6983
baselineRegionQuery.addDisjunctionFilterValues(FieldKey.TIMESTAMP, [
7084
`<${formattedStartTimestamp}`,
7185
`>${formattedEndTimestamp}`,
7286
]);
7387

74-
const yAxis = chartInfo.yAxes[0];
75-
const parsedFunction = parseFunction(yAxis ?? '');
76-
const plottedFunctionName = parsedFunction?.name;
77-
const plottedFunctionParameter = parsedFunction?.arguments[0];
78-
79-
// If the y-axis is not count, we add the field that has been aggregated on, to the queries to complete the boxed region.
88+
// If the y-axis aggregate is not count, we add the field that has been aggregated on, to the queries to complete the boxed region.
8089
// For example, if the y-axis is avg(span.duration), we add span.duration: [y1, y2] to query in the selected region
8190
// and span.duration: <y1 or span.duration:>y2 to the baseline query.
82-
if (plottedFunctionName !== 'count' && plottedFunctionParameter) {
91+
if (useYAxisCoords) {
8392
selectedRegionQuery.addFilterValue(plottedFunctionParameter, `>=${y1}`);
8493
selectedRegionQuery.addFilterValue(plottedFunctionParameter, `<=${y2}`);
8594

95+
baselineRegionQuery.addOp('OR');
8696
baselineRegionQuery.addDisjunctionFilterValues(plottedFunctionParameter, [
8797
`<${y1}`,
8898
`>${y2}`,
8999
]);
100+
baselineRegionQuery.addOp(')');
90101
}
91102

92103
const query1 = selectedRegionQuery.formatString();

0 commit comments

Comments
 (0)