-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database-clusters): Implement V1 of the database clusters tab in…
… Snuba Admin (#6345) Implemented V1 of the database clusters tab in Snuba Admin. The purpose of this tab is to show the nodes on which clickhouse is running as well as their versions. Future work: Instead of using a raw table, there should be groupings and relationships that allow us to better visualize the cluster setup (e.g. clusters should be grouped together). We should also add more metadata so that it's easier to understand the topology of our clusters (distributed nodes should be differentiated from regular storage nodes). <img width="1462" alt="image" src="https://github.com/user-attachments/assets/5b9d2331-1c37-4ac7-8da5-8b188215f02d">
- Loading branch information
Showing
11 changed files
with
328 additions
and
92 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from dataclasses import dataclass | ||
from typing import Sequence | ||
|
||
from snuba.admin.clickhouse.common import get_ro_node_connection | ||
from snuba.admin.clickhouse.nodes import get_storage_info | ||
from snuba.clusters.cluster import ClickhouseClientSettings | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Node: | ||
cluster: str | ||
host_name: str | ||
host_address: str | ||
shard: int | ||
replica: int | ||
version: str | ||
|
||
|
||
@dataclass(frozen=True) | ||
class HostInfo: | ||
host: str | ||
port: int | ||
storage_name: str | ||
|
||
|
||
def get_node_info() -> Sequence[Node]: | ||
node_info = [] | ||
hosts = set() | ||
for storage_info in get_storage_info(): | ||
for node in storage_info["dist_nodes"]: | ||
hosts.add( | ||
HostInfo(node["host"], node["port"], storage_info["storage_name"]) | ||
) | ||
|
||
for node in storage_info["local_nodes"]: | ||
hosts.add( | ||
HostInfo(node["host"], node["port"], storage_info["storage_name"]) | ||
) | ||
|
||
for host_info in hosts: | ||
connection = get_ro_node_connection( | ||
host_info.host, | ||
host_info.port, | ||
host_info.storage_name, | ||
ClickhouseClientSettings.QUERY, | ||
) | ||
nodes = [ | ||
Node(*result) | ||
for result in connection.execute( | ||
"SELECT cluster, host_name, host_address, shard_num, replica_num, version() FROM system.clusters WHERE is_local = 1;" | ||
).results | ||
] | ||
node_info.extend(nodes) | ||
|
||
return node_info |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { MantineReactTable, MRT_ColumnDef, useMantineReactTable } from "mantine-react-table"; | ||
import React, { useMemo } from "react"; | ||
import { useEffect, useState } from "react"; | ||
import Client from "SnubaAdmin/api_client"; | ||
import { ClickhouseNodeInfo } from "./types"; | ||
|
||
function DatabaseClusters(props: { api: Client }) { | ||
const [nodeData, setNodeData] = useState<ClickhouseNodeInfo[]>([]); | ||
|
||
useEffect(() => { | ||
props.api.getClickhouseNodeInfo().then((res) => { | ||
setNodeData(res); | ||
}); | ||
}, []); | ||
|
||
const columns = useMemo<MRT_ColumnDef<ClickhouseNodeInfo>[]>( | ||
() => [ | ||
{ | ||
accessorKey: 'cluster', | ||
header: 'Cluster', | ||
}, | ||
{ | ||
accessorFn: (row) => `${row.host_name} (${row.host_address})`, | ||
header: 'Host', | ||
}, | ||
{ | ||
accessorKey: 'shard', | ||
header: 'Shard', | ||
}, | ||
{ | ||
accessorKey: 'replica', | ||
header: 'Replica', | ||
}, | ||
{ | ||
accessorKey: 'version', | ||
header: 'Version', | ||
filterVariant: 'multi-select', | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
const table = useMantineReactTable({ | ||
columns, | ||
data: nodeData, | ||
initialState: { showColumnFilters: true }, | ||
enableFacetedValues: true, | ||
}); | ||
|
||
return <MantineReactTable table={table} />; | ||
} | ||
|
||
export default DatabaseClusters |
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,10 @@ | ||
type ClickhouseNodeInfo = { | ||
cluster: string, | ||
host_name: string, | ||
host_address: string, | ||
shard: number, | ||
replica: number, | ||
version: string, | ||
}; | ||
|
||
export { ClickhouseNodeInfo }; |
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
Oops, something went wrong.