Skip to content

Commit 7ae9b36

Browse files
authored
feat(perf): Add MEP param to other landing requests (#32575)
* feat(perf): Add MEP param to other landing requests This will add the metricsEnhanced param to the other widget and table requests, since it should be safe to add even if it's not consumed.
1 parent 99a7654 commit 7ae9b36

File tree

11 files changed

+377
-252
lines changed

11 files changed

+377
-252
lines changed

static/app/utils/discover/genericDiscoverQuery.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type BaseDiscoverQueryProps = {
4444
* passed, but cursor will be ignored.
4545
*/
4646
noPagination?: boolean;
47+
/**
48+
* Extra query parameters to be added.
49+
*/
50+
queryExtras?: Record<string, string>;
4751
/**
4852
* Sets referrer parameter in the API Payload. Set of allowed referrers are defined
4953
* on the OrganizationEventsV2Endpoint view.
@@ -155,6 +159,8 @@ class _GenericDiscoverQuery<T, P> extends React.Component<Props<T, P>, State<T>>
155159
payload.referrer = referrer;
156160
}
157161

162+
Object.assign(payload, props.queryExtras ?? {});
163+
158164
return payload;
159165
}
160166

static/app/utils/performance/contexts/metricsEnhancedSetting.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ interface MetricsEnhancedSettingContext {
1111
setMEPEnabled: (value: boolean) => void;
1212
}
1313

14-
const [_MEPSettingProvider, _useMEPSettingContext] =
14+
const [_MEPSettingProvider, _useMEPSettingContext, MEPSettingContext] =
1515
createDefinedContext<MetricsEnhancedSettingContext>({
1616
name: 'MetricsEnhancedSettingContext',
1717
});
1818

19+
export const MEPConsumer = MEPSettingContext.Consumer;
20+
1921
export const MEPSettingProvider = ({
2022
children,
2123
_isMEPEnabled,

static/app/views/performance/landing/widgets/utils.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ function setWidgetStorageObject(localObject: Record<string, string>) {
1818
localStorage.setItem(getContainerLocalStorageObjectKey, JSON.stringify(localObject));
1919
}
2020

21+
export function getMEPQueryParams(isMEPEnabled: boolean) {
22+
return isMEPEnabled
23+
? {
24+
metricsEnhanced: '1',
25+
}
26+
: undefined;
27+
}
28+
2129
const getContainerLocalStorageObjectKey = 'landing-chart-container';
2230
const getContainerKey = (
2331
index: number,

static/app/views/performance/landing/widgets/widgets/histogramWidget.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import {Fragment, useMemo} from 'react';
22
import styled from '@emotion/styled';
33

44
import {t} from 'sentry/locale';
5+
import {useMEPSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
56
import HistogramQuery from 'sentry/utils/performance/histogram/histogramQuery';
67
import {Chart as HistogramChart} from 'sentry/views/performance/landing/chart/histogramChart';
78

89
import {GenericPerformanceWidget} from '../components/performanceWidget';
910
import {transformHistogramQuery} from '../transforms/transformHistogramQuery';
1011
import {PerformanceWidgetProps, WidgetDataResult} from '../types';
12+
import {getMEPQueryParams} from '../utils';
1113

1214
type AreaDataType = {
1315
chart: WidgetDataResult & ReturnType<typeof transformHistogramQuery>;
1416
};
1517

1618
export function HistogramWidget(props: PerformanceWidgetProps) {
19+
const {isMEPEnabled} = useMEPSettingContext();
1720
const {ContainerActions, location} = props;
1821
const globalSelection = props.eventView.getPageFilters();
1922

@@ -28,6 +31,7 @@ export function HistogramWidget(props: PerformanceWidgetProps) {
2831
location={props.location}
2932
numBuckets={20}
3033
dataFilter="exclude_outliers"
34+
queryExtras={getMEPQueryParams(isMEPEnabled)}
3135
/>
3236
),
3337
transform: transformHistogramQuery,

static/app/views/performance/landing/widgets/widgets/lineChartListWidget.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Truncate from 'sentry/components/truncate';
1111
import {t, tct} from 'sentry/locale';
1212
import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
1313
import {getAggregateAlias} from 'sentry/utils/discover/fields';
14+
import {useMEPSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
1415
import {usePageError} from 'sentry/utils/performance/contexts/pageError';
1516
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
1617
import withApi from 'sentry/utils/withApi';
@@ -30,7 +31,7 @@ import SelectableList, {
3031
import {transformDiscoverToList} from '../transforms/transformDiscoverToList';
3132
import {transformEventsRequestToArea} from '../transforms/transformEventsToArea';
3233
import {PerformanceWidgetProps, QueryDefinition, WidgetDataResult} from '../types';
33-
import {eventsRequestQueryProps} from '../utils';
34+
import {eventsRequestQueryProps, getMEPQueryParams} from '../utils';
3435
import {PerformanceWidgetSetting} from '../widgetDefinitions';
3536

3637
type DataType = {
@@ -52,6 +53,7 @@ const framesList = [
5253
];
5354

5455
export function LineChartListWidget(props: PerformanceWidgetProps) {
56+
const {isMEPEnabled} = useMEPSettingContext();
5557
const [selectedListIndex, setSelectListIndex] = useState<number>(0);
5658
const {ContainerActions} = props;
5759
const pageError = usePageError();
@@ -111,6 +113,7 @@ export function LineChartListWidget(props: PerformanceWidgetProps) {
111113
limit={3}
112114
cursor="0:0:1"
113115
noPagination
116+
queryExtras={getMEPQueryParams(isMEPEnabled)}
114117
/>
115118
);
116119
},
@@ -175,6 +178,7 @@ export function LineChartListWidget(props: PerformanceWidgetProps) {
175178
)}
176179
hideError
177180
onError={pageError.setPageError}
181+
queryExtras={getMEPQueryParams(isMEPEnabled)}
178182
/>
179183
);
180184
},

static/app/views/performance/landing/widgets/widgets/singleFieldAreaWidget.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import _DurationChart from 'sentry/views/performance/charts/chart';
1515
import {GenericPerformanceWidget} from '../components/performanceWidget';
1616
import {transformEventsRequestToArea} from '../transforms/transformEventsToArea';
1717
import {PerformanceWidgetProps, QueryDefinition, WidgetDataResult} from '../types';
18-
import {eventsRequestQueryProps} from '../utils';
18+
import {eventsRequestQueryProps, getMEPQueryParams} from '../utils';
1919

2020
type DataType = {
2121
chart: WidgetDataResult & ReturnType<typeof transformEventsRequestToArea>;
@@ -58,13 +58,7 @@ export function SingleFieldAreaWidget(props: PerformanceWidgetProps) {
5858
)}
5959
hideError
6060
onError={pageError.setPageError}
61-
queryExtras={
62-
isMEPEnabled
63-
? {
64-
metricsEnhanced: '1',
65-
}
66-
: undefined
67-
}
61+
queryExtras={getMEPQueryParams(isMEPEnabled)}
6862
/>
6963
)}
7064
</QueryBatchNode>

static/app/views/performance/landing/widgets/widgets/vitalWidget.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import space from 'sentry/styles/space';
1111
import {defined} from 'sentry/utils';
1212
import DiscoverQuery, {TableDataRow} from 'sentry/utils/discover/discoverQuery';
1313
import {getAggregateAlias, WebVital} from 'sentry/utils/discover/fields';
14+
import {useMEPSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
1415
import {usePageError} from 'sentry/utils/performance/contexts/pageError';
1516
import {VitalData} from 'sentry/utils/performance/vitals/vitalsCardsDiscoverQuery';
1617
import {decodeList} from 'sentry/utils/queryString';
@@ -32,7 +33,7 @@ import SelectableList, {
3233
import {transformDiscoverToList} from '../transforms/transformDiscoverToList';
3334
import {transformEventsRequestToVitals} from '../transforms/transformEventsToVitals';
3435
import {PerformanceWidgetProps, QueryDefinition, WidgetDataResult} from '../types';
35-
import {eventsRequestQueryProps} from '../utils';
36+
import {eventsRequestQueryProps, getMEPQueryParams} from '../utils';
3637
import {ChartDefinition, PerformanceWidgetSetting} from '../widgetDefinitions';
3738

3839
type DataType = {
@@ -85,6 +86,7 @@ export function transformFieldsWithStops(props: {
8586
}
8687

8788
export function VitalWidget(props: PerformanceWidgetProps) {
89+
const {isMEPEnabled} = useMEPSettingContext();
8890
const {ContainerActions, eventView, organization, location} = props;
8991
const [selectedListIndex, setSelectListIndex] = useState<number>(0);
9092
const field = props.fields[0];
@@ -125,6 +127,7 @@ export function VitalWidget(props: PerformanceWidgetProps) {
125127
limit={3}
126128
cursor="0:0:1"
127129
noPagination
130+
queryExtras={getMEPQueryParams(isMEPEnabled)}
128131
/>
129132
);
130133
},
@@ -164,6 +167,7 @@ export function VitalWidget(props: PerformanceWidgetProps) {
164167
)}
165168
hideError
166169
onError={pageError.setPageError}
170+
queryExtras={getMEPQueryParams(isMEPEnabled)}
167171
/>
168172
);
169173
},

static/app/views/performance/table.tsx

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import DiscoverQuery, {
2525
import EventView, {EventData, isFieldSortable} from 'sentry/utils/discover/eventView';
2626
import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
2727
import {fieldAlignment, getAggregateAlias} from 'sentry/utils/discover/fields';
28+
import {MEPConsumer} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
2829
import CellAction, {Actions, updateQuery} from 'sentry/views/eventsV2/table/cellAction';
2930
import {TableColumn} from 'sentry/views/eventsV2/table/types';
3031

32+
import {getMEPQueryParams} from './landing/widgets/utils';
3133
import TransactionThresholdModal, {
3234
modalCss,
3335
TransactionThresholdMetric,
@@ -395,35 +397,42 @@ class _Table extends React.Component<Props, State> {
395397

396398
return (
397399
<div>
398-
<DiscoverQuery
399-
eventView={sortedEventView}
400-
orgSlug={organization.slug}
401-
location={location}
402-
setError={setError}
403-
referrer="api.performance.landing-table"
404-
transactionName={transaction}
405-
transactionThreshold={transactionThreshold}
406-
>
407-
{({pageLinks, isLoading, tableData}) => (
408-
<React.Fragment>
409-
<GridEditable
410-
isLoading={isLoading}
411-
data={tableData ? tableData.data : []}
412-
columnOrder={columnOrder}
413-
columnSortBy={columnSortBy}
414-
grid={{
415-
onResizeColumn: this.handleResizeColumn,
416-
renderHeadCell: this.renderHeadCellWithMeta(tableData?.meta) as any,
417-
renderBodyCell: this.renderBodyCellWithData(tableData) as any,
418-
renderPrependColumns: this.renderPrependCellWithData(tableData) as any,
419-
prependColumnWidths,
420-
}}
421-
location={location}
422-
/>
423-
<Pagination pageLinks={pageLinks} />
424-
</React.Fragment>
400+
<MEPConsumer>
401+
{value => (
402+
<DiscoverQuery
403+
eventView={sortedEventView}
404+
orgSlug={organization.slug}
405+
location={location}
406+
setError={setError}
407+
referrer="api.performance.landing-table"
408+
transactionName={transaction}
409+
transactionThreshold={transactionThreshold}
410+
queryExtras={getMEPQueryParams(value.isMEPEnabled)}
411+
>
412+
{({pageLinks, isLoading, tableData}) => (
413+
<React.Fragment>
414+
<GridEditable
415+
isLoading={isLoading}
416+
data={tableData ? tableData.data : []}
417+
columnOrder={columnOrder}
418+
columnSortBy={columnSortBy}
419+
grid={{
420+
onResizeColumn: this.handleResizeColumn,
421+
renderHeadCell: this.renderHeadCellWithMeta(tableData?.meta) as any,
422+
renderBodyCell: this.renderBodyCellWithData(tableData) as any,
423+
renderPrependColumns: this.renderPrependCellWithData(
424+
tableData
425+
) as any,
426+
prependColumnWidths,
427+
}}
428+
location={location}
429+
/>
430+
<Pagination pageLinks={pageLinks} />
431+
</React.Fragment>
432+
)}
433+
</DiscoverQuery>
425434
)}
426-
</DiscoverQuery>
435+
</MEPConsumer>
427436
</div>
428437
);
429438
}

tests/js/spec/views/performance/landing/utils.spec.jsx renamed to tests/js/spec/views/performance/landing/utils.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ProjectsStore from 'sentry/stores/projectsStore';
44
import EventView from 'sentry/utils/discover/eventView';
55
import {getCurrentLandingDisplay} from 'sentry/views/performance/landing/utils';
66

7-
function initializeData(projects, query) {
7+
function initializeData(projects, query = {}) {
88
const organization = TestStubs.Organization({
99
features: [],
1010
projects,
@@ -16,6 +16,8 @@ function initializeData(projects, query) {
1616
query: query || {},
1717
},
1818
},
19+
projects,
20+
project: projects[0],
1921
});
2022
const eventView = EventView.fromLocation(initialData.router.location);
2123
ProjectsStore.loadInitialData(initialData.organization.projects);

0 commit comments

Comments
 (0)