Skip to content

Commit

Permalink
Merge pull request #180 from duyet/chore/new-features
Browse files Browse the repository at this point in the history
feat: add /users, /roles, /distributed-ddl-queue, /readonly-tables
  • Loading branch information
duyet authored Mar 27, 2024
2 parents 31bea5b + 4eef5a9 commit 3ed7a70
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 80 deletions.
18 changes: 13 additions & 5 deletions app/[query]/clickhouse-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ import { backupsConfig } from './more/backups'
import { disksConfig } from './more/disks'
import { mergeTreeSettingsConfig } from './more/mergetree-settings'
import { metricsConfig } from './more/metrics'
import { replicasConfig } from './more/replicas'
import { replicationQueueConfig } from './more/replication-queue'
import { rolesConfig } from './more/roles'
import { settingsConfig } from './more/settings'
import { topUsageColumnsConfig } from './more/top-usage-columns'
import { topUsageTablesConfig } from './more/top-usage-tables'
import { usersConfig } from './more/users'
import { commonErrorsConfig } from './queries/common-errors'
import { expensiveQueriesConfig } from './queries/expensive-queries'
import { expensiveQueriesByMemoryConfig } from './queries/expensive-queries-by-memory'
import { failedQueriesConfig } from './queries/failed-queries'
import { historyQueriesConfig } from './queries/history-queries'
import { runningQueriesConfig } from './queries/running-queries'
import { distributedDdlQueueConfig } from './tables/distributed-ddl-queue'
import { readOnlyTablesConfig } from './tables/readonly-tables'
import { replicasConfig } from './tables/replicas'
import { replicationQueueConfig } from './tables/replication-queue'
import { tablesOverviewConfig } from './tables/table-overview'

export const queries: Array<QueryConfig> = [
// Overview
// Tables
tablesOverviewConfig,
distributedDdlQueueConfig,
replicasConfig,
replicationQueueConfig,
readOnlyTablesConfig,

// Queries
runningQueriesConfig,
Expand All @@ -49,10 +57,10 @@ export const queries: Array<QueryConfig> = [

// More
backupsConfig,
replicasConfig,
replicationQueueConfig,
metricsConfig,
asynchronousMetricsConfig,
usersConfig,
rolesConfig,
]

export const getQueryConfigByName = (
Expand Down
13 changes: 13 additions & 0 deletions app/[query]/more/roles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type QueryConfig } from '@/lib/types/query-config'

export const rolesConfig: QueryConfig = {
name: 'roles',
description: 'Roles',
sql: `
SELECT *,
FROM system.roles
ORDER BY name
`,
columns: ['name', 'id', 'storage'],
columnFormats: {},
}
24 changes: 24 additions & 0 deletions app/[query]/more/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type QueryConfig } from '@/lib/types/query-config'

export const usersConfig: QueryConfig = {
name: 'users',
description: 'Users account',
sql: `
SELECT *,
FROM system.users
ORDER BY name
`,
columns: [
'name',
'storage',
'auth_type',
'auth_params',
'host_ip',
'host_names',
'default_roles_all',
'default_roles_list',
'default_roles_except',
'default_database',
],
columnFormats: {},
}
44 changes: 44 additions & 0 deletions app/[query]/tables/distributed-ddl-queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ColumnFormat } from '@/components/data-table/column-defs'
import { type QueryConfig } from '@/lib/types/query-config'

export const distributedDdlQueueConfig: QueryConfig = {
name: 'distributed-ddl-queue',
description:
'Distributed ddl queries (ON CLUSTER clause) that were executed on a cluster',
sql: `
SELECT
entry,
status,
entry_version,
format('{}:{}', initiator_host, toString(initiator_port)) AS initiator,
cluster,
query,
toString(settings) AS settings,
format('{}:{}', host, toString(port)) AS host,
exception_code,
exception_text,
query_finish_time,
query_duration_ms
FROM system.distributed_ddl_queue
ORDER BY entry DESC, host
`,
columns: [
'entry',
'status',
'entry_version',
'initiator',
'cluster',
'query',
'settings',
'host',
'exception_code',
'exception_text',
'query_finish_time',
'query_duration_ms',
],
columnFormats: {
status: ColumnFormat.ColoredBadge,
query: ColumnFormat.CodeToggle,
settings: ColumnFormat.CodeToggle,
},
}
55 changes: 55 additions & 0 deletions app/[query]/tables/readonly-tables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ColumnFormat } from '@/components/data-table/column-defs'
import { type QueryConfig } from '@/lib/types/query-config'

export const readOnlyTablesConfig: QueryConfig = {
name: 'readonly-tables',
description: `Readonly tables and their replicas`,
sql: `
SELECT
database || '.' || table as table,
is_readonly,
absolute_delay,
zookeeper_path,
last_queue_update_exception,
last_queue_update,
zookeeper_exception,
total_replicas,
active_replicas,
is_leader,
is_session_expired,
replica_name,
replica_path,
log_pointer,
engine
FROM system.replicas
WHERE is_readonly = 1
ORDER BY database, table
`,
columns: [
'table',
'is_readonly',
'absolute_delay',
'zookeeper_path',
'last_queue_update_exception',
'last_queue_update',
'zookeeper_exception',
'total_replicas',
'active_replicas',
'is_leader',
'is_session_expired',
'replica_name',
'replica_path',
'log_pointer',
'engine',
],
columnFormats: {
table: ColumnFormat.ColoredBadge,
engine: ColumnFormat.ColoredBadge,
is_leader: ColumnFormat.Boolean,
can_become_leader: ColumnFormat.Boolean,
is_readonly: ColumnFormat.Boolean,
is_session_expired: ColumnFormat.Boolean,
replica_name: ColumnFormat.ColoredBadge,
},
relatedCharts: [],
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion components/charts/cpu-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function ChartCPUUsage({
const sql = `
SELECT ${interval}(event_time) AS event_time,
avg(ProfileEvent_OSCPUVirtualTimeMicroseconds) / 1000000 as avg_cpu
FROM system.metric_log
FROM merge(system, '^metric_log')
WHERE event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1
ORDER BY 1`
Expand Down
2 changes: 1 addition & 1 deletion components/charts/disks-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function ChartDisksUsage({
map['DiskUsed_default'] as DiskUsed_default,
formatReadableSize(DiskAvailable_default) as readable_DiskAvailable_default,
formatReadableSize(DiskUsed_default) as readable_DiskUsed_default
FROM system.asynchronous_metric_log
FROM merge(system, '^asynchronous_metric_log')
WHERE event_time >= (now() - toIntervalHour(${lastHours}))
GROUP BY 1
ORDER BY 1 ASC
Expand Down
2 changes: 1 addition & 1 deletion components/charts/memory-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function ChartMemoryUsage({
SELECT ${interval}(event_time) as event_time,
avg(CurrentMetric_MemoryTracking) AS avg_memory,
formatReadableSize(avg_memory) AS readable_avg_memory
FROM system.metric_log
FROM merge(system, '^metric_log')
WHERE event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1
ORDER BY 1 ASC`
Expand Down
2 changes: 1 addition & 1 deletion components/charts/merge-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function ChartMergeCount({
SELECT ${interval}(event_time) AS event_time,
avg(CurrentMetric_Merge) AS avg_CurrentMetric_Merge,
avg(CurrentMetric_PartMutation) AS avg_CurrentMetric_PartMutation
FROM system.metric_log
FROM merge(system, '^metric_log')
WHERE event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1
ORDER BY 1
Expand Down
2 changes: 1 addition & 1 deletion components/charts/new-parts-created.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function ChartNewPartsCreated({
formatReadableQuantity(total_rows) AS readable_total_rows,
sum(size_in_bytes) AS total_bytes_on_disk,
formatReadableSize(total_bytes_on_disk) AS readable_total_bytes_on_disk
FROM system.part_log
FROM merge(system, '^part_log')
WHERE (event_type = 'NewPart') AND (event_time > (now() - toIntervalHour(${lastHours})))
GROUP BY
event_time,
Expand Down
2 changes: 1 addition & 1 deletion components/charts/query-count-by-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function ChartQueryCountByUser({
SELECT ${interval}(event_time) AS event_time,
user,
COUNT(*) AS count
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1, 2
Expand Down
4 changes: 2 additions & 2 deletions components/charts/query-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function ChartQueryCount({
WITH event_count AS (
SELECT ${interval}(event_time) AS event_time,
COUNT() AS query_count
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1
Expand All @@ -26,7 +26,7 @@ export async function ChartQueryCount({
SELECT ${interval}(event_time) AS event_time,
query_kind,
COUNT() AS count
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1, 2
Expand Down
2 changes: 1 addition & 1 deletion components/charts/query-duration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function ChartQueryDuration({
SELECT ${interval}(event_time) AS event_time,
AVG(query_duration_ms) AS query_duration_ms,
query_duration_ms / 1000 AS query_duration_s
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND query_kind = 'Select'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
Expand Down
2 changes: 1 addition & 1 deletion components/charts/query-memory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function ChartQueryMemory({
SELECT ${interval}(event_time) AS event_time,
AVG(memory_usage) AS memory_usage,
formatReadableSize(memory_usage) AS readable_memory_usage
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND query_kind = 'Select'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
Expand Down
2 changes: 1 addition & 1 deletion components/charts/query-type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function ChartQueryType({
const sql = `
SELECT type,
COUNT() AS query_count
FROM system.query_log
FROM merge(system, '^query_log')
WHERE type = 'QueryFinish'
AND event_time >= (now() - INTERVAL ${lastHours} HOUR)
GROUP BY 1
Expand Down
49 changes: 0 additions & 49 deletions cypress/e2e/tables-page.cy.ts

This file was deleted.

Loading

0 comments on commit 3ed7a70

Please sign in to comment.