Skip to content

Commit

Permalink
chore(frontend): better UX for running queries page (#59)
Browse files Browse the repository at this point in the history
* chore(frontend): change the way render of reloading running queries

* chore: format reable row count for running queries table
  • Loading branch information
duyet authored Dec 2, 2023
1 parent bf61a8e commit 3feb3b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 15 additions & 5 deletions frontend/src/pages/RunningQueries/RunningQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Table, Button, notification, Typography } from 'antd'
import { Table, Button, notification, Typography, Tooltip, Spin } from 'antd'
import { usePollingEffect } from '../../utils/usePollingEffect'
import React, { useState } from 'react'
import { ColumnType } from 'antd/es/table'
Expand All @@ -8,8 +8,10 @@ const { Paragraph } = Typography
interface RunningQueryData {
query: string
read_rows: number
read_rows_readable: string
query_id: string
total_rows_approx: number
total_rows_approx_readable: string
elapsed: number
memory_usage: string
}
Expand Down Expand Up @@ -80,11 +82,16 @@ export default function RunningQueries() {
)
},
},
{ title: 'User', dataIndex: 'user' },
{ title: 'Elapsed time', dataIndex: 'elapsed' },
{
title: 'Rows read',
dataIndex: 'read_rows',
render: (_: any, item) => `~${item.read_rows}/${item.total_rows_approx}`,
render: (_: any, item) => (
<Tooltip title={`~${item.read_rows}/${item.total_rows_approx}`}>
~{item.read_rows_readable}/{item.total_rows_approx_readable}
</Tooltip>
),
},
{ title: 'Memory Usage', dataIndex: 'memory_usage' },
{
Expand All @@ -95,7 +102,6 @@ export default function RunningQueries() {

usePollingEffect(
async () => {
setRunningQueries([])
setLoadingRunningQueries(true)
const res = await fetch('/api/analyze/running_queries')
const resJson = await res.json()
Expand All @@ -108,9 +114,13 @@ export default function RunningQueries() {

return (
<>
<h1 style={{ textAlign: 'left' }}>Running queries</h1>
<h1 style={{ textAlign: 'left' }}>Running queries {loadingRunningQueries ? <Spin /> : null}</h1>
<br />
<Table columns={columns} dataSource={runningQueries} loading={loadingRunningQueries} />
<Table
columns={columns}
dataSource={runningQueries}
loading={runningQueries.length == 0 && loadingRunningQueries}
/>
</>
)
}
11 changes: 10 additions & 1 deletion housewatch/clickhouse/queries/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@
"""

RUNNING_QUERIES_SQL = """
SELECT query, elapsed, read_rows, total_rows_approx, formatReadableSize(memory_usage) AS memory_usage, query_id
SELECT
query,
user,
elapsed,
read_rows,
formatReadableQuantity(read_rows) AS read_rows_readable,
total_rows_approx,
formatReadableQuantity(total_rows_approx) AS total_rows_approx_readable,
formatReadableSize(memory_usage) AS memory_usage,
query_id
FROM system.processes
WHERE Settings['log_comment'] != 'running_queries_lookup'
ORDER BY elapsed DESC
Expand Down

0 comments on commit 3feb3b2

Please sign in to comment.