-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
ref(perf): Move out the span transactions table #69771
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e09bf0
Move transactions table into the module
gggritso 0df5536
Lift up data fetching state
gggritso b1a2e03
Static column order
gggritso 131c132
Remove redundant wrapper
gggritso dc6144e
Simplify routing
gggritso 21b3e06
Move out table cell renderer
gggritso 8bc35e3
Export testable component
gggritso f3e00a8
Sorting
gggritso 53fa32b
Merge branch 'master' into ref/perf/move-span-transactions-table
gggritso 8f76d71
Update spec
gggritso File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
static/app/views/performance/database/queryTransactionsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import {Fragment} from 'react'; | ||
import {browserHistory} from 'react-router'; | ||
import type {Location} from 'history'; | ||
import * as qs from 'query-string'; | ||
|
||
import type {GridColumnHeader} from 'sentry/components/gridEditable'; | ||
import GridEditable, {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable'; | ||
import Link from 'sentry/components/links/link'; | ||
import type {CursorHandler} from 'sentry/components/pagination'; | ||
import Pagination from 'sentry/components/pagination'; | ||
import {t} from 'sentry/locale'; | ||
import type {Organization} from 'sentry/types'; | ||
import type {EventsMetaType} from 'sentry/utils/discover/eventView'; | ||
import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers'; | ||
import type {Sort} from 'sentry/utils/discover/fields'; | ||
import {useLocation} from 'sentry/utils/useLocation'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
import {normalizeUrl} from 'sentry/utils/withDomainRequired'; | ||
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell'; | ||
import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign'; | ||
import type {SpanMetricsResponse} from 'sentry/views/starfish/types'; | ||
import {SpanMetricsField} from 'sentry/views/starfish/types'; | ||
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters'; | ||
import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types'; | ||
|
||
type Row = Pick< | ||
SpanMetricsResponse, | ||
| 'transaction' | ||
| 'transaction.method' | ||
| 'spm()' | ||
| 'avg(span.self_time)' | ||
| 'sum(span.self_time)' | ||
| 'time_spent_percentage()' | ||
>; | ||
|
||
type Column = GridColumnHeader< | ||
'transaction' | 'spm()' | 'avg(span.self_time)' | 'time_spent_percentage()' | ||
>; | ||
|
||
const COLUMN_ORDER: Column[] = [ | ||
{ | ||
key: 'transaction', | ||
name: t('Found In'), | ||
width: COL_WIDTH_UNDEFINED, | ||
}, | ||
{ | ||
key: 'spm()', | ||
name: getThroughputTitle('db'), | ||
width: COL_WIDTH_UNDEFINED, | ||
}, | ||
{ | ||
key: `avg(${SpanMetricsField.SPAN_SELF_TIME})`, | ||
name: DataTitles.avg, | ||
width: COL_WIDTH_UNDEFINED, | ||
}, | ||
{ | ||
key: 'time_spent_percentage()', | ||
name: DataTitles.timeSpent, | ||
width: COL_WIDTH_UNDEFINED, | ||
}, | ||
]; | ||
|
||
const SORTABLE_FIELDS = [ | ||
'avg(span.self_time)', | ||
'spm()', | ||
'time_spent_percentage()', | ||
] as const; | ||
|
||
type ValidSort = Sort & { | ||
field: (typeof SORTABLE_FIELDS)[number]; | ||
}; | ||
|
||
export function isAValidSort(sort: Sort): sort is ValidSort { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neat |
||
return (SORTABLE_FIELDS as unknown as string[]).includes(sort.field); | ||
} | ||
|
||
interface Props { | ||
data: Row[]; | ||
isLoading: boolean; | ||
sort: ValidSort; | ||
span: Pick<SpanMetricsResponse, SpanMetricsField.SPAN_GROUP | SpanMetricsField.SPAN_OP>; | ||
error?: Error | null; | ||
meta?: EventsMetaType; | ||
pageLinks?: string; | ||
} | ||
|
||
export function QueryTransactionsTable({ | ||
data, | ||
isLoading, | ||
error, | ||
meta, | ||
pageLinks, | ||
sort, | ||
span, | ||
}: Props) { | ||
const location = useLocation(); | ||
const organization = useOrganization(); | ||
|
||
const handleCursor: CursorHandler = (newCursor, pathname, query) => { | ||
browserHistory.push({ | ||
pathname, | ||
query: {...query, [QueryParameterNames.TRANSACTIONS_CURSOR]: newCursor}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<GridEditable | ||
aria-label={t('Transactions')} | ||
isLoading={isLoading} | ||
error={error} | ||
data={data} | ||
columnOrder={COLUMN_ORDER} | ||
columnSortBy={[ | ||
{ | ||
key: sort.field, | ||
order: sort.kind, | ||
}, | ||
]} | ||
grid={{ | ||
renderHeadCell: col => | ||
renderHeadCell({ | ||
column: col, | ||
sort, | ||
location, | ||
sortParameterName: QueryParameterNames.TRANSACTIONS_SORT, | ||
}), | ||
renderBodyCell: (column, row) => | ||
renderBodyCell(column, row, meta, span, location, organization), | ||
}} | ||
location={location} | ||
/> | ||
|
||
<Pagination pageLinks={pageLinks} onCursor={handleCursor} /> | ||
</Fragment> | ||
); | ||
} | ||
|
||
function renderBodyCell( | ||
column: Column, | ||
row: Row, | ||
meta: EventsMetaType | undefined, | ||
span: Pick<SpanMetricsResponse, SpanMetricsField.SPAN_GROUP | SpanMetricsField.SPAN_OP>, | ||
location: Location, | ||
organization: Organization | ||
) { | ||
if (column.key === 'transaction') { | ||
const label = | ||
row['transaction.method'] && !row.transaction.startsWith(row['transaction.method']) | ||
? `${row['transaction.method']} ${row.transaction}` | ||
: row.transaction; | ||
|
||
const pathname = normalizeUrl( | ||
`/organizations/${organization.slug}/performance/database/spans/span/${encodeURIComponent(span[SpanMetricsField.SPAN_GROUP])}` | ||
); | ||
const query: {[key: string]: string | undefined} = { | ||
...location.query, | ||
transaction: row.transaction, | ||
transactionMethod: row['transaction.method'], | ||
}; | ||
|
||
return ( | ||
<OverflowEllipsisTextContainer> | ||
<Link to={`${pathname}?${qs.stringify(query)}`}>{label}</Link> | ||
</OverflowEllipsisTextContainer> | ||
); | ||
} | ||
|
||
if (!meta || !meta?.fields) { | ||
return row[column.key]; | ||
} | ||
|
||
const renderer = getFieldRenderer(column.key, meta.fields, false); | ||
const rendered = renderer( | ||
{...row, 'span.op': span['span.op']}, | ||
{ | ||
location, | ||
organization, | ||
unit: meta.units?.[column.key], | ||
} | ||
); | ||
|
||
return rendered; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably rename this referrer eventually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely! Cleaning up referrers everywhere is on my list