Skip to content

ref: Make includeAllArgs mandatory in doEventsRequest() and iterate on types #87682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions static/app/actionCreators/events.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ describe('Events ActionCreator', function () {
});
});

it('requests events stats with relative period', function () {
doEventsRequest(api, {
it('requests events stats with relative period', async function () {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
includePrevious: false,
period: '7d',
partial: true,
Expand All @@ -52,9 +53,10 @@ describe('Events ActionCreator', function () {
);
});

it('sets useRpc param', function () {
doEventsRequest(api, {
it('sets useRpc param', async function () {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
includePrevious: false,
period: '7d',
partial: true,
Expand All @@ -73,9 +75,10 @@ describe('Events ActionCreator', function () {
);
});

it('requests events stats with relative period including previous period', function () {
doEventsRequest(api, {
it('requests events stats with relative period including previous period', async function () {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
includePrevious: true,
period: '7d',
partial: true,
Expand All @@ -93,11 +96,12 @@ describe('Events ActionCreator', function () {
);
});

it('requests events stats with absolute period', function () {
it('requests events stats with absolute period', async function () {
const start = new Date('2017-10-12T12:00:00.000Z');
const end = new Date('2017-10-17T00:00:00.000Z');
doEventsRequest(api, {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
includePrevious: false,
start,
end,
Expand All @@ -121,8 +125,9 @@ describe('Events ActionCreator', function () {
it('requests events stats with absolute period including previous period', async function () {
const start = new Date('2017-10-12T12:00:00.000Z');
const end = new Date('2017-10-17T00:00:00.000Z');
await doEventsRequest(api, {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
includePrevious: true,
start,
end,
Expand All @@ -143,8 +148,9 @@ describe('Events ActionCreator', function () {
});

it('spreads query extras', async function () {
await doEventsRequest(api, {
await doEventsRequest<false>(api, {
...opts,
includeAllArgs: false,
queryExtras: {useOnDemandMetrics: 'true'},
partial: true,
});
Expand Down
10 changes: 4 additions & 6 deletions static/app/actionCreators/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {LocationDescriptor} from 'history';
import pick from 'lodash/pick';

import {addErrorMessage} from 'sentry/actionCreators/indicator';
import type {ApiResult, Client, ResponseMeta} from 'sentry/api';
import type {ApiResult, Client} from 'sentry/api';
import {canIncludePreviousPeriod} from 'sentry/components/charts/utils';
import {t} from 'sentry/locale';
import type {DateString} from 'sentry/types/core';
Expand Down Expand Up @@ -61,7 +61,7 @@ type Options = {
yAxis?: string | string[];
};

export type EventsStatsOptions<T extends boolean> = {includeAllArgs?: T} & Options;
export type EventsStatsOptions<T extends boolean> = {includeAllArgs: T} & Options;

/**
* Make requests to `events-stats` endpoint
Expand All @@ -83,7 +83,7 @@ export type EventsStatsOptions<T extends boolean> = {includeAllArgs?: T} & Optio
* @param {Record<string, string>} options.queryExtras A list of extra query parameters
* @param {(org: OrganizationSummary) => string} options.generatePathname A function that returns an override for the pathname
*/
export const doEventsRequest = <IncludeAllArgsType extends boolean = false>(
export const doEventsRequest = <IncludeAllArgsType extends boolean>(
api: Client,
{
organization,
Expand Down Expand Up @@ -113,9 +113,7 @@ export const doEventsRequest = <IncludeAllArgsType extends boolean = false>(
useRpc,
}: EventsStatsOptions<IncludeAllArgsType>
): IncludeAllArgsType extends true
? Promise<
[EventsStats | MultiSeriesEventsStats, string | undefined, ResponseMeta | undefined]
>
? Promise<ApiResult<EventsStats | MultiSeriesEventsStats>>
: Promise<EventsStats | MultiSeriesEventsStats> => {
const pathname =
generatePathname?.(organization) ??
Expand Down
1 change: 1 addition & 0 deletions static/app/components/charts/eventsRequest.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('EventsRequest', function () {
query: '',
children: () => null,
partial: false,
includeAllArgs: false,
includeTransformedData: true,
};

Expand Down
4 changes: 3 additions & 1 deletion static/app/components/charts/eventsRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type RenderProps = LoadingStatus &
};

type DefaultProps = {
includeAllArgs: false;
/**
* Include data for previous period
*/
Expand Down Expand Up @@ -277,6 +278,7 @@ class EventsRequest extends PureComponent<EventsRequestProps, EventsRequestState
comparisonDelta: undefined,
limit: 15,
query: '',
includeAllArgs: false,
includePrevious: true,
includeTransformedData: true,
};
Expand Down Expand Up @@ -334,7 +336,7 @@ class EventsRequest extends PureComponent<EventsRequestProps, EventsRequestState
} else {
try {
api.clear();
timeseriesData = await doEventsRequest(api, props);
timeseriesData = await doEventsRequest<false>(api, props);
} catch (resp) {
if (resp?.responseJSON?.detail) {
errorMessage = resp.responseJSON.detail;
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/charts/onDemandMetricRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {EventsStats, MultiSeriesEventsStats} from 'sentry/types/organizatio
export class OnDemandMetricRequest extends EventsRequest {
fetchExtrapolatedData = async (): Promise<EventsStats> => {
const {api, organization, ...props} = this.props;
const retVal = await doEventsRequest(api, {
const retVal = await doEventsRequest<false>(api, {
...props,
organization,
generatePathname: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ class TriggersChart extends PureComponent<Props, State> {
if (isOnDemandMetricAlert) {
const {sampleRate} = this.state;
const baseProps: EventsRequestProps = {
includeAllArgs: false,
api,
organization,
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,9 @@ export async function doOnDemandMetricsRequest(
const fetchEstimatedStats = () =>
`/organizations/${requestData.organization.slug}/metrics-estimation-stats/`;

const response = await doEventsRequest<false>(api, {
const response = await doEventsRequest<true>(api, {
...requestData,
includeAllArgs: true,
queryExtras: {
...requestData.queryExtras,
useOnDemandMetrics: true,
Expand All @@ -645,21 +646,17 @@ export async function doOnDemandMetricsRequest(
generatePathname: isEditing ? fetchEstimatedStats : undefined,
});

// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
response[0] = {...response[0]};

if (
hasDatasetSelector(requestData.organization) &&
widgetType === WidgetType.DISCOVER
) {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
const meta = response[0].meta ?? {};
const meta: any = response[0].meta ?? {};
meta.discoverSplitDecision = 'transaction-like';
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
response[0] = {...response[0], ...{meta}};
}

// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
return [response[0], response[1], response[2]];
} catch (err) {
Sentry.captureMessage('Failed to fetch metrics estimation stats', {extra: err});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export function LineChartListWidget(props: PerformanceWidgetProps) {
return (
<EventsRequest
{...pick(provided, eventsRequestQueryProps)}
includeAllArgs={false}
yAxis={yAxis}
limit={1}
includePrevious={includePreviousParam}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function SingleFieldAreaWidget(props: PerformanceWidgetProps) {
{({queryBatching}) => (
<EventsRequest
{...pick(provided, eventsRequestQueryProps)}
includeAllArgs={false}
limit={1}
queryBatching={queryBatching}
includePrevious
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export function StackedAreaChartListWidget(props: PerformanceWidgetProps) {
return (
<EventsRequest
{...pick(prunedProvided, eventsRequestQueryProps)}
includeAllArgs={false}
limit={5}
includePrevious={false}
includeTransformedData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function VitalWidget(props: PerformanceWidgetProps) {
return (
<EventsRequest
{...requestProps}
includeAllArgs={false}
limit={1}
currentSeriesNames={[sortField!]}
includePrevious={false}
Expand Down
Loading