Skip to content

Commit

Permalink
ref(starfish): create a shared useSeries function (#70235)
Browse files Browse the repository at this point in the history
1. Create shared `useSeries` which support `useSpanMetricsSeries` and
`useMetricsSeries` where SpanMetrics and Metrics are the dataset names.
2. Rename `MetricsResponse` to `SpanMetricsResponse`, `MetricsProperty`
to `SpanMetricsProperty`, etc so that they match the datasetname
3. Create `MetricsResponse`, `MetricsProperty` etc for fields in the
Metrics dataset
  • Loading branch information
DominikB2014 authored May 3, 2024
1 parent 03ba8dd commit f0156b9
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 118 deletions.
4 changes: 2 additions & 2 deletions static/app/views/aiMonitoring/PipelinesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'project.id'
| 'span.description'
| 'span.group'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {useResourceModuleFilters} from 'sentry/views/performance/browser/resourc
import {AVG_COLOR, THROUGHPUT_COLOR} from 'sentry/views/starfish/colors';
import Chart, {ChartType} from 'sentry/views/starfish/components/chart';
import ChartPanel from 'sentry/views/starfish/components/chartPanel';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {SpanMetricsField} from 'sentry/views/starfish/types';
import {
DataTitles,
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/performance/cache/cacheLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
} from 'sentry/views/performance/cache/tables/transactionsTable';
import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {SpanFunction} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {decodeScalar} from 'sentry/utils/queryString';
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
import {Referrer} from 'sentry/views/performance/cache/referrers';
import {useTransactionDurationSeries} from 'sentry/views/performance/cache/samplePanel/charts/useTransactionDurationSeries';
import {CHART_HEIGHT} from 'sentry/views/performance/cache/settings';
import {AVG_COLOR} from 'sentry/views/starfish/colors';
import Chart, {ChartType} from 'sentry/views/starfish/components/chart';
import ChartPanel from 'sentry/views/starfish/components/chartPanel';
import {useMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import type {MetricsQueryFilters} from 'sentry/views/starfish/types';
import {DataTitles} from 'sentry/views/starfish/views/spans/types';

export function TransactionDurationChart() {
Expand All @@ -16,8 +18,13 @@ export function TransactionDurationChart() {
},
});

const {data, isLoading} = useTransactionDurationSeries({
transactionName: transaction,
const search: MetricsQueryFilters = {
transaction,
};

const {data, isLoading} = useMetricsSeries({
yAxis: ['avg(transaction.duration)'],
search: MutableSearch.fromQueryObject(search),
referrer: Referrer.SAMPLES_CACHE_TRANSACTION_DURATION,
});

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {TransactionCell} from 'sentry/views/performance/cache/tables/transactionCell';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {type MetricsResponse, SpanFunction} from 'sentry/views/starfish/types';
import {SpanFunction, type SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {DataTitles} from 'sentry/views/starfish/views/spans/types';

const {CACHE_MISS_RATE, SPM, TIME_SPENT_PERCENTAGE} = SpanFunction;

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'project'
| 'project.id'
| 'transaction'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
import Onboarding from 'sentry/views/performance/onboarding';
import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {ModuleName, SpanMetricsField} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {ActionSelector} from 'sentry/views/starfish/views/spans/selectors/actionSelector';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders'
import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
import {DatabaseSpanDescription} from 'sentry/views/starfish/components/spanDescription';
import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
Expand Down
4 changes: 2 additions & 2 deletions static/app/views/performance/database/queriesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {SpanDescriptionCell} from 'sentry/views/starfish/components/tableCells/spanDescriptionCell';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {ModuleName} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {DataTitles} from 'sentry/views/starfish/views/spans/types';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'project.id'
| 'span.description'
| 'span.group'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
import {ModuleName, SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/performance/http/httpLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
import Onboarding from 'sentry/views/performance/onboarding';
import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {ModuleName} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

Expand Down
2 changes: 1 addition & 1 deletion static/app/views/performance/http/httpSamplesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {computeAxisMax} from 'sentry/views/starfish/components/chart';
import DetailPanel from 'sentry/views/starfish/components/detailPanel';
import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
import {useIndexedSpans} from 'sentry/views/starfish/queries/useIndexedSpans';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {useSpanMetricsTopNSeries} from 'sentry/views/starfish/queries/useSpanMetricsTopNSeries';
import {
ModuleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {TransactionCell} from 'sentry/views/performance/http/tables/transactionCell';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {DataTitles} from 'sentry/views/starfish/views/spans/types';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'project.id'
| 'transaction'
| 'transaction.method'
Expand Down
4 changes: 2 additions & 2 deletions static/app/views/performance/http/tables/domainsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {DomainCell} from 'sentry/views/performance/http/tables/domainCell';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {DataTitles} from 'sentry/views/starfish/views/spans/types';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'project'
| 'project.id'
| 'span.domain'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import {useQueuesByTransactionQuery} from 'sentry/views/performance/queues/queries/useQueuesByTransactionQuery';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'avg_if(span.self_time,span.op,queue.process)'
| 'count_op(queue.publish)'
| 'count_op(queue.process)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {MessageSpanSamplesTable} from 'sentry/views/performance/queues/messageSp
import {useQueuesMetricsQuery} from 'sentry/views/performance/queues/queries/useQueuesMetricsQuery';
import {computeAxisMax} from 'sentry/views/starfish/components/chart';
import DetailPanel from 'sentry/views/starfish/components/detailPanel';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import {useSampleScatterPlotSeries} from 'sentry/views/starfish/views/spanSummaryPage/sampleList/durationChart/useSampleScatterPlotSeries';

// We're defining our own query filter here, apart from settings.ts because the spans endpoint doesn't accept IN operations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import type {MetricsProperty} from 'sentry/views/starfish/types';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import type {SpanMetricsProperty} from 'sentry/views/starfish/types';

type Props = {
destination?: string;
enabled?: boolean;
};

const yAxis: MetricsProperty[] = [
const yAxis: SpanMetricsProperty[] = [
'avg_if(span.self_time,span.op,queue.publish)',
'avg_if(span.self_time,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
Expand Down
4 changes: 2 additions & 2 deletions static/app/views/performance/queues/queuesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import {useQueuesByDestinationQuery} from 'sentry/views/performance/queues/queries/useQueuesByDestinationQuery';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import type {MetricsResponse} from 'sentry/views/starfish/types';
import type {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

type Row = Pick<
MetricsResponse,
SpanMetricsResponse,
| 'avg_if(span.self_time,span.op,queue.process)'
| 'count_op(queue.publish)'
| 'count_op(queue.process)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import usePageFilters from 'sentry/utils/usePageFilters';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
import type {MetricsProperty} from 'sentry/views/starfish/types';
import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSeries';
import type {SpanMetricsProperty} from 'sentry/views/starfish/types';

jest.mock('sentry/utils/useLocation');
jest.mock('sentry/utils/usePageFilters');
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('useSpanMetricsSeries', () => {
'resource.render_blocking_status': 'blocking' as const,
environment: undefined,
},
yAxis: ['spm()'] as MetricsProperty[],
yAxis: ['spm()'] as SpanMetricsProperty[],
},
}
);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('useSpanMetricsSeries', () => {
const {rerender} = renderHook(({yAxis}) => useSpanMetricsSeries({yAxis}), {
wrapper: Wrapper,
initialProps: {
yAxis: ['avg(span.self_time)', 'spm()'] as MetricsProperty[],
yAxis: ['avg(span.self_time)', 'spm()'] as SpanMetricsProperty[],
},
});

Expand All @@ -154,13 +154,13 @@ describe('useSpanMetricsSeries', () => {
method: 'GET',
query: expect.objectContaining({
interval: '30m',
yAxis: ['avg(span.self_time)', 'spm()'] as MetricsProperty[],
yAxis: ['avg(span.self_time)', 'spm()'] as SpanMetricsProperty[],
}),
})
);

rerender({
yAxis: ['p95(span.self_time)', 'spm()'] as MetricsProperty[],
yAxis: ['p95(span.self_time)', 'spm()'] as SpanMetricsProperty[],
});

await waitFor(() =>
Expand All @@ -170,7 +170,7 @@ describe('useSpanMetricsSeries', () => {
method: 'GET',
query: expect.objectContaining({
interval: '1h',
yAxis: ['p95(span.self_time)', 'spm()'] as MetricsProperty[],
yAxis: ['p95(span.self_time)', 'spm()'] as SpanMetricsProperty[],
}),
})
)
Expand All @@ -192,7 +192,7 @@ describe('useSpanMetricsSeries', () => {
const {result} = renderHook(({yAxis}) => useSpanMetricsSeries({yAxis}), {
wrapper: Wrapper,
initialProps: {
yAxis: ['spm()'] as MetricsProperty[],
yAxis: ['spm()'] as SpanMetricsProperty[],
},
});

Expand Down Expand Up @@ -232,7 +232,10 @@ describe('useSpanMetricsSeries', () => {
const {result} = renderHook(({yAxis}) => useSpanMetricsSeries({yAxis}), {
wrapper: Wrapper,
initialProps: {
yAxis: ['http_response_rate(3)', 'http_response_rate(4)'] as MetricsProperty[],
yAxis: [
'http_response_rate(3)',
'http_response_rate(4)',
] as SpanMetricsProperty[],
},
});

Expand Down
Loading

0 comments on commit f0156b9

Please sign in to comment.