Skip to content

Commit a43807f

Browse files
authored
feat(alerts): Load best effort data for spans dataset (#88912)
Span alerts should always use the best effort method of querying. This ensures that the query will be guaranteed to finish as well as showing the most accurate data possible. `EventsRequest` just needs to pass down the `sampling` mode prop. Since the `doEventsRequest` method that gets called downstream already accepts `sampling` as an argument and passes it to the request, I only need to add this at the top level.
1 parent 0cb325b commit a43807f

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

Diff for: static/app/components/charts/eventsRequest.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {AggregationOutputType} from 'sentry/utils/discover/fields';
2626
import {getAggregateAlias, stripEquationPrefix} from 'sentry/utils/discover/fields';
2727
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
2828
import type {QueryBatching} from 'sentry/utils/performance/contexts/genericQueryBatcher';
29+
import type {SamplingMode} from 'sentry/views/explore/hooks/useProgressiveQuery';
2930

3031
export type TimeSeriesData = {
3132
allTimeseriesData?: EventsStatsData;
@@ -199,6 +200,10 @@ type EventsRequestPartialProps = {
199200
* Sample rate used for data extrapolation in OnDemandMetricsRequest
200201
*/
201202
sampleRate?: number;
203+
/**
204+
* The type of sampling mode used for EAP dataset requests
205+
*/
206+
sampling?: SamplingMode;
202207
/**
203208
* Should loading be shown.
204209
*/

Diff for: static/app/views/alerts/rules/metric/triggers/chart/index.spec.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
AlertRuleThresholdType,
1111
Dataset,
1212
} from 'sentry/views/alerts/rules/metric/types';
13+
import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery';
1314

1415
const theme = ThemeFixture();
1516

@@ -253,4 +254,53 @@ describe('Incident Rules Create', () => {
253254
})
254255
);
255256
});
257+
258+
it('uses best effort sampling for span alerts', async () => {
259+
const {organization, project, router} = initializeOrg({
260+
organization: {features: ['visibility-explore-progressive-loading']},
261+
});
262+
263+
render(
264+
<TriggersChart
265+
theme={theme}
266+
api={api}
267+
location={router.location}
268+
organization={organization}
269+
projects={[project]}
270+
query=""
271+
timeWindow={1}
272+
aggregate="count(span.duration)"
273+
dataset={Dataset.EVENTS_ANALYTICS_PLATFORM}
274+
triggers={[]}
275+
environment={null}
276+
comparisonType={AlertRuleComparisonType.COUNT}
277+
resolveThreshold={null}
278+
thresholdType={AlertRuleThresholdType.BELOW}
279+
newAlertOrQuery
280+
onDataLoaded={() => {}}
281+
isQueryValid
282+
showTotalCount
283+
/>
284+
);
285+
286+
expect(await screen.findByTestId('area-chart')).toBeInTheDocument();
287+
expect(await screen.findByTestId('alert-total-events')).toBeInTheDocument();
288+
289+
expect(eventStatsMock).toHaveBeenCalledWith(
290+
expect.anything(),
291+
expect.objectContaining({
292+
query: {
293+
interval: '1m',
294+
project: [2],
295+
query: '',
296+
statsPeriod: '14d',
297+
yAxis: 'count(span.duration)',
298+
referrer: 'api.organization-event-stats',
299+
dataset: 'spans',
300+
sampling: SAMPLING_MODE.BEST_EFFORT,
301+
useRpc: '1',
302+
},
303+
})
304+
);
305+
});
256306
});

Diff for: static/app/views/alerts/rules/metric/triggers/chart/index.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {getComparisonMarkLines} from 'sentry/views/alerts/utils/getComparisonMar
5959
import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
6060
import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
6161
import {ConfidenceFooter} from 'sentry/views/explore/charts/confidenceFooter';
62+
import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery';
6263

6364
import type {MetricRule, Trigger} from '../../types';
6465
import {
@@ -747,7 +748,20 @@ class TriggersChart extends PureComponent<Props, State> {
747748
{noop}
748749
</EventsRequest>
749750
) : null}
750-
<EventsRequest {...baseProps} period={period} dataLoadedCallback={onDataLoaded}>
751+
<EventsRequest
752+
{...baseProps}
753+
period={period}
754+
dataLoadedCallback={onDataLoaded}
755+
// Span alerts only need to do a best effort request and do not need
756+
// preflight requests. A user needs to see the highest fidelity data possible
757+
// to set up the alert.
758+
sampling={
759+
organization.features.includes('visibility-explore-progressive-loading') &&
760+
dataset === Dataset.EVENTS_ANALYTICS_PLATFORM
761+
? SAMPLING_MODE.BEST_EFFORT
762+
: undefined
763+
}
764+
>
751765
{({
752766
loading,
753767
errored,

0 commit comments

Comments
 (0)