Skip to content
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

feat(performance): queues module table sorting #70817

Merged
merged 14 commits into from
May 15, 2024
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
5 changes: 4 additions & 1 deletion static/app/utils/discover/fieldRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getSpanOperationName,
isEquation,
isRelativeSpanOperationBreakdownField,
parseFunction,
SPAN_OP_BREAKDOWN_FIELDS,
SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
} from 'sentry/utils/discover/fields';
Expand Down Expand Up @@ -782,10 +783,12 @@ const SPECIAL_FUNCTIONS: SpecialFunctions = {
);
},
time_spent_percentage: fieldName => data => {
const parsedFunction = parseFunction(fieldName);
const column = parsedFunction?.arguments?.[1] ?? SpanMetricsField.SPAN_SELF_TIME;
return (
<TimeSpentCell
percentage={data[fieldName]}
total={data[`sum(${SpanMetricsField.SPAN_SELF_TIME})`]}
total={data[`sum(${column})`]}
op={data[`span.op`]}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
MODULE_TITLE,
RELEASE_LEVEL,
} from 'sentry/views/performance/queues/settings';
import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';

function DestinationSummaryPage() {
const organization = useOrganization();
Expand All @@ -40,7 +41,7 @@ function DestinationSummaryPage() {
const {query} = useLocation();
const destination = decodeScalar(query.destination);

const {data} = useQueuesMetricsQuery({destination});
const {data, isLoading} = useQueuesMetricsQuery({destination});
return (
<Fragment>
<Layout.Header>
Expand Down Expand Up @@ -94,37 +95,40 @@ function DestinationSummaryPage() {
title={t('Avg Time In Queue')}
value={data[0]?.['avg(messaging.message.receive.latency)']}
unit={DurationUnit.MILLISECOND}
isLoading={false}
isLoading={isLoading}
/>
<MetricReadout
title={t('Avg Processing Time')}
value={data[0]?.['avg_if(span.duration,span.op,queue.process)']}
unit={DurationUnit.MILLISECOND}
isLoading={false}
isLoading={isLoading}
/>
<MetricReadout
title={t('Error Rate')}
value={undefined}
unit={'percentage'}
isLoading={false}
isLoading={isLoading}
/>
<MetricReadout
title={t('Published')}
value={data[0]?.['count_op(queue.publish)']}
unit={'count'}
isLoading={false}
isLoading={isLoading}
/>
<MetricReadout
title={t('Processed')}
value={data[0]?.['count_op(queue.process)']}
unit={'count'}
isLoading={false}
isLoading={isLoading}
/>
<MetricReadout
title={t('Time Spent')}
value={data[0]?.['sum(span.duration)']}
unit={DurationUnit.MILLISECOND}
isLoading={false}
tooltip={getTimeSpentExplanation(
data[0]?.['time_spent_percentage(app,span.duration)']
)}
isLoading={isLoading}
/>
</MetricsRibbon>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen} from 'sentry-test/reactTestingLibrary';

import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {TransactionsTable} from 'sentry/views/performance/queues/destinationSummary/transactionsTable';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

jest.mock('sentry/utils/useOrganization');
jest.mock('sentry/utils/useLocation');

describe('transactionsTable', () => {
const organization = OrganizationFixture();
Expand All @@ -18,6 +21,16 @@ describe('transactionsTable', () => {
'<https://sentry.io/fake/next>; rel="next"; results="true"; cursor="0:20:0"';

beforeEach(() => {
jest.mocked(useLocation).mockReturnValue({
pathname: '',
search: '',
query: {statsPeriod: '10d', project: '1'},
hash: '',
state: undefined,
action: 'PUSH',
key: '',
});

eventsMock = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/events/`,
headers: {Link: pageLinks},
Expand All @@ -35,6 +48,7 @@ describe('transactionsTable', () => {
'avg_if(span.duration,span.op,queue.publish)': 0,
'avg_if(span.duration,span.op,queue.process)': 3,
'avg(messaging.message.receive.latency)': 20,
'time_spent_percentage(app,span.duration)': 0.5,
},
],
meta: {
Expand All @@ -47,6 +61,7 @@ describe('transactionsTable', () => {
'avg_if(span.duration,span.op,queue.publish)': 'duration',
'avg_if(span.duration,span.op,queue.process)': 'duration',
'avg(messaging.message.receive.latency)': 'duration',
'time_spent_percentage(app,span.duration)': 'percentage',
},
},
},
Expand Down Expand Up @@ -84,6 +99,7 @@ describe('transactionsTable', () => {
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
dataset: 'spansMetrics',
}),
Expand All @@ -97,4 +113,47 @@ describe('transactionsTable', () => {
expect(screen.getByRole('cell', {name: 'Consumer'})).toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
});

it('sorts by processing time', async () => {
jest.mocked(useLocation).mockReturnValue({
pathname: '',
search: '',
query: {
statsPeriod: '10d',
project: '1',
[QueryParameterNames.DESTINATIONS_SORT]:
'-avg_if(span.duration,span.op,queue.process)',
},
hash: '',
state: undefined,
action: 'PUSH',
key: '',
});

render(<TransactionsTable />);

expect(eventsMock).toHaveBeenCalledWith(
'/organizations/org-slug/events/',
expect.objectContaining({
query: expect.objectContaining({
field: [
'transaction',
'span.op',
'count()',
'count_op(queue.publish)',
'count_op(queue.process)',
'sum(span.duration)',
'avg(span.duration)',
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
dataset: 'spansMetrics',
sort: '-avg_if(span.duration,span.op,queue.process)',
}),
})
);
await screen.findByText('celery.backend_cleanup');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import type {Organization} from 'sentry/types';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {EventsMetaType} from 'sentry/utils/discover/eventView';
import {FIELD_FORMATTERS, getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
import {decodeScalar} from 'sentry/utils/queryString';
import type {Sort} from 'sentry/utils/discover/fields';
import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
import useLocationQuery from 'sentry/utils/url/useLocationQuery';
import {useLocation} from 'sentry/utils/useLocation';
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 {SpanMetricsResponse} from 'sentry/views/starfish/types';
import {SpanFunction, type SpanMetricsResponse} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

type Row = Pick<
Expand Down Expand Up @@ -71,19 +73,52 @@ const COLUMN_ORDER: Column[] = [
width: COL_WIDTH_UNDEFINED,
},
{
key: 'sum(span.duration)',
key: 'time_spent_percentage(app,span.duration)',
name: t('Time Spent'),
width: COL_WIDTH_UNDEFINED,
},
];

const SORTABLE_FIELDS = [
'transaction',
'count_op(queue.publish)',
'count_op(queue.process)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
`${SpanFunction.TIME_SPENT_PERCENTAGE}(app,span.duration)`,
] as const;

type ValidSort = Sort & {
field: (typeof SORTABLE_FIELDS)[number];
};

export function isAValidSort(sort: Sort): sort is ValidSort {
return (SORTABLE_FIELDS as unknown as string[]).includes(sort.field);
}

const DEFAULT_SORT = {
field: 'time_spent_percentage(app,span.duration)' as const,
kind: 'desc' as const,
};

export function TransactionsTable() {
const organization = useOrganization();
const location = useLocation();
const destination = decodeScalar(location.query.destination);

const locationQuery = useLocationQuery({
fields: {
destination: decodeScalar,
[QueryParameterNames.DESTINATIONS_SORT]: decodeScalar,
},
});
const sort =
decodeSorts(locationQuery[QueryParameterNames.DESTINATIONS_SORT])
.filter(isAValidSort)
.at(0) ?? DEFAULT_SORT;

const {data, isLoading, meta, pageLinks, error} = useQueuesByTransactionQuery({
destination,
destination: locationQuery.destination,
sort,
});

const handleCursor: CursorHandler = (newCursor, pathname, query) => {
Expand All @@ -101,12 +136,19 @@ export function TransactionsTable() {
error={error}
data={data}
columnOrder={COLUMN_ORDER}
columnSortBy={[]}
columnSortBy={[
{
key: sort.field,
order: sort.kind,
},
]}
grid={{
renderHeadCell: col =>
renderHeadCell: column =>
renderHeadCell({
column: col,
column,
sort,
location,
sortParameterName: QueryParameterNames.DESTINATIONS_SORT,
}),
renderBodyCell: (column, row) =>
renderBodyCell(column, row, meta, location, organization),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('messageSamplesPanel', () => {
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
per_page: 10,
project: [],
Expand Down Expand Up @@ -190,6 +191,7 @@ describe('messageSamplesPanel', () => {
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
per_page: 10,
project: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useQueuesByDestinationQuery({enabled, destination, sort}: Props)
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage()',
'time_spent_percentage(app,span.duration)',
],
enabled,
sorts: sort ? [sort] : [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {Sort} from 'sentry/utils/discover/fields';
import {decodeScalar} from 'sentry/utils/queryString';
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import {useLocation} from 'sentry/utils/useLocation';
Expand All @@ -8,9 +9,10 @@ import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
type Props = {
destination?: string;
enabled?: boolean;
sort?: Sort;
};

export function useQueuesByTransactionQuery({destination, enabled}: Props) {
export function useQueuesByTransactionQuery({destination, enabled, sort}: Props) {
const location = useLocation();
const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);

Expand All @@ -32,9 +34,10 @@ export function useQueuesByTransactionQuery({destination, enabled}: Props) {
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
enabled,
sorts: [],
sorts: sort ? [sort] : [],
limit: 10,
cursor,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function useQueuesMetricsQuery({destination, transaction, enabled}: Props
'avg_if(span.duration,span.op,queue.publish)',
'avg_if(span.duration,span.op,queue.process)',
'avg(messaging.message.receive.latency)',
'time_spent_percentage(app,span.duration)',
],
enabled,
sorts: [],
Expand Down
9 changes: 5 additions & 4 deletions static/app/views/performance/queues/queuesLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {MODULE_TITLE, RELEASE_LEVEL} from 'sentry/views/performance/queues/setti
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

const DEFAULT_SORT = {
field: 'time_spent_percentage()' as const,
field: 'time_spent_percentage(app,span.duration)' as const,
kind: 'desc' as const,
};

Expand All @@ -43,13 +43,14 @@ function QueuesLandingPage() {
const query = useLocationQuery({
fields: {
destination: decodeScalar,
[QueryParameterNames.DOMAINS_SORT]: decodeScalar,
[QueryParameterNames.DESTINATIONS_SORT]: decodeScalar,
},
});

const sort =
decodeSorts(query[QueryParameterNames.DOMAINS_SORT]).filter(isAValidSort).at(0) ??
DEFAULT_SORT;
decodeSorts(query[QueryParameterNames.DESTINATIONS_SORT])
.filter(isAValidSort)
.at(0) ?? DEFAULT_SORT;

const handleSearch = (newDestination: string) => {
browserHistory.push({
Expand Down
Loading
Loading