Skip to content

Commit 9ccddcd

Browse files
billyvggggritso
andauthored
ref(insights): Refactor cache- + queues- page widgets (#89344)
Part of #88560 Follow-up to #89325 --------- Co-authored-by: George Gritsouk <989898+gggritso@users.noreply.github.com>
1 parent 2c1be32 commit 9ccddcd

15 files changed

+196
-58
lines changed

static/app/views/insights/cache/views/cacheLandingPage.tsx

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import {
2121
} from 'sentry/views/insights/cache/components/tables/transactionsTable';
2222
import {Referrer} from 'sentry/views/insights/cache/referrers';
2323
import {BASE_FILTERS, MODULE_DOC_LINK} from 'sentry/views/insights/cache/settings';
24-
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
2524
import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
2625
import {ModulePageFilterBar} from 'sentry/views/insights/common/components/modulePageFilterBar';
2726
import {ModulePageProviders} from 'sentry/views/insights/common/components/modulePageProviders';
2827
import {ModulesOnboarding} from 'sentry/views/insights/common/components/modulesOnboarding';
2928
import {ModuleBodyUpsellHook} from 'sentry/views/insights/common/components/moduleUpsellHookWrapper';
29+
import CacheMissRateChartWidget from 'sentry/views/insights/common/components/widgets/cacheMissRateChartWidget';
30+
import CacheThroughputChartWidget from 'sentry/views/insights/common/components/widgets/cacheThroughputChartWidget';
3031
import {
3132
useMetrics,
3233
useSpanMetrics,
@@ -37,10 +38,6 @@ import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnbo
3738
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
3839
import {useSamplesDrawer} from 'sentry/views/insights/common/utils/useSamplesDrawer';
3940
import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
40-
import {
41-
DataTitles,
42-
getThroughputChartTitle,
43-
} from 'sentry/views/insights/common/views/spans/types';
4441
import {BackendHeader} from 'sentry/views/insights/pages/backend/backendPageHeader';
4542
import {
4643
type MetricsProperty,
@@ -81,11 +78,7 @@ export function CacheLandingPage() {
8178
requiredParams: ['transaction'],
8279
});
8380

84-
const {
85-
isPending: isCacheMissRateLoading,
86-
data: cacheMissRateData,
87-
error: cacheMissRateError,
88-
} = useSpanMetricsSeries(
81+
const {error: cacheMissRateError} = useSpanMetricsSeries(
8982
{
9083
yAxis: [`${CACHE_MISS_RATE}()`],
9184
search: MutableSearch.fromQueryObject(BASE_FILTERS),
@@ -94,19 +87,6 @@ export function CacheLandingPage() {
9487
Referrer.LANDING_CACHE_HIT_MISS_CHART
9588
);
9689

97-
const {
98-
isPending: isThroughputDataLoading,
99-
data: throughputData,
100-
error: throughputError,
101-
} = useSpanMetricsSeries(
102-
{
103-
search: MutableSearch.fromQueryObject(BASE_FILTERS),
104-
yAxis: ['epm()'],
105-
transformAliasToInputFormat: true,
106-
},
107-
Referrer.LANDING_CACHE_THROUGHPUT_CHART
108-
);
109-
11090
const {
11191
isFetching: isTransactionsListFetching,
11292
data: transactionsList,
@@ -160,6 +140,7 @@ export function CacheLandingPage() {
160140
const hasData = useHasFirstSpan(ModuleName.CACHE);
161141

162142
useEffect(() => {
143+
// TODO: EAP does not use an indexer, so these metrics indexer errors are not possible. When EAP is fully rolled out, remove this check.
163144
const hasMissingDataError =
164145
cacheMissRateError?.message === CACHE_ERROR_MESSAGE ||
165146
transactionsListError?.message === CACHE_ERROR_MESSAGE;
@@ -211,20 +192,10 @@ export function CacheLandingPage() {
211192
</ModuleLayout.Full>
212193
<ModulesOnboarding moduleName={ModuleName.CACHE}>
213194
<ModuleLayout.Half>
214-
<InsightsLineChartWidget
215-
title={DataTitles[`cache_miss_rate()`]}
216-
series={[cacheMissRateData[`${CACHE_MISS_RATE}()`]]}
217-
isLoading={isCacheMissRateLoading}
218-
error={cacheMissRateError}
219-
/>
195+
<CacheMissRateChartWidget />
220196
</ModuleLayout.Half>
221197
<ModuleLayout.Half>
222-
<InsightsLineChartWidget
223-
title={getThroughputChartTitle('cache.get_item')}
224-
series={[throughputData['epm()']]}
225-
isLoading={isThroughputDataLoading}
226-
error={throughputError}
227-
/>
198+
<CacheThroughputChartWidget />
228199
</ModuleLayout.Half>
229200
<ModuleLayout.Full>
230201
<TransactionsTable
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
2+
import {Referrer} from 'sentry/views/insights/cache/referrers';
3+
import {BASE_FILTERS} from 'sentry/views/insights/cache/settings';
4+
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
5+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
6+
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
7+
import {DataTitles} from 'sentry/views/insights/common/views/spans/types';
8+
import {SpanFunction} from 'sentry/views/insights/types';
9+
10+
const {CACHE_MISS_RATE} = SpanFunction;
11+
12+
export default function CacheMissRateChartWidget(props: LoadableChartWidgetProps) {
13+
const {isPending, data, error} = useSpanMetricsSeries(
14+
{
15+
yAxis: [`${CACHE_MISS_RATE}()`],
16+
search: MutableSearch.fromQueryObject(BASE_FILTERS),
17+
transformAliasToInputFormat: true,
18+
},
19+
Referrer.LANDING_CACHE_HIT_MISS_CHART,
20+
props.pageFilters
21+
);
22+
23+
return (
24+
<InsightsLineChartWidget
25+
{...props}
26+
id="cacheMissRateChartWidget"
27+
title={DataTitles[`cache_miss_rate()`]}
28+
series={[data[`${CACHE_MISS_RATE}()`]]}
29+
isLoading={isPending}
30+
error={error}
31+
/>
32+
);
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
2+
import {Referrer} from 'sentry/views/insights/cache/referrers';
3+
import {BASE_FILTERS} from 'sentry/views/insights/cache/settings';
4+
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
5+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
6+
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
7+
import {getThroughputChartTitle} from 'sentry/views/insights/common/views/spans/types';
8+
9+
export default function CacheThroughputChartWidget(props: LoadableChartWidgetProps) {
10+
const {isPending, data, error} = useSpanMetricsSeries(
11+
{
12+
search: MutableSearch.fromQueryObject(BASE_FILTERS),
13+
yAxis: ['epm()'],
14+
transformAliasToInputFormat: true,
15+
},
16+
Referrer.LANDING_CACHE_THROUGHPUT_CHART,
17+
props.pageFilters
18+
);
19+
20+
return (
21+
<InsightsLineChartWidget
22+
{...props}
23+
id="cacheThroughputChartWidget"
24+
title={getThroughputChartTitle('cache.get_item')}
25+
series={[data['epm()']]}
26+
isLoading={isPending}
27+
error={error}
28+
/>
29+
);
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
2+
import {LatencyChart} from 'sentry/views/insights/queues/charts/latencyChart';
3+
import {Referrer} from 'sentry/views/insights/queues/referrers';
4+
5+
export default function QueuesLandingLatencyChartWidget(props: LoadableChartWidgetProps) {
6+
return (
7+
<LatencyChart
8+
{...props}
9+
id="queuesLandingLatencyChartWidget"
10+
referrer={Referrer.QUEUES_LANDING_CHARTS}
11+
/>
12+
);
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
2+
import {ThroughputChart} from 'sentry/views/insights/queues/charts/throughputChart';
3+
import {Referrer} from 'sentry/views/insights/queues/referrers';
4+
5+
export default function QueuesLandingThroughputChartWidget(
6+
props: LoadableChartWidgetProps
7+
) {
8+
return (
9+
<ThroughputChart
10+
{...props}
11+
id="queuesLandingThroughputChartWidget"
12+
referrer={Referrer.QUEUES_LANDING_CHARTS}
13+
/>
14+
);
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {decodeScalar} from 'sentry/utils/queryString';
2+
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
3+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
4+
import {LatencyChart} from 'sentry/views/insights/queues/charts/latencyChart';
5+
import {Referrer} from 'sentry/views/insights/queues/referrers';
6+
7+
export default function QueuesSummaryLatencyChartWidget(props: LoadableChartWidgetProps) {
8+
const {destination} = useLocationQuery({
9+
fields: {
10+
destination: decodeScalar,
11+
},
12+
});
13+
14+
return (
15+
<LatencyChart
16+
{...props}
17+
id="queuesSummaryLatencyChartWidget"
18+
referrer={Referrer.QUEUES_SUMMARY_CHARTS}
19+
destination={destination}
20+
/>
21+
);
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {decodeScalar} from 'sentry/utils/queryString';
2+
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
3+
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types';
4+
import {ThroughputChart} from 'sentry/views/insights/queues/charts/throughputChart';
5+
import {Referrer} from 'sentry/views/insights/queues/referrers';
6+
7+
export default function QueuesSummaryThroughputChartWidget(
8+
props: LoadableChartWidgetProps
9+
) {
10+
const {destination} = useLocationQuery({
11+
fields: {
12+
destination: decodeScalar,
13+
},
14+
});
15+
16+
return (
17+
<ThroughputChart
18+
{...props}
19+
id="queuesSummaryThroughputChartWidget"
20+
referrer={Referrer.QUEUES_SUMMARY_CHARTS}
21+
destination={destination}
22+
/>
23+
);
24+
}

static/app/views/insights/queues/charts/latencyChart.spec.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ describe('latencyChart', () => {
4444
});
4545
it('renders', async () => {
4646
render(
47-
<LatencyChart destination="events" referrer={Referrer.QUEUES_SUMMARY_CHARTS} />,
47+
<LatencyChart
48+
id="latency-chart-test"
49+
destination="events"
50+
referrer={Referrer.QUEUES_SUMMARY_CHARTS}
51+
/>,
4852
{organization}
4953
);
5054
screen.getByText('Average Duration');

static/app/views/insights/queues/charts/latencyChart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import cloneDeep from 'lodash/cloneDeep';
22

33
import {t} from 'sentry/locale';
4+
import type {PageFilters} from 'sentry/types/core';
45
import {defined} from 'sentry/utils';
56
import {InsightsAreaChartWidget} from 'sentry/views/insights/common/components/insightsAreaChartWidget';
67
import {useProcessQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery';
78
import type {Referrer} from 'sentry/views/insights/queues/referrers';
89
import {FIELD_ALIASES} from 'sentry/views/insights/queues/settings';
910

1011
interface Props {
12+
id: string;
1113
referrer: Referrer;
1214
destination?: string;
1315
error?: Error | null;
16+
pageFilters?: PageFilters;
1417
}
1518

16-
export function LatencyChart({error, destination, referrer}: Props) {
19+
export function LatencyChart({id, error, destination, referrer, pageFilters}: Props) {
1720
const {
1821
data,
1922
isPending,
2023
error: latencyError,
2124
} = useProcessQueuesTimeSeriesQuery({
2225
destination,
2326
referrer,
27+
pageFilters,
2428
});
2529

2630
const messageReceiveLatencySeries = cloneDeep(
@@ -51,6 +55,7 @@ export function LatencyChart({error, destination, referrer}: Props) {
5155

5256
return (
5357
<InsightsAreaChartWidget
58+
id={id}
5459
title={t('Average Duration')}
5560
series={[messageReceiveLatencySeries, data['avg(span.duration)']]}
5661
aliases={FIELD_ALIASES}

static/app/views/insights/queues/charts/throughputChart.spec.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ describe('throughputChart', () => {
3131
});
3232
});
3333
it('renders', async () => {
34-
render(<ThroughputChart referrer={Referrer.QUEUES_SUMMARY_CHARTS} />, {organization});
34+
render(
35+
<ThroughputChart
36+
id="throughput-chart-test"
37+
referrer={Referrer.QUEUES_SUMMARY_CHARTS}
38+
/>,
39+
{organization}
40+
);
3541
screen.getByText('Published vs Processed');
3642
expect(eventsStatsMock).toHaveBeenCalledWith(
3743
'/organizations/org-slug/events-stats/',

static/app/views/insights/queues/charts/throughputChart.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {useTheme} from '@emotion/react';
22

33
import {t} from 'sentry/locale';
4+
import type {PageFilters} from 'sentry/types/core';
45
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
56
import {renameDiscoverSeries} from 'sentry/views/insights/common/utils/renameDiscoverSeries';
67
import {useProcessQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery';
@@ -9,12 +10,14 @@ import type {Referrer} from 'sentry/views/insights/queues/referrers';
910
import {FIELD_ALIASES} from 'sentry/views/insights/queues/settings';
1011

1112
interface Props {
13+
id: string;
1214
referrer: Referrer;
1315
destination?: string;
1416
error?: Error | null;
17+
pageFilters?: PageFilters;
1518
}
1619

17-
export function ThroughputChart({error, destination, referrer}: Props) {
20+
export function ThroughputChart({id, error, destination, pageFilters, referrer}: Props) {
1821
const theme = useTheme();
1922
const {
2023
data: publishData,
@@ -23,6 +26,7 @@ export function ThroughputChart({error, destination, referrer}: Props) {
2326
} = usePublishQueuesTimeSeriesQuery({
2427
destination,
2528
referrer,
29+
pageFilters,
2630
});
2731

2832
const {
@@ -32,10 +36,12 @@ export function ThroughputChart({error, destination, referrer}: Props) {
3236
} = useProcessQueuesTimeSeriesQuery({
3337
destination,
3438
referrer,
39+
pageFilters,
3540
});
3641

3742
return (
3843
<InsightsLineChartWidget
44+
id={id}
3945
title={t('Published vs Processed')}
4046
series={[
4147
renameDiscoverSeries(

static/app/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {PageFilters} from 'sentry/types/core';
12
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
23
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
34
import type {Referrer} from 'sentry/views/insights/queues/referrers';
@@ -7,6 +8,7 @@ type Props = {
78
referrer: Referrer;
89
destination?: string;
910
enabled?: boolean;
11+
pageFilters?: PageFilters;
1012
};
1113

1214
const yAxis: SpanMetricsProperty[] = [
@@ -15,7 +17,12 @@ const yAxis: SpanMetricsProperty[] = [
1517
'epm()',
1618
];
1719

18-
export function useProcessQueuesTimeSeriesQuery({enabled, destination, referrer}: Props) {
20+
export function useProcessQueuesTimeSeriesQuery({
21+
enabled,
22+
destination,
23+
referrer,
24+
pageFilters,
25+
}: Props) {
1926
const search = new MutableSearch('span.op:queue.process');
2027
if (destination) {
2128
search.addFilterValue('messaging.destination.name', destination, false);
@@ -28,6 +35,7 @@ export function useProcessQueuesTimeSeriesQuery({enabled, destination, referrer}
2835
enabled,
2936
transformAliasToInputFormat: true,
3037
},
31-
referrer
38+
referrer,
39+
pageFilters
3240
);
3341
}

0 commit comments

Comments
 (0)