-
Notifications
You must be signed in to change notification settings - Fork 14
feat: show running queries #1313
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
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
250661a
feat: show running queries
sareyu 9ba6997
fix: fixup
sareyu b2f786e
fix: add limit and sorting
sareyu 12b3273
fix: fixes
sareyu 7b7848c
fix: review fixes
sareyu 5a4cda1
fix: use zod
sareyu 1721d5b
fix: use zod
sareyu 496e091
fix: use zod
sareyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
89 changes: 89 additions & 0 deletions
89
src/containers/Tenant/Diagnostics/TopQueries/RunningQueriesData.tsx
This file contains hidden or 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,89 @@ | ||
import type {Column} from '@gravity-ui/react-data-table'; | ||
import DataTable from '@gravity-ui/react-data-table'; | ||
|
||
import {ResponseError} from '../../../../components/Errors/ResponseError'; | ||
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable'; | ||
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout'; | ||
import {TruncatedQuery} from '../../../../components/TruncatedQuery/TruncatedQuery'; | ||
import {topQueriesApi} from '../../../../store/reducers/executeTopQueries/executeTopQueries'; | ||
import type {KeyValueRow} from '../../../../types/api/query'; | ||
import {cn} from '../../../../utils/cn'; | ||
import {formatDateTime} from '../../../../utils/dataFormatters/dataFormatters'; | ||
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks'; | ||
import {MAX_QUERY_HEIGHT, QUERY_TABLE_SETTINGS} from '../../utils/constants'; | ||
|
||
import i18n from './i18n'; | ||
|
||
const b = cn('kv-top-queries'); | ||
|
||
interface Props { | ||
database: string; | ||
} | ||
|
||
const RUNNING_QUERIES_COLUMNS_WIDTH_LS_KEY = 'runningQueriesColumnsWidth'; | ||
|
||
const columns: Column<KeyValueRow>[] = [ | ||
{ | ||
name: 'UserSID', | ||
header: i18n('col_user'), | ||
render: ({row}) => <div className={b('user-sid')}>{row.UserSID || '–'}</div>, | ||
sortable: true, | ||
}, | ||
{ | ||
name: 'QueryStartAt', | ||
header: i18n('col_start-time'), | ||
render: ({row}) => formatDateTime(new Date(row.QueryStartAt as string).getTime()), | ||
sortable: true, | ||
resizeable: false, | ||
defaultOrder: DataTable.DESCENDING, | ||
}, | ||
{ | ||
name: 'Query', | ||
header: i18n('col_query-text'), | ||
render: ({row}) => ( | ||
<div className={b('query')}> | ||
<TruncatedQuery value={row.Query?.toString()} maxQueryHeight={MAX_QUERY_HEIGHT} /> | ||
</div> | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
width: 500, | ||
sortable: false, | ||
}, | ||
{ | ||
name: 'ApplicationName', | ||
header: i18n('col_app'), | ||
render: ({row}) => <div className={b('user-sid')}>{row.ApplicationName || '–'}</div>, | ||
sortable: true, | ||
}, | ||
]; | ||
|
||
export const RunningQueriesData = ({database}: Props) => { | ||
const [autoRefreshInterval] = useAutoRefreshInterval(); | ||
const filters = useTypedSelector((state) => state.executeTopQueries); | ||
const { | ||
currentData: data, | ||
isFetching, | ||
error, | ||
} = topQueriesApi.useGetRunningQueriesQuery( | ||
{ | ||
database, | ||
filters, | ||
}, | ||
{pollingInterval: autoRefreshInterval}, | ||
); | ||
|
||
return ( | ||
<TableWithControlsLayout.Table loading={isFetching && data === undefined}> | ||
{error ? ( | ||
<ResponseError error={error} /> | ||
) : ( | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ResizeableDataTable | ||
emptyDataMessage={i18n('no-data')} | ||
columnsWidthLSKey={RUNNING_QUERIES_COLUMNS_WIDTH_LS_KEY} | ||
columns={columns} | ||
data={data || []} | ||
settings={QUERY_TABLE_SETTINGS} | ||
/> | ||
)} | ||
</TableWithControlsLayout.Table> | ||
); | ||
}; |
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
src/containers/Tenant/Diagnostics/TopQueries/TopQueriesData.tsx
This file contains hidden or 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,71 @@ | ||
import {ResponseError} from '../../../../components/Errors/ResponseError'; | ||
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable'; | ||
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout'; | ||
import {topQueriesApi} from '../../../../store/reducers/executeTopQueries/executeTopQueries'; | ||
import type {KeyValueRow} from '../../../../types/api/query'; | ||
import type {EPathType} from '../../../../types/api/schema'; | ||
import {cn} from '../../../../utils/cn'; | ||
import {isSortableTopQueriesProperty} from '../../../../utils/diagnostics'; | ||
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks'; | ||
import {QUERY_TABLE_SETTINGS} from '../../utils/constants'; | ||
import {isColumnEntityType} from '../../utils/schema'; | ||
|
||
import {TOP_QUERIES_COLUMNS, TOP_QUERIES_COLUMNS_WIDTH_LS_KEY} from './getTopQueriesColumns'; | ||
import i18n from './i18n'; | ||
|
||
const b = cn('kv-top-queries'); | ||
|
||
interface Props { | ||
database: string; | ||
onRowClick: (row: any) => void; | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type?: EPathType; | ||
} | ||
|
||
export const TopQueriesData = ({database, onRowClick, type}: Props) => { | ||
const [autoRefreshInterval] = useAutoRefreshInterval(); | ||
const filters = useTypedSelector((state) => state.executeTopQueries); | ||
const {currentData, isFetching, error} = topQueriesApi.useGetTopQueriesQuery( | ||
{ | ||
database, | ||
filters, | ||
}, | ||
{pollingInterval: autoRefreshInterval}, | ||
); | ||
const loading = isFetching && currentData === undefined; | ||
const {result: data} = currentData || {}; | ||
|
||
const rawColumns = TOP_QUERIES_COLUMNS; | ||
const columns = rawColumns.map((column) => ({ | ||
...column, | ||
sortable: isSortableTopQueriesProperty(column.name), | ||
})); | ||
|
||
const handleRowClick = (row: KeyValueRow) => { | ||
return onRowClick(row.QueryText as string); | ||
}; | ||
|
||
if (error && !data) { | ||
return ( | ||
<TableWithControlsLayout.Table> | ||
<ResponseError error={error} /> | ||
</TableWithControlsLayout.Table> | ||
); | ||
} | ||
|
||
if (!data || isColumnEntityType(type)) { | ||
return <TableWithControlsLayout.Table>{i18n('no-data')}</TableWithControlsLayout.Table>; | ||
} | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<TableWithControlsLayout.Table loading={loading}> | ||
<ResizeableDataTable | ||
columnsWidthLSKey={TOP_QUERIES_COLUMNS_WIDTH_LS_KEY} | ||
columns={columns} | ||
data={data} | ||
settings={QUERY_TABLE_SETTINGS} | ||
onRowClick={handleRowClick} | ||
rowClassName={() => b('row')} | ||
/> | ||
</TableWithControlsLayout.Table> | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}; |
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
{ | ||
"no-data": "No data", | ||
"filter.text.placeholder": "Search by query text..." | ||
"filter.text.placeholder": "Search by query text...", | ||
"mode_top": "Top", | ||
"mode_running": "Running", | ||
"col_user": "User", | ||
"col_start-time": "Start time", | ||
"col_query-text": "Query text", | ||
"col_app": "Application" | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
{ | ||
"no-data": "Нет данных", | ||
"filter.text.placeholder": "Искать по тексту запроса..." | ||
"filter.text.placeholder": "Искать по тексту запроса...", | ||
"mode_top": "Top", | ||
"mode_running": "Running", | ||
"col_user": "User", | ||
"col_start-time": "Start time", | ||
"col_query-text": "Query text", | ||
"col_app": "Application" | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.