mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 00:15:09 +03:00
feat(nodes): add fleet monitoring and implement the Penpot layout (#7342)
Expose sampled CPU topology, absolute RAM, TCP/UDP counts, load averages and network throughput through the existing heartbeat and descendant contracts, preserving measured zero versus unavailable values. Add an explicit nullable telemetry migration and freshness/availability checks.
Provide read-only All nodes and Master rows with deduplicated host/client totals, grouped SQL aggregation and reporting coverage. Preserve known descendants during parent outages and prefer the freshest valid observation of shared GUIDs. Keep the ordinary heartbeat broadcast free of fleet-wide totals.
Implement the approved compact Penpot-inspired Nodes layout, responsive stacked details, status diagnostics and existing remote actions. Preserve cached rows, search and controls on overview refresh failures. By maintainer decision, hide both system rows when no remote nodes are registered.
Final review of 44ed457985: no outstanding HIGH or MEDIUM findings. CI and Docs CI passed (13 jobs; 2342 frontend tests in 269 files), including Go/race and mixed-version node E2E. Feature-specific PostgreSQL regression execution was not independently verified in the selected CI logs. See https://github.com/MHSanaei/3x-ui/pull/7342#issuecomment-7363599190.
Closes #7335
Closes #7336
Closes #7337
This commit is contained in:
@@ -3,12 +3,39 @@ import { useMemo } from 'react';
|
||||
|
||||
import { HttpUtil } from '@/utils';
|
||||
import { parseMsg } from '@/utils/zodValidate';
|
||||
import { NodeListSchema } from '@/schemas/node';
|
||||
import { NodeListSchema, NodeOverviewSchema } from '@/schemas/node';
|
||||
import type { NodeRecord } from '@/schemas/node';
|
||||
import { keys } from '@/api/queryKeys';
|
||||
|
||||
export type { NodeRecord };
|
||||
|
||||
async function fetchNodeOverview() {
|
||||
const msg = await HttpUtil.get('/panel/api/nodes/overview', undefined, { silent: true });
|
||||
if (!msg.success || msg.obj == null) throw new Error(msg.msg || 'Failed to fetch node overview');
|
||||
return NodeOverviewSchema.parse(msg.obj);
|
||||
}
|
||||
|
||||
const emptyNodes: NodeRecord[] = [];
|
||||
|
||||
export function useNodeOverviewQuery() {
|
||||
const query = useQuery({
|
||||
queryKey: keys.nodes.overview(),
|
||||
queryFn: fetchNodeOverview,
|
||||
refetchInterval: 5_000,
|
||||
});
|
||||
return {
|
||||
nodes: query.data?.nodes ?? emptyNodes,
|
||||
master: query.data?.master,
|
||||
fleet: query.data?.fleet,
|
||||
nodesUpdatedAt: query.dataUpdatedAt,
|
||||
loading: query.isFetching,
|
||||
fetched: query.data !== undefined || query.isError,
|
||||
fetchError: query.isLoadingError ? query.error.message : '',
|
||||
refreshError: query.isRefetchError ? query.error.message : '',
|
||||
refetch: query.refetch,
|
||||
};
|
||||
}
|
||||
|
||||
export interface NodeTotals {
|
||||
total: number;
|
||||
online: number;
|
||||
|
||||
@@ -8,6 +8,7 @@ export const keys = {
|
||||
nodes: {
|
||||
root: () => ['nodes'] as const,
|
||||
list: () => ['nodes', 'list'] as const,
|
||||
overview: () => ['nodes', 'overview'] as const,
|
||||
},
|
||||
hosts: {
|
||||
root: () => ['hosts'] as const,
|
||||
|
||||
@@ -1297,6 +1297,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"remark": "",
|
||||
"scheme": "https",
|
||||
"status": "online",
|
||||
"telemetry": null,
|
||||
"tlsVerifyMode": "verify",
|
||||
"transitive": false,
|
||||
"unavailableMetrics": [
|
||||
@@ -1324,11 +1325,34 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"total": 10737418240,
|
||||
"up": 1048576
|
||||
},
|
||||
"NodeFleetCounts": {
|
||||
"activeCount": 90,
|
||||
"clientCount": 100,
|
||||
"depletedCount": 2,
|
||||
"disabledCount": 8,
|
||||
"inboundCount": 8,
|
||||
"onlineCount": 20
|
||||
},
|
||||
"NodeInboundTraffic": {
|
||||
"down": 0,
|
||||
"id": 1,
|
||||
"up": 0
|
||||
},
|
||||
"NodeMasterView": {
|
||||
"counts": {
|
||||
"activeCount": 90,
|
||||
"clientCount": 100,
|
||||
"depletedCount": 2,
|
||||
"disabledCount": 8,
|
||||
"inboundCount": 8,
|
||||
"onlineCount": 20
|
||||
},
|
||||
"panelVersion": "v3.12.0",
|
||||
"telemetry": null,
|
||||
"xrayError": "",
|
||||
"xrayState": "running",
|
||||
"xrayVersion": "26.1.1"
|
||||
},
|
||||
"NodeMutationRequest": {
|
||||
"address": "",
|
||||
"allowPrivateAddress": false,
|
||||
@@ -1349,6 +1373,34 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"scheme": "http",
|
||||
"tlsVerifyMode": "verify"
|
||||
},
|
||||
"NodeOverview": {
|
||||
"fleet": {
|
||||
"activeCount": 90,
|
||||
"clientCount": 100,
|
||||
"depletedCount": 2,
|
||||
"disabledCount": 8,
|
||||
"inboundCount": 8,
|
||||
"onlineCount": 20
|
||||
},
|
||||
"master": {
|
||||
"counts": {
|
||||
"activeCount": 90,
|
||||
"clientCount": 100,
|
||||
"depletedCount": 2,
|
||||
"disabledCount": 8,
|
||||
"inboundCount": 8,
|
||||
"onlineCount": 20
|
||||
},
|
||||
"panelVersion": "v3.12.0",
|
||||
"telemetry": null,
|
||||
"xrayError": "",
|
||||
"xrayState": "running",
|
||||
"xrayVersion": "26.1.1"
|
||||
},
|
||||
"nodes": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"NodeSnapshotAttachment": {
|
||||
"email": "user1",
|
||||
"inboundId": 1
|
||||
@@ -1364,6 +1416,25 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
null
|
||||
]
|
||||
},
|
||||
"NodeTelemetry": {
|
||||
"cpuPct": 12.5,
|
||||
"load1": 0.25,
|
||||
"load15": 0.12,
|
||||
"load5": 0.18,
|
||||
"logicalCores": 8,
|
||||
"memAvailableBytes": 1073741824,
|
||||
"memTotalBytes": 4294967296,
|
||||
"memUsedBytes": 2147483648,
|
||||
"netDown": 2048,
|
||||
"netUp": 1024,
|
||||
"physicalCores": 4,
|
||||
"resourceScope": "container",
|
||||
"sampleAgeMillis": 125,
|
||||
"sampledAt": 1700000000000,
|
||||
"tcpCount": 75,
|
||||
"udpCount": 12,
|
||||
"uptimeSecs": 3600
|
||||
},
|
||||
"NodeTrafficSnapshotV1": {
|
||||
"activeInboundTree": {},
|
||||
"clients": [
|
||||
@@ -1439,6 +1510,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"remark": "Primary edge",
|
||||
"scheme": "https",
|
||||
"status": "online",
|
||||
"telemetry": null,
|
||||
"tlsVerifyMode": "verify",
|
||||
"transitive": false,
|
||||
"unavailableMetrics": [
|
||||
@@ -1674,6 +1746,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"panelVersion": "",
|
||||
"publicIP": null,
|
||||
"resourceScope": "",
|
||||
"sampleAgeMillis": 125,
|
||||
"swap": null,
|
||||
"tcpCount": 0,
|
||||
"udpCount": 0,
|
||||
|
||||
@@ -4729,6 +4729,14 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"example": "online",
|
||||
"type": "string"
|
||||
},
|
||||
"telemetry": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/NodeTelemetry"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"tlsVerifyMode": {
|
||||
"enum": [
|
||||
"verify",
|
||||
@@ -4890,6 +4898,43 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeFleetCounts": {
|
||||
"properties": {
|
||||
"activeCount": {
|
||||
"example": 90,
|
||||
"type": "integer"
|
||||
},
|
||||
"clientCount": {
|
||||
"example": 100,
|
||||
"type": "integer"
|
||||
},
|
||||
"depletedCount": {
|
||||
"example": 2,
|
||||
"type": "integer"
|
||||
},
|
||||
"disabledCount": {
|
||||
"example": 8,
|
||||
"type": "integer"
|
||||
},
|
||||
"inboundCount": {
|
||||
"example": 8,
|
||||
"type": "integer"
|
||||
},
|
||||
"onlineCount": {
|
||||
"example": 20,
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"activeCount",
|
||||
"clientCount",
|
||||
"depletedCount",
|
||||
"disabledCount",
|
||||
"inboundCount",
|
||||
"onlineCount"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeInboundTraffic": {
|
||||
"properties": {
|
||||
"down": {
|
||||
@@ -4912,6 +4957,40 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeMasterView": {
|
||||
"properties": {
|
||||
"counts": {
|
||||
"$ref": "#/components/schemas/NodeFleetCounts"
|
||||
},
|
||||
"panelVersion": {
|
||||
"example": "v3.12.0",
|
||||
"type": "string"
|
||||
},
|
||||
"telemetry": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/NodeTelemetry"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"xrayError": {
|
||||
"type": "string"
|
||||
},
|
||||
"xrayState": {
|
||||
"example": "running",
|
||||
"type": "string"
|
||||
},
|
||||
"xrayVersion": {
|
||||
"example": "26.1.1",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"counts"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeMutationRequest": {
|
||||
"description": "NodeMutationRequest is the node write/probe contract. ApiToken is accepted\nonly as input. On update, nil means keep the stored token; replacement and\nclearing are explicit and mutually exclusive.",
|
||||
"properties": {
|
||||
@@ -5002,6 +5081,33 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeOverview": {
|
||||
"properties": {
|
||||
"fleet": {
|
||||
"$ref": "#/components/schemas/NodeFleetCounts"
|
||||
},
|
||||
"master": {
|
||||
"$ref": "#/components/schemas/NodeMasterView"
|
||||
},
|
||||
"nodes": {
|
||||
"items": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/NodeView"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"fleet",
|
||||
"master",
|
||||
"nodes"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeSnapshotAttachment": {
|
||||
"properties": {
|
||||
"email": {
|
||||
@@ -5045,6 +5151,106 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeTelemetry": {
|
||||
"description": "NodeTelemetry describes one host sample. Nil metrics were not measured.",
|
||||
"properties": {
|
||||
"cpuPct": {
|
||||
"example": 12.5,
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
},
|
||||
"load1": {
|
||||
"example": 0.25,
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
},
|
||||
"load15": {
|
||||
"example": 0.12,
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
},
|
||||
"load5": {
|
||||
"example": 0.18,
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
},
|
||||
"logicalCores": {
|
||||
"example": 8,
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"memAvailableBytes": {
|
||||
"example": 1073741824,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"memTotalBytes": {
|
||||
"example": 4294967296,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"memUsedBytes": {
|
||||
"example": 2147483648,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"netDown": {
|
||||
"example": 2048,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"netUp": {
|
||||
"example": 1024,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"physicalCores": {
|
||||
"example": 4,
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"resourceScope": {
|
||||
"example": "container",
|
||||
"type": "string"
|
||||
},
|
||||
"sampleAgeMillis": {
|
||||
"example": 125,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"sampledAt": {
|
||||
"example": 1700000000000,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"tcpCount": {
|
||||
"example": 75,
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"udpCount": {
|
||||
"example": 12,
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"uptimeSecs": {
|
||||
"example": 3600,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"sampledAt"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NodeTrafficSnapshotV1": {
|
||||
"description": "NodeTrafficSnapshotV1 carries complete counters every tick; only unchanged structure is omitted.",
|
||||
"properties": {
|
||||
@@ -5276,6 +5482,14 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"example": "online",
|
||||
"type": "string"
|
||||
},
|
||||
"telemetry": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/NodeTelemetry"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"tlsVerifyMode": {
|
||||
"example": "verify",
|
||||
"type": "string"
|
||||
@@ -6179,6 +6393,12 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"resourceScope": {
|
||||
"type": "string"
|
||||
},
|
||||
"sampleAgeMillis": {
|
||||
"example": 125,
|
||||
"format": "int64",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"swap": {},
|
||||
"tcpCount": {
|
||||
"type": "integer"
|
||||
|
||||
@@ -1092,6 +1092,7 @@ export interface Node {
|
||||
remark: string;
|
||||
scheme: string;
|
||||
status: string;
|
||||
telemetry?: NodeTelemetry | null;
|
||||
tlsVerifyMode: string;
|
||||
transitive?: boolean;
|
||||
unavailableMetrics?: string[];
|
||||
@@ -1119,12 +1120,30 @@ export interface NodeClientTraffic {
|
||||
up: number;
|
||||
}
|
||||
|
||||
export interface NodeFleetCounts {
|
||||
activeCount: number;
|
||||
clientCount: number;
|
||||
depletedCount: number;
|
||||
disabledCount: number;
|
||||
inboundCount: number;
|
||||
onlineCount: number;
|
||||
}
|
||||
|
||||
export interface NodeInboundTraffic {
|
||||
down: number;
|
||||
id: number;
|
||||
up: number;
|
||||
}
|
||||
|
||||
export interface NodeMasterView {
|
||||
counts: NodeFleetCounts;
|
||||
panelVersion?: string;
|
||||
telemetry?: NodeTelemetry | null;
|
||||
xrayError?: string;
|
||||
xrayState?: string;
|
||||
xrayVersion?: string;
|
||||
}
|
||||
|
||||
export interface NodeMutationRequest {
|
||||
address: string;
|
||||
allowPrivateAddress: boolean;
|
||||
@@ -1144,6 +1163,12 @@ export interface NodeMutationRequest {
|
||||
tlsVerifyMode: string;
|
||||
}
|
||||
|
||||
export interface NodeOverview {
|
||||
fleet: NodeFleetCounts;
|
||||
master: NodeMasterView;
|
||||
nodes: NodeView | null[];
|
||||
}
|
||||
|
||||
export interface NodeSnapshotAttachment {
|
||||
email: string;
|
||||
inboundId: number;
|
||||
@@ -1154,6 +1179,26 @@ export interface NodeSnapshotStructure {
|
||||
inbounds: Inbound | null[];
|
||||
}
|
||||
|
||||
export interface NodeTelemetry {
|
||||
cpuPct?: number | null;
|
||||
load1?: number | null;
|
||||
load15?: number | null;
|
||||
load5?: number | null;
|
||||
logicalCores?: number | null;
|
||||
memAvailableBytes?: number | null;
|
||||
memTotalBytes?: number | null;
|
||||
memUsedBytes?: number | null;
|
||||
netDown?: number | null;
|
||||
netUp?: number | null;
|
||||
physicalCores?: number | null;
|
||||
resourceScope?: string;
|
||||
sampleAgeMillis?: number | null;
|
||||
sampledAt: number;
|
||||
tcpCount?: number | null;
|
||||
udpCount?: number | null;
|
||||
uptimeSecs?: number | null;
|
||||
}
|
||||
|
||||
export interface NodeTrafficSnapshotV1 {
|
||||
activeInboundTree: Record<string, string[]>;
|
||||
clients: NodeClientTraffic[];
|
||||
@@ -1203,6 +1248,7 @@ export interface NodeView {
|
||||
remark: string;
|
||||
scheme: string;
|
||||
status: string;
|
||||
telemetry?: NodeTelemetry | null;
|
||||
tlsVerifyMode: string;
|
||||
transitive?: boolean;
|
||||
unavailableMetrics?: string[];
|
||||
@@ -1411,6 +1457,7 @@ export interface Status {
|
||||
panelVersion: string;
|
||||
publicIP: unknown;
|
||||
resourceScope?: string;
|
||||
sampleAgeMillis?: number | null;
|
||||
swap: unknown;
|
||||
tcpCount: number;
|
||||
udpCount: number;
|
||||
|
||||
@@ -1167,6 +1167,7 @@ export const NodeSchema = z.object({
|
||||
remark: z.string(),
|
||||
scheme: z.enum(['http', 'https']),
|
||||
status: z.string(),
|
||||
telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(),
|
||||
tlsVerifyMode: z.enum(['verify', 'skip', 'pin', 'mtls']),
|
||||
transitive: z.boolean().optional(),
|
||||
unavailableMetrics: z.array(z.string()).optional(),
|
||||
@@ -1196,6 +1197,16 @@ export const NodeClientTrafficSchema = z.object({
|
||||
});
|
||||
export type NodeClientTraffic = z.infer<typeof NodeClientTrafficSchema>;
|
||||
|
||||
export const NodeFleetCountsSchema = z.object({
|
||||
activeCount: z.number().int(),
|
||||
clientCount: z.number().int(),
|
||||
depletedCount: z.number().int(),
|
||||
disabledCount: z.number().int(),
|
||||
inboundCount: z.number().int(),
|
||||
onlineCount: z.number().int(),
|
||||
});
|
||||
export type NodeFleetCounts = z.infer<typeof NodeFleetCountsSchema>;
|
||||
|
||||
export const NodeInboundTrafficSchema = z.object({
|
||||
down: z.number().int(),
|
||||
id: z.number().int(),
|
||||
@@ -1203,6 +1214,16 @@ export const NodeInboundTrafficSchema = z.object({
|
||||
});
|
||||
export type NodeInboundTraffic = z.infer<typeof NodeInboundTrafficSchema>;
|
||||
|
||||
export const NodeMasterViewSchema = z.object({
|
||||
counts: z.lazy(() => NodeFleetCountsSchema),
|
||||
panelVersion: z.string().optional(),
|
||||
telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(),
|
||||
xrayError: z.string().optional(),
|
||||
xrayState: z.string().optional(),
|
||||
xrayVersion: z.string().optional(),
|
||||
});
|
||||
export type NodeMasterView = z.infer<typeof NodeMasterViewSchema>;
|
||||
|
||||
export const NodeMutationRequestSchema = z.object({
|
||||
address: z.string(),
|
||||
allowPrivateAddress: z.boolean(),
|
||||
@@ -1223,6 +1244,13 @@ export const NodeMutationRequestSchema = z.object({
|
||||
});
|
||||
export type NodeMutationRequest = z.infer<typeof NodeMutationRequestSchema>;
|
||||
|
||||
export const NodeOverviewSchema = z.object({
|
||||
fleet: z.lazy(() => NodeFleetCountsSchema),
|
||||
master: z.lazy(() => NodeMasterViewSchema),
|
||||
nodes: z.array(z.lazy(() => NodeViewSchema).nullable()),
|
||||
});
|
||||
export type NodeOverview = z.infer<typeof NodeOverviewSchema>;
|
||||
|
||||
export const NodeSnapshotAttachmentSchema = z.object({
|
||||
email: z.string(),
|
||||
inboundId: z.number().int(),
|
||||
@@ -1235,6 +1263,27 @@ export const NodeSnapshotStructureSchema = z.object({
|
||||
});
|
||||
export type NodeSnapshotStructure = z.infer<typeof NodeSnapshotStructureSchema>;
|
||||
|
||||
export const NodeTelemetrySchema = z.object({
|
||||
cpuPct: z.number().nullable().optional(),
|
||||
load1: z.number().nullable().optional(),
|
||||
load15: z.number().nullable().optional(),
|
||||
load5: z.number().nullable().optional(),
|
||||
logicalCores: z.number().int().nullable().optional(),
|
||||
memAvailableBytes: z.number().int().nullable().optional(),
|
||||
memTotalBytes: z.number().int().nullable().optional(),
|
||||
memUsedBytes: z.number().int().nullable().optional(),
|
||||
netDown: z.number().int().nullable().optional(),
|
||||
netUp: z.number().int().nullable().optional(),
|
||||
physicalCores: z.number().int().nullable().optional(),
|
||||
resourceScope: z.string().optional(),
|
||||
sampleAgeMillis: z.number().int().nullable().optional(),
|
||||
sampledAt: z.number().int(),
|
||||
tcpCount: z.number().int().nullable().optional(),
|
||||
udpCount: z.number().int().nullable().optional(),
|
||||
uptimeSecs: z.number().int().nullable().optional(),
|
||||
});
|
||||
export type NodeTelemetry = z.infer<typeof NodeTelemetrySchema>;
|
||||
|
||||
export const NodeTrafficSnapshotV1Schema = z.object({
|
||||
activeInboundTree: z.record(z.string(), z.array(z.string())),
|
||||
clients: z.array(z.lazy(() => NodeClientTrafficSchema)),
|
||||
@@ -1285,6 +1334,7 @@ export const NodeViewSchema = z.object({
|
||||
remark: z.string(),
|
||||
scheme: z.string(),
|
||||
status: z.string(),
|
||||
telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(),
|
||||
tlsVerifyMode: z.string(),
|
||||
transitive: z.boolean().optional(),
|
||||
unavailableMetrics: z.array(z.string()).optional(),
|
||||
@@ -1509,6 +1559,7 @@ export const StatusSchema = z.object({
|
||||
panelVersion: z.string(),
|
||||
publicIP: z.unknown(),
|
||||
resourceScope: z.string().optional(),
|
||||
sampleAgeMillis: z.number().int().nullable().optional(),
|
||||
swap: z.unknown(),
|
||||
tcpCount: z.number().int(),
|
||||
udpCount: z.number().int(),
|
||||
|
||||
@@ -2082,6 +2082,13 @@ export const sections: readonly Section[] = [
|
||||
responseSchema: 'NodeView',
|
||||
responseSchemaArray: true,
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/panel/api/nodes/overview',
|
||||
summary:
|
||||
'Read the local panel, unique fleet client counts and sampled remote host telemetry.',
|
||||
responseSchema: 'NodeOverview',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/nodes/mtls/ca',
|
||||
|
||||
@@ -1,160 +1,652 @@
|
||||
.toolbar {
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@font-face {
|
||||
font-family: 'Source Sans Pro';
|
||||
src: url('./fonts/SourceSansPro-Regular.woff2') format('woff2');
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
.name-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.name-cell .name {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.name-cell .remark {
|
||||
font-size: 12px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.address-header {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ip-toggle-icon {
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.ip-toggle-icon:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.address-hidden {
|
||||
filter: blur(5px);
|
||||
transition: filter 0.2s ease;
|
||||
}
|
||||
|
||||
.address-visible {
|
||||
filter: none;
|
||||
}
|
||||
|
||||
.node-cards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.node-card {
|
||||
border: 1px solid var(--ant-color-border-secondary);
|
||||
border-radius: 10px;
|
||||
padding: 12px;
|
||||
background: var(--ant-color-fill-quaternary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.card-expand {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
transition: transform 150ms ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.card-expand.is-expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.node-name {
|
||||
@font-face {
|
||||
font-family: 'Source Sans Pro';
|
||||
src: url('./fonts/SourceSansPro-Semibold.woff2') format('woff2');
|
||||
font-weight: 600;
|
||||
flex: 1;
|
||||
font-display: swap;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Source Sans Pro';
|
||||
src: url('./fonts/SourceSansPro-Bold.woff2') format('woff2');
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
}
|
||||
.nodes-page.is-dark:not(.is-ultra) {
|
||||
--bg-page: #1c1e23;
|
||||
}
|
||||
|
||||
@media (min-width: 769px) {
|
||||
.nodes-page .ant-sidebar:not(.sidebar-pinned) {
|
||||
--sider-rail: 69px !important;
|
||||
}
|
||||
|
||||
.nodes-page .ant-sidebar:not(.sidebar-pinned) .ant-layout-sider-collapsed {
|
||||
flex-basis: 69px !important;
|
||||
width: 69px !important;
|
||||
min-width: 69px !important;
|
||||
max-width: 69px !important;
|
||||
}
|
||||
|
||||
.nodes-page .content-area {
|
||||
padding-inline-start: 23px;
|
||||
}
|
||||
}
|
||||
.nodes-overview {
|
||||
--node-fg: var(--node-text);
|
||||
--node-secondary: var(--node-muted);
|
||||
--node-card: var(--node-surface);
|
||||
--node-field: var(--node-header-bg);
|
||||
--node-line: var(--node-border);
|
||||
--node-fleet: var(--node-fleet-bg);
|
||||
--node-button: var(--node-accent);
|
||||
--node-add-bg: #1269eb;
|
||||
--node-link: #185ea8;
|
||||
--node-good: #317a19;
|
||||
--node-bad: #b42e35;
|
||||
--node-purple: #722ed1;
|
||||
--node-group-bg: #ebedf0;
|
||||
--node-active-bg: #eef6e9;
|
||||
--node-disabled-bg: #eeeff2;
|
||||
--node-depleted-bg: #f9ebeb;
|
||||
--node-online-bg: #e7f0fa;
|
||||
min-width: 0;
|
||||
font:
|
||||
400 13px/1.25 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
color: var(--node-fg);
|
||||
}
|
||||
.dark .nodes-overview,
|
||||
.nodes-page.is-dark:not(.is-ultra) .nodes-overview {
|
||||
--node-fg: #d6d9e0;
|
||||
--node-secondary: #9296a0;
|
||||
--node-card: #23252b;
|
||||
--node-field: #2b2d32;
|
||||
--node-line: #353841;
|
||||
--node-fleet: #252b34;
|
||||
--node-button: #1677ff;
|
||||
--node-link: #8cb8ff;
|
||||
--node-good: #66b740;
|
||||
--node-bad: #eb6469;
|
||||
--node-purple: #bb9df5;
|
||||
--node-group-bg: #30333b;
|
||||
--node-active-bg: #172d12;
|
||||
--node-disabled-bg: #37393e;
|
||||
--node-depleted-bg: #401a1c;
|
||||
--node-online-bg: #102d4b;
|
||||
}
|
||||
.nodes-heading,
|
||||
.nodes-toolbar,
|
||||
.nodes-footnote {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-inline-start: 12px;
|
||||
}
|
||||
.nodes-heading {
|
||||
align-items: start;
|
||||
justify-content: space-between;
|
||||
margin-block-end: 21px;
|
||||
}
|
||||
.nodes-heading h1 {
|
||||
margin: 0;
|
||||
font:
|
||||
600 25px/34px 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
.nodes-heading p {
|
||||
margin: 1px 0 0;
|
||||
color: var(--node-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 21px;
|
||||
}
|
||||
.nodes-heading-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding-block-start: 4px;
|
||||
}
|
||||
.nodes-heading .ant-btn,
|
||||
.nodes-toolbar .ant-btn {
|
||||
font-family: inherit;
|
||||
border-radius: 7px;
|
||||
}
|
||||
.nodes-heading .ant-btn {
|
||||
height: 38px;
|
||||
}
|
||||
.nodes-heading .nodes-add {
|
||||
width: 138px;
|
||||
background: var(--node-add-bg);
|
||||
font-weight: 600;
|
||||
}
|
||||
.nodes-heading .nodes-add:hover {
|
||||
background: #145fd1;
|
||||
}
|
||||
.nodes-heading .nodes-mtls {
|
||||
width: 145px;
|
||||
background: var(--node-card);
|
||||
border-color: var(--node-line);
|
||||
}
|
||||
.nodes-toolbar {
|
||||
min-height: 36px;
|
||||
margin-block-end: 13px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.nodes-toolbar .ant-input-affix-wrapper {
|
||||
width: min(278px, 100%);
|
||||
}
|
||||
.nodes-toolbar .ant-input-affix-wrapper,
|
||||
.nodes-toolbar .ant-select {
|
||||
height: 36px;
|
||||
border-radius: 7px;
|
||||
font: inherit;
|
||||
color: var(--node-fg);
|
||||
background: var(--node-field);
|
||||
border-color: var(--node-line);
|
||||
}
|
||||
.nodes-toolbar .ant-input::placeholder,
|
||||
.nodes-toolbar .ant-input-prefix,
|
||||
.node-registered {
|
||||
color: var(--node-secondary);
|
||||
}
|
||||
.nodes-toolbar .ant-input {
|
||||
font: inherit;
|
||||
}
|
||||
.nodes-toolbar .ant-select {
|
||||
width: 148px;
|
||||
}
|
||||
.nodes-toolbar .ant-select-selector {
|
||||
background: transparent;
|
||||
}
|
||||
.node-registered {
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
.nodes-table-card {
|
||||
padding: 15px 11px 30px;
|
||||
border: 1px solid var(--node-line);
|
||||
border-radius: 12px;
|
||||
background: var(--node-card);
|
||||
}
|
||||
.nodes-table-scroll {
|
||||
overflow-x: auto;
|
||||
container-type: inline-size;
|
||||
}
|
||||
.node-fleet-table {
|
||||
width: 100%;
|
||||
min-width: 920px;
|
||||
table-layout: fixed;
|
||||
border-spacing: 0;
|
||||
color: var(--node-fg);
|
||||
}
|
||||
.node-fleet-table th,
|
||||
.node-fleet-table td {
|
||||
padding: 0 8px;
|
||||
text-align: start;
|
||||
vertical-align: middle;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.node-fleet-table thead th {
|
||||
height: 44px;
|
||||
padding-inline: 1px;
|
||||
background: var(--node-field);
|
||||
color: var(--node-secondary);
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-fleet-table thead th:nth-child(6),
|
||||
.node-fleet-table thead th:nth-child(8) {
|
||||
font-weight: 700;
|
||||
}
|
||||
.node-fleet-table thead th:first-child {
|
||||
border-start-start-radius: 8px;
|
||||
border-end-start-radius: 8px;
|
||||
}
|
||||
.node-fleet-table thead th:last-child {
|
||||
border-start-end-radius: 8px;
|
||||
border-end-end-radius: 8px;
|
||||
}
|
||||
.node-fleet-table tbody > tr:not(.node-history-row) {
|
||||
height: 70px;
|
||||
}
|
||||
.node-fleet-table td,
|
||||
.node-fleet-table .node-name-cell {
|
||||
border-block-end: 1px solid var(--node-line);
|
||||
}
|
||||
.node-row-remote > td:first-child {
|
||||
padding-inline-end: 0;
|
||||
}
|
||||
.node-fleet-table .node-enabled {
|
||||
text-align: center;
|
||||
color: var(--node-secondary);
|
||||
}
|
||||
.node-fleet-table .node-enabled .ant-switch {
|
||||
min-width: 34px;
|
||||
height: 18px;
|
||||
}
|
||||
.node-fleet-table .node-enabled .ant-switch-handle {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
.node-fleet-table .node-enabled .ant-switch.ant-switch-checked {
|
||||
background: var(--node-button);
|
||||
}
|
||||
.node-row-fleet > * {
|
||||
background: var(--node-fleet);
|
||||
}
|
||||
.node-row-fleet td:first-child {
|
||||
box-shadow: inset 3px 0 var(--node-button);
|
||||
}
|
||||
.node-row-fleet > td:nth-child(5) {
|
||||
padding-inline-end: 2px;
|
||||
}
|
||||
[dir='rtl'] .node-row-fleet td:first-child {
|
||||
box-shadow: inset -3px 0 var(--node-button);
|
||||
}
|
||||
.node-actions-heading,
|
||||
.node-readonly-action,
|
||||
.node-icon-action,
|
||||
.node-expander,
|
||||
.node-status-button {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.node-actions,
|
||||
.node-system-action,
|
||||
.node-status-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.node-actions {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 3px;
|
||||
}
|
||||
.node-actions > .ant-checkbox-wrapper {
|
||||
margin-inline: 8px 5px;
|
||||
}
|
||||
.node-actions .ant-checkbox-inner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background: var(--node-card);
|
||||
border-color: #636b7b;
|
||||
}
|
||||
.node-actions .ant-checkbox-checked .ant-checkbox-inner {
|
||||
background: var(--node-button);
|
||||
border-color: var(--node-button);
|
||||
}
|
||||
.node-system-action {
|
||||
gap: 12px;
|
||||
padding-inline-start: 9px;
|
||||
color: var(--node-secondary);
|
||||
}
|
||||
.node-system-badge {
|
||||
min-width: 52px;
|
||||
padding: 4px 12px;
|
||||
border-radius: 4px;
|
||||
color: var(--node-fg);
|
||||
background: var(--node-group-bg);
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.node-sigma {
|
||||
color: var(--node-link);
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-icon-action,
|
||||
.node-expander {
|
||||
display: inline-grid;
|
||||
place-content: center;
|
||||
width: 18px;
|
||||
height: 24px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.node-icon-delete {
|
||||
color: var(--node-bad);
|
||||
}
|
||||
.node-icon-action:disabled {
|
||||
color: var(--node-secondary);
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
.node-expander {
|
||||
height: 18px;
|
||||
border: 1px solid var(--node-line);
|
||||
border-radius: 4px;
|
||||
background: var(--node-field);
|
||||
color: var(--node-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.node-name,
|
||||
.node-cell-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.node-name {
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-name > span,
|
||||
.node-name > small {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
.node-row-fleet .node-name > span,
|
||||
.node-row-master .node-name > span {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.row-action-trigger {
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
.node-row-fleet .node-name > small {
|
||||
font-size: 11px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.card-stats {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.stat-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
.node-name small {
|
||||
color: var(--node-secondary);
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
opacity: 0.6;
|
||||
min-width: 96px;
|
||||
flex-shrink: 0;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.card-stats .ant-tag {
|
||||
.node-open-link:any-link {
|
||||
color: var(--node-link);
|
||||
font-size: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.node-open-link:hover,
|
||||
.node-open-link:focus-visible {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.node-open-link span {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-status-button {
|
||||
gap: 5px;
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-status-button[data-status='online'] {
|
||||
color: var(--node-good);
|
||||
}
|
||||
.node-status-button[data-status='offline'] {
|
||||
color: var(--node-bad);
|
||||
}
|
||||
.node-status-button .online-dot,
|
||||
.node-status-button .xray-error-dot,
|
||||
.node-status-button .ant-badge-status-dot {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
flex: 0 0 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.node-status-button .online-dot {
|
||||
background: var(--node-good);
|
||||
}
|
||||
.node-status-button .xray-error-dot {
|
||||
background: var(--node-purple);
|
||||
}
|
||||
.node-status-info {
|
||||
margin-inline-start: auto;
|
||||
color: var(--node-secondary);
|
||||
font-size: 10px;
|
||||
}
|
||||
.node-status-popup .ant-tooltip-container {
|
||||
width: min(258px, 90vw);
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #414550;
|
||||
border-radius: 8px;
|
||||
color: #d6d9e0;
|
||||
font:
|
||||
400 11px/1.4 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
.node-status-tooltip h3 {
|
||||
margin: 0 0 5px;
|
||||
color: #a6aab4;
|
||||
font:
|
||||
600 11px 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
.node-status-tooltip dl {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.card-history {
|
||||
margin-top: 4px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--ant-color-border-secondary);
|
||||
}
|
||||
|
||||
.card-empty {
|
||||
text-align: center;
|
||||
color: var(--ant-color-text-secondary);
|
||||
padding: 24px 12px;
|
||||
.node-status-tooltip dl > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
justify-content: space-between;
|
||||
gap: 25px;
|
||||
line-height: 23px;
|
||||
}
|
||||
|
||||
.node-network-speed {
|
||||
display: inline-grid;
|
||||
row-gap: 2px;
|
||||
text-align: start;
|
||||
line-height: 1.25;
|
||||
.node-status-tooltip dd {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.node-network-direction {
|
||||
display: grid;
|
||||
grid-template-columns: 1em auto;
|
||||
column-gap: 4px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
.node-status-tooltip dt {
|
||||
color: #a6aab4;
|
||||
}
|
||||
.node-hardware {
|
||||
gap: 6px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.node-cpu {
|
||||
font:
|
||||
400 11px/15px 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
.node-ram {
|
||||
font:
|
||||
400 10px/13px 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
.node-memory-detail {
|
||||
color: var(--node-secondary);
|
||||
font-size: 9px;
|
||||
}
|
||||
.node-network-speed,
|
||||
.node-runtime,
|
||||
.node-connections,
|
||||
.node-system-clients {
|
||||
gap: 5px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.node-network-speed {
|
||||
display: inline-grid;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.node-network-direction {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
}
|
||||
.node-network-up {
|
||||
color: var(--node-link);
|
||||
}
|
||||
.node-row-fleet .node-network-speed,
|
||||
.node-row-master .node-network-speed {
|
||||
font-size: 12px;
|
||||
}
|
||||
.node-connections > span:nth-child(-n + 2) {
|
||||
font-weight: 600;
|
||||
}
|
||||
.node-connection-load,
|
||||
.node-runtime small {
|
||||
color: var(--node-secondary);
|
||||
font-size: 9px;
|
||||
}
|
||||
.node-runtime .node-panel-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
}
|
||||
.node-runtime .node-icon-action {
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
color: var(--node-link);
|
||||
font-size: 11px;
|
||||
}
|
||||
.node-system-clients {
|
||||
font-size: 11px;
|
||||
}
|
||||
.node-system-clients small {
|
||||
color: var(--node-secondary);
|
||||
font-size: 10px;
|
||||
}
|
||||
.node-client-counts {
|
||||
display: grid;
|
||||
grid-template-columns: 52fr 54fr 58fr;
|
||||
grid-template-rows: repeat(2, 21px);
|
||||
gap: 4px 6px;
|
||||
align-items: center;
|
||||
}
|
||||
.node-count-total {
|
||||
grid-column: 1;
|
||||
grid-row: 1 / span 2;
|
||||
}
|
||||
.node-client-counts .ant-tag {
|
||||
margin: 0;
|
||||
padding-inline: 2px;
|
||||
text-align: center;
|
||||
line-height: 19px;
|
||||
font:
|
||||
400 11px/19px 'Source Sans Pro',
|
||||
system-ui,
|
||||
sans-serif;
|
||||
color: var(--node-fg);
|
||||
background: var(--node-disabled-bg);
|
||||
}
|
||||
.node-client-counts .node-count-active {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
background: var(--node-active-bg);
|
||||
color: var(--node-good);
|
||||
}
|
||||
.node-client-counts .node-count-disabled {
|
||||
grid-column: 3;
|
||||
grid-row: 1;
|
||||
}
|
||||
.node-client-counts .node-count-depleted {
|
||||
grid-column: 2;
|
||||
grid-row: 2;
|
||||
background: var(--node-depleted-bg);
|
||||
color: var(--node-bad);
|
||||
}
|
||||
.node-client-counts .node-count-online {
|
||||
grid-column: 3;
|
||||
grid-row: 2;
|
||||
background: var(--node-online-bg);
|
||||
color: var(--node-link);
|
||||
}
|
||||
.node-history-row td {
|
||||
padding: 12px;
|
||||
}
|
||||
.nodes-footnote {
|
||||
justify-content: space-between;
|
||||
margin-block-start: 9px;
|
||||
color: var(--node-secondary);
|
||||
font-size: 11px;
|
||||
line-height: 22px;
|
||||
}
|
||||
@container (max-width: 1205px) {
|
||||
.node-actions > .ant-checkbox-wrapper {
|
||||
margin-inline: 4px;
|
||||
}
|
||||
|
||||
.node-actions > .node-icon-action {
|
||||
width: 17px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 650px) {
|
||||
.nodes-heading {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.nodes-heading-actions {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.node-registered {
|
||||
margin-inline-start: 0;
|
||||
}
|
||||
}
|
||||
@container (width < 920px) {
|
||||
.node-fleet-table,
|
||||
.node-fleet-table thead,
|
||||
.node-fleet-table tbody,
|
||||
.node-fleet-table tr,
|
||||
.node-fleet-table .node-history-row td {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
}
|
||||
.node-fleet-table colgroup {
|
||||
display: none;
|
||||
}
|
||||
.node-fleet-table thead th:not(:first-child) {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip-path: inset(50%);
|
||||
}
|
||||
.node-fleet-table thead th:first-child {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-inline: 10px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.node-fleet-table tbody > tr:not(.node-history-row) {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
height: auto;
|
||||
margin-block-start: 8px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--node-line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.node-row-fleet {
|
||||
background: var(--node-fleet);
|
||||
}
|
||||
.node-fleet-table tbody td,
|
||||
.node-fleet-table .node-name-cell {
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
text-align: start;
|
||||
}
|
||||
.node-fleet-table .node-name-cell,
|
||||
.node-fleet-table tbody td:first-child {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.node-fleet-table .node-name-cell {
|
||||
grid-row: 1;
|
||||
}
|
||||
.node-fleet-table td[data-label]::before {
|
||||
display: block;
|
||||
margin-block-end: 4px;
|
||||
color: var(--node-secondary);
|
||||
font-size: 11px;
|
||||
content: attr(data-label);
|
||||
}
|
||||
.node-fleet-table .node-row-fleet td:first-child {
|
||||
box-shadow: none;
|
||||
}
|
||||
.node-fleet-table .node-history-row td {
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { expect, within } from 'storybook/test';
|
||||
import { ConfigProvider } from 'antd';
|
||||
import { useState } from 'react';
|
||||
import type { NodeRecord } from '@/schemas/node';
|
||||
import NodeList from './NodeList';
|
||||
|
||||
const counts = {
|
||||
clientCount: 7100,
|
||||
inboundCount: 40,
|
||||
activeCount: 6050,
|
||||
disabledCount: 50,
|
||||
depletedCount: 1000,
|
||||
onlineCount: 210,
|
||||
};
|
||||
const noop = () => {};
|
||||
|
||||
function Fixture({ rtl }: { rtl?: boolean }) {
|
||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||
const [now] = useState(Date.now);
|
||||
const nodes: NodeRecord[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Finland edge',
|
||||
status: 'online',
|
||||
enable: true,
|
||||
xrayVersion: '26.1.1',
|
||||
panelVersion: '3.12.0',
|
||||
latencyMs: 42,
|
||||
lastHeartbeat: Math.floor(now / 1000) - 2,
|
||||
scheme: 'https',
|
||||
address: '2001:db8::3',
|
||||
port: 2053,
|
||||
basePath: '/edge/',
|
||||
telemetry: {
|
||||
sampledAt: now,
|
||||
cpuPct: 0,
|
||||
logicalCores: 8,
|
||||
memUsedBytes: 4 * 2 ** 30,
|
||||
memTotalBytes: 16 * 2 ** 30,
|
||||
netUp: 1024,
|
||||
netDown: 2048,
|
||||
tcpCount: 0,
|
||||
udpCount: 21,
|
||||
load1: 0.25,
|
||||
load5: 0.15,
|
||||
load15: 0.1,
|
||||
uptimeSecs: 5000,
|
||||
},
|
||||
clientCount: 3077,
|
||||
onlineCount: 31,
|
||||
onlineTotalCount: 53,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Frankfurt',
|
||||
status: 'online',
|
||||
enable: true,
|
||||
panelVersion: '3.13.0',
|
||||
scheme: 'https',
|
||||
address: 'frankfurt-with-a-very-long-hostname.example.test',
|
||||
port: 443,
|
||||
telemetry: { sampledAt: now, cpuPct: 40, logicalCores: 4, tcpCount: 4, load1: 0.75 },
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'This-is-an-intentionally-long-node-name-without-spaces',
|
||||
status: 'offline',
|
||||
enable: true,
|
||||
lastError: 'Remote panel did not respond',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Standby',
|
||||
status: 'online',
|
||||
enable: false,
|
||||
telemetry: { sampledAt: now, cpuPct: 100, tcpCount: 9 },
|
||||
},
|
||||
];
|
||||
return (
|
||||
<ConfigProvider direction={rtl ? 'rtl' : 'ltr'}>
|
||||
<div dir={rtl ? 'rtl' : 'ltr'} className="nodes-story">
|
||||
<NodeList
|
||||
nodes={nodes}
|
||||
selectedIds={selectedIds}
|
||||
onSelectionChange={setSelectedIds}
|
||||
master={{
|
||||
counts: {
|
||||
inboundCount: 8,
|
||||
clientCount: 2200,
|
||||
activeCount: 1860,
|
||||
disabledCount: 50,
|
||||
depletedCount: 290,
|
||||
onlineCount: 80,
|
||||
},
|
||||
panelVersion: '3.13.0',
|
||||
xrayVersion: '26.1.1',
|
||||
xrayState: 'running',
|
||||
telemetry: {
|
||||
sampledAt: now,
|
||||
cpuPct: 20,
|
||||
logicalCores: 4,
|
||||
memUsedBytes: 2 * 2 ** 30,
|
||||
memTotalBytes: 8 * 2 ** 30,
|
||||
netUp: 1024,
|
||||
netDown: 2048,
|
||||
tcpCount: 10,
|
||||
udpCount: 5,
|
||||
load1: 0.5,
|
||||
load5: 0.3,
|
||||
load15: 0.15,
|
||||
uptimeSecs: 91000,
|
||||
},
|
||||
}}
|
||||
fleet={counts}
|
||||
latestVersion="3.13.0"
|
||||
onAdd={noop}
|
||||
onMtls={noop}
|
||||
onEdit={noop}
|
||||
onDelete={noop}
|
||||
onProbe={noop}
|
||||
onToggleEnable={noop}
|
||||
onUpdateNode={noop}
|
||||
onUpdateSelected={noop}
|
||||
onRestart={noop}
|
||||
/>
|
||||
</div>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const meta = { title: 'Nodes/Fleet Monitoring', component: Fixture } satisfies Meta<typeof Fixture>;
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Desktop: Story = {
|
||||
play: async ({ canvasElement, userEvent }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const row = canvas.getByRole('row', { name: /All nodes/ });
|
||||
await expect(within(row).getByText('3/5 reporting')).toBeVisible();
|
||||
await expect(within(row).getByText('20.0%')).toBeVisible();
|
||||
await expect(within(row).queryByRole('checkbox')).toBeNull();
|
||||
await expect(
|
||||
within(canvas.getByRole('row', { name: /Master/ })).queryByRole('switch'),
|
||||
).toBeNull();
|
||||
const edge = canvas.getByRole('row', { name: /Finland edge/ });
|
||||
const link = within(edge).getByRole('link', { name: 'Open' });
|
||||
await expect(link).toHaveAttribute('href', 'https://[2001:db8::3]:2053/edge/');
|
||||
await expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
const status = within(edge).getByRole('button', { name: 'Online' });
|
||||
await userEvent.click(status);
|
||||
await expect(await within(canvasElement.ownerDocument.body).findByText('42 ms')).toBeVisible();
|
||||
const input = canvas.getByRole('searchbox', { name: 'Search' });
|
||||
await userEvent.click(input);
|
||||
for (const viewport of [1280, 1440, 1664, 1920]) {
|
||||
const container = canvas.getByRole('region', { name: 'Nodes' });
|
||||
container.style.width = `${viewport - 260}px`;
|
||||
const table = container.querySelector('.nodes-table-scroll') as HTMLElement;
|
||||
await expect(table.scrollWidth).toBeLessThanOrEqual(table.clientWidth + 1);
|
||||
container.style.width = '';
|
||||
}
|
||||
await userEvent.type(input, 'Frankfurt');
|
||||
await expect(canvas.queryByText('Finland edge')).toBeNull();
|
||||
await expect(canvas.getByText('3/5 reporting')).toBeVisible();
|
||||
await userEvent.clear(input);
|
||||
},
|
||||
};
|
||||
|
||||
export const RTL: Story = { args: { rtl: true }, globals: { theme: 'light' } };
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,6 @@ export default function NodeNetworkSpeed({
|
||||
node: NodeRecord;
|
||||
receivedAt?: number;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { token } = theme.useToken();
|
||||
const expiration =
|
||||
receivedAt && node.heartbeatAgeMillis != null
|
||||
? receivedAt + HEARTBEAT_FRESHNESS_MS - node.heartbeatAgeMillis
|
||||
@@ -40,15 +38,36 @@ export default function NodeNetworkSpeed({
|
||||
};
|
||||
const fresh = useSyncExternalStore(subscribe, isFresh);
|
||||
const available = node.enable && node.status === 'online' && !node.transitive && fresh;
|
||||
return (
|
||||
<NetworkSpeedValues
|
||||
up={available && !node.unavailableMetrics?.includes('netUp') ? node.netUp : undefined}
|
||||
down={available && !node.unavailableMetrics?.includes('netDown') ? node.netDown : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function NetworkSpeedValues({
|
||||
up,
|
||||
down,
|
||||
uploadFirst,
|
||||
}: {
|
||||
up?: number | null;
|
||||
down?: number | null;
|
||||
uploadFirst?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { token } = theme.useToken();
|
||||
const directions = [
|
||||
{
|
||||
key: 'netDown' as const,
|
||||
rate: down,
|
||||
isUpload: false,
|
||||
label: t('pages.index.download'),
|
||||
Icon: ArrowDownOutlined,
|
||||
color: token.colorTextTertiary,
|
||||
},
|
||||
{
|
||||
key: 'netUp' as const,
|
||||
rate: up,
|
||||
isUpload: true,
|
||||
label: t('pages.index.upload'),
|
||||
Icon: ArrowUpOutlined,
|
||||
color: token.colorPrimary,
|
||||
@@ -56,30 +75,27 @@ export default function NodeNetworkSpeed({
|
||||
];
|
||||
return (
|
||||
<span className="node-network-speed">
|
||||
{directions.map(({ key, label, Icon, color }) => {
|
||||
const rate = node[key];
|
||||
const value =
|
||||
available &&
|
||||
!node.unavailableMetrics?.includes(key) &&
|
||||
typeof rate === 'number' &&
|
||||
Number.isFinite(rate) &&
|
||||
rate >= 0
|
||||
? SizeFormatter.speedFormat(rate)
|
||||
: '—';
|
||||
return (
|
||||
<Tooltip key={key} title={label}>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label + ' ' + value}
|
||||
className="node-network-direction"
|
||||
dir="ltr"
|
||||
>
|
||||
<Icon aria-hidden style={{ color }} />
|
||||
<span aria-hidden>{value}</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
{(uploadFirst ? directions.reverse() : directions).map(
|
||||
({ rate, label, Icon, color, isUpload }) => {
|
||||
const value =
|
||||
typeof rate === 'number' && Number.isFinite(rate) && rate >= 0
|
||||
? SizeFormatter.speedFormat(rate)
|
||||
: '—';
|
||||
return (
|
||||
<Tooltip key={label} title={label}>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label + ' ' + value}
|
||||
className={'node-network-direction' + (isUpload ? ' node-network-up' : '')}
|
||||
dir="ltr"
|
||||
>
|
||||
<Icon aria-hidden style={{ color }} />
|
||||
<span aria-hidden>{value}</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,30 +4,18 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
Col,
|
||||
ConfigProvider,
|
||||
Input,
|
||||
Layout,
|
||||
Modal,
|
||||
Result,
|
||||
Row,
|
||||
Spin,
|
||||
Statistic,
|
||||
Typography,
|
||||
message,
|
||||
} from 'antd';
|
||||
import {
|
||||
CheckCircleOutlined,
|
||||
CloseCircleOutlined,
|
||||
CloudServerOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons';
|
||||
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
import { useMediaQuery } from '@/hooks/useMediaQuery';
|
||||
import { useNodesQuery } from '@/api/queries/useNodesQuery';
|
||||
import { useNodeOverviewQuery } from '@/api/queries/useNodesQuery';
|
||||
import type { NodeRecord } from '@/api/queries/useNodesQuery';
|
||||
import { useNodeMutations } from '@/api/queries/useNodeMutations';
|
||||
import AppSidebar from '@/layouts/AppSidebar';
|
||||
@@ -70,14 +58,23 @@ function UpdateChannelChoice({ onChange }: { onChange: (dev: boolean) => void })
|
||||
export default function NodesPage() {
|
||||
const { t } = useTranslation();
|
||||
const { isDark, isUltra, antdThemeConfig } = useTheme();
|
||||
const { isMobile } = useMediaQuery();
|
||||
const [modal, modalContextHolder] = Modal.useModal();
|
||||
const [messageApi, messageContextHolder] = message.useMessage();
|
||||
useEffect(() => {
|
||||
setMessageInstance(messageApi);
|
||||
}, [messageApi]);
|
||||
|
||||
const { nodes, nodesUpdatedAt, loading, fetched, fetchError, refetch, totals } = useNodesQuery();
|
||||
const {
|
||||
nodes,
|
||||
master,
|
||||
fleet,
|
||||
nodesUpdatedAt,
|
||||
loading,
|
||||
fetched,
|
||||
fetchError,
|
||||
refreshError,
|
||||
refetch,
|
||||
} = useNodeOverviewQuery();
|
||||
const {
|
||||
create,
|
||||
update,
|
||||
@@ -360,74 +357,29 @@ export default function NodesPage() {
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Row gutter={[isMobile ? 8 : 16, isMobile ? 8 : 12]}>
|
||||
<Col span={24}>
|
||||
<Card size="small" hoverable className="summary-card">
|
||||
<Row gutter={[16, isMobile ? 16 : 12]}>
|
||||
<Col xs={12} sm={12} md={6}>
|
||||
<Statistic
|
||||
title={t('pages.nodes.totalNodes')}
|
||||
value={String(totals.total)}
|
||||
prefix={<CloudServerOutlined aria-hidden />}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={12} sm={12} md={6}>
|
||||
<Statistic
|
||||
title={t('pages.nodes.onlineNodes')}
|
||||
value={String(totals.online)}
|
||||
prefix={
|
||||
<CheckCircleOutlined
|
||||
aria-hidden
|
||||
style={{ color: 'var(--ant-color-success)' }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={12} sm={12} md={6}>
|
||||
<Statistic
|
||||
title={t('pages.nodes.offlineNodes')}
|
||||
value={String(totals.offline)}
|
||||
prefix={
|
||||
<CloseCircleOutlined
|
||||
aria-hidden
|
||||
style={{ color: 'var(--ant-color-error)' }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={12} sm={12} md={6}>
|
||||
<Statistic
|
||||
title={t('pages.nodes.avgLatency')}
|
||||
value={totals.avgLatency > 0 ? `${totals.avgLatency} ms` : '-'}
|
||||
prefix={<ThunderboltOutlined aria-hidden />}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col span={24}>
|
||||
<NodeList
|
||||
nodes={nodes}
|
||||
nodesUpdatedAt={nodesUpdatedAt}
|
||||
loading={loading}
|
||||
isMobile={isMobile}
|
||||
latestVersion={latestVersion}
|
||||
selectedIds={selectedIds}
|
||||
onSelectionChange={setSelectedIds}
|
||||
onAdd={onAdd}
|
||||
onMtls={() => setMtlsOpen(true)}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
onProbe={onProbe}
|
||||
onToggleEnable={onToggleEnable}
|
||||
onUpdateNode={onUpdateNode}
|
||||
onUpdateSelected={onUpdateSelected}
|
||||
onRestart={onRestart}
|
||||
restartingIds={restartingIds}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<>
|
||||
{refreshError && <Alert type="warning" showIcon title={refreshError} />}
|
||||
<NodeList
|
||||
nodes={nodes}
|
||||
master={master}
|
||||
fleet={fleet}
|
||||
nodesUpdatedAt={nodesUpdatedAt}
|
||||
loading={loading}
|
||||
latestVersion={latestVersion}
|
||||
selectedIds={selectedIds}
|
||||
onSelectionChange={setSelectedIds}
|
||||
onAdd={onAdd}
|
||||
onMtls={() => setMtlsOpen(true)}
|
||||
onEdit={onEdit}
|
||||
onDelete={onDelete}
|
||||
onProbe={onProbe}
|
||||
onToggleEnable={onToggleEnable}
|
||||
onUpdateNode={onUpdateNode}
|
||||
onUpdateSelected={onUpdateSelected}
|
||||
onRestart={onRestart}
|
||||
restartingIds={restartingIds}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Spin>
|
||||
</Layout.Content>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { useCallback, useMemo, useState, useSyncExternalStore } from 'react';
|
||||
import type { NodeTelemetry } from '@/generated/types';
|
||||
|
||||
const FRESHNESS_MS = 30_000;
|
||||
|
||||
function expires(sample: NodeTelemetry, receivedAt?: number) {
|
||||
return receivedAt && sample.sampleAgeMillis != null
|
||||
? receivedAt + FRESHNESS_MS - sample.sampleAgeMillis
|
||||
: sample.sampledAt + FRESHNESS_MS;
|
||||
}
|
||||
|
||||
export function freshTelemetry(
|
||||
sample: NodeTelemetry | null | undefined,
|
||||
now: number,
|
||||
receivedAt?: number,
|
||||
) {
|
||||
if (!sample) return undefined;
|
||||
const remaining = expires(sample, receivedAt) - now;
|
||||
return remaining > 0 && remaining <= FRESHNESS_MS ? sample : undefined;
|
||||
}
|
||||
|
||||
export function useTelemetryClock(
|
||||
samples: readonly (NodeTelemetry | null | undefined)[],
|
||||
receivedAt?: number,
|
||||
) {
|
||||
const [mountedAt] = useState(Date.now);
|
||||
const deadlines = useMemo(
|
||||
() =>
|
||||
samples
|
||||
.flatMap((sample) => (sample ? [expires(sample, receivedAt)] : []))
|
||||
.sort((a, b) => a - b),
|
||||
[samples, receivedAt],
|
||||
);
|
||||
const subscribe = useCallback(
|
||||
(refresh: () => void) => {
|
||||
let timer: number | undefined;
|
||||
const schedule = () => {
|
||||
const now = Date.now();
|
||||
const deadline = deadlines.find((time) => time > now && time <= now + FRESHNESS_MS);
|
||||
if (deadline !== undefined) {
|
||||
timer = window.setTimeout(() => {
|
||||
refresh();
|
||||
schedule();
|
||||
}, deadline - now);
|
||||
}
|
||||
};
|
||||
schedule();
|
||||
return () => window.clearTimeout(timer);
|
||||
},
|
||||
[deadlines],
|
||||
);
|
||||
const snapshot = () => {
|
||||
const now = Date.now();
|
||||
const latestExpiry = deadlines.reduce((last, time) => (time <= now ? time : last), 0);
|
||||
return Math.max(mountedAt, receivedAt ?? 0, latestExpiry);
|
||||
};
|
||||
return useSyncExternalStore(subscribe, snapshot, snapshot);
|
||||
}
|
||||
|
||||
export function aggregateTelemetry(samples: NodeTelemetry[]) {
|
||||
const cpu = samples.filter((host) => host.cpuPct != null);
|
||||
const memory = samples.filter(
|
||||
(host) =>
|
||||
host.memTotalBytes != null &&
|
||||
host.memTotalBytes > 0 &&
|
||||
host.memUsedBytes != null &&
|
||||
host.memUsedBytes <= host.memTotalBytes,
|
||||
);
|
||||
function sum(key: keyof NodeTelemetry, hosts = samples) {
|
||||
let total: number | undefined;
|
||||
for (const sample of hosts) {
|
||||
const value = sample[key];
|
||||
if (typeof value === 'number') total = (total ?? 0) + value;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
const telemetry: NodeTelemetry = {
|
||||
sampledAt: 0,
|
||||
cpuPct: cpu.length ? (sum('cpuPct', cpu) ?? 0) / cpu.length : undefined,
|
||||
logicalCores: cpu.every((host) => host.logicalCores != null)
|
||||
? sum('logicalCores', cpu)
|
||||
: undefined,
|
||||
memUsedBytes: sum('memUsedBytes', memory),
|
||||
memTotalBytes: sum('memTotalBytes', memory),
|
||||
memAvailableBytes: memory.every((host) => host.memAvailableBytes != null)
|
||||
? sum('memAvailableBytes', memory)
|
||||
: undefined,
|
||||
netUp: sum('netUp'),
|
||||
netDown: sum('netDown'),
|
||||
tcpCount: sum('tcpCount'),
|
||||
udpCount: sum('udpCount'),
|
||||
load1: sum('load1'),
|
||||
load5: sum('load5'),
|
||||
load15: sum('load15'),
|
||||
};
|
||||
return { telemetry, cpuHosts: cpu.length, memoryHosts: memory.length };
|
||||
}
|
||||
|
||||
export function reportingSample(sample: NodeTelemetry | null | undefined): sample is NodeTelemetry {
|
||||
if (!sample) return false;
|
||||
const { sampledAt: _time, sampleAgeMillis: _age, resourceScope: _scope, ...metrics } = sample;
|
||||
return Object.values(metrics).some((metric) => typeof metric === 'number');
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright 2010-2018 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { NodeFleetCountsSchema, NodeMasterViewSchema, NodeTelemetrySchema } from '@/generated/zod';
|
||||
|
||||
export const NodeRecordSchema = z
|
||||
.object({
|
||||
@@ -23,6 +24,7 @@ export const NodeRecordSchema = z
|
||||
panelVersion: z.string().optional(),
|
||||
uptimeSecs: z.number().optional(),
|
||||
unavailableMetrics: z.array(z.string()).optional(),
|
||||
telemetry: NodeTelemetrySchema.optional(),
|
||||
inboundCount: z.number().optional(),
|
||||
clientCount: z.number().optional(),
|
||||
onlineCount: z.number().optional(),
|
||||
@@ -54,6 +56,11 @@ export const NodeRecordSchema = z
|
||||
.loose();
|
||||
|
||||
export const NodeListSchema = z.array(NodeRecordSchema);
|
||||
export const NodeOverviewSchema = z.object({
|
||||
nodes: NodeListSchema,
|
||||
master: NodeMasterViewSchema,
|
||||
fleet: NodeFleetCountsSchema,
|
||||
});
|
||||
|
||||
export const ProbeResultSchema = z
|
||||
.object({
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { act, fireEvent, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { expect, it, vi } from 'vitest';
|
||||
import NodeList from '@/pages/nodes/NodeList';
|
||||
import type { NodeRecord } from '@/schemas/node';
|
||||
import { renderWithProviders } from './test-utils';
|
||||
|
||||
const counts = {
|
||||
inboundCount: 1,
|
||||
clientCount: 2,
|
||||
activeCount: 2,
|
||||
disabledCount: 0,
|
||||
depletedCount: 0,
|
||||
onlineCount: 1,
|
||||
};
|
||||
const noop = () => {};
|
||||
const actions = {
|
||||
onAdd: noop,
|
||||
onMtls: noop,
|
||||
onEdit: noop,
|
||||
onDelete: noop,
|
||||
onProbe: noop,
|
||||
onToggleEnable: noop,
|
||||
onUpdateNode: noop,
|
||||
onUpdateSelected: noop,
|
||||
onRestart: noop,
|
||||
};
|
||||
|
||||
it('hides Master and All nodes without a remote, even with fresh Master telemetry', async () => {
|
||||
const onAdd = vi.fn();
|
||||
const sampledAt = Date.now();
|
||||
function list(nodes: NodeRecord[]) {
|
||||
return (
|
||||
<NodeList
|
||||
{...actions}
|
||||
onAdd={onAdd}
|
||||
nodes={nodes}
|
||||
master={{ counts, telemetry: { sampledAt, cpuPct: 31 } }}
|
||||
fleet={counts}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
/>
|
||||
);
|
||||
}
|
||||
const view = renderWithProviders(list([]));
|
||||
expect(screen.queryByRole('table')).toBeNull();
|
||||
expect(screen.queryByRole('searchbox')).toBeNull();
|
||||
expect(screen.queryByText('All nodes')).toBeNull();
|
||||
expect(screen.queryByRole('rowheader', { name: 'Master' })).toBeNull();
|
||||
expect(screen.queryByRole('switch')).toBeNull();
|
||||
await userEvent.click(screen.getByRole('button', { name: /add node/i }));
|
||||
expect(onAdd).toHaveBeenCalledOnce();
|
||||
view.rerender(list([{ id: 1, name: 'disabled edge', enable: false, status: 'online' }]));
|
||||
const rows = screen.getAllByRole('row');
|
||||
expect(rows[1].textContent).toContain('All nodes');
|
||||
expect(rows[1].textContent).toContain('1/2 reporting');
|
||||
expect(rows[2].textContent).toContain('Master');
|
||||
expect(rows[3].textContent).toContain('disabled edge');
|
||||
fireEvent.change(screen.getByRole('searchbox'), { target: { value: 'unmatched' } });
|
||||
expect(screen.getAllByRole('row')).toHaveLength(3);
|
||||
expect(screen.getByText('1/2 reporting')).toBeTruthy();
|
||||
view.rerender(list([]));
|
||||
expect(screen.queryByRole('table')).toBeNull();
|
||||
expect(screen.queryByText(/totals use reporting nodes/)).toBeNull();
|
||||
});
|
||||
|
||||
it('expires only the stale host and keeps weighted RAM and live byte rates separate', () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const now = Date.now();
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
{...actions}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
nodesUpdatedAt={now}
|
||||
nodes={[
|
||||
{
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
enable: true,
|
||||
status: 'online',
|
||||
telemetry: {
|
||||
sampledAt: now - 29_500,
|
||||
sampleAgeMillis: 29_500,
|
||||
memUsedBytes: 4 * 2 ** 30,
|
||||
memTotalBytes: 16 * 2 ** 30,
|
||||
netDown: 1024,
|
||||
tcpCount: 0,
|
||||
cpuPct: 20,
|
||||
logicalCores: 4,
|
||||
},
|
||||
},
|
||||
]}
|
||||
master={{
|
||||
counts,
|
||||
telemetry: {
|
||||
sampledAt: now,
|
||||
sampleAgeMillis: 0,
|
||||
memUsedBytes: 6 * 2 ** 30,
|
||||
memTotalBytes: 8 * 2 ** 30,
|
||||
cpuPct: 40,
|
||||
logicalCores: 8,
|
||||
netDown: 2048,
|
||||
tcpCount: 10,
|
||||
},
|
||||
}}
|
||||
fleet={counts}
|
||||
/>,
|
||||
);
|
||||
const fleet = () => within(screen.getByRole('row', { name: /All nodes/ }));
|
||||
expect(fleet().getByText(/10 GB \/ 24 GB · 41.7%/)).toBeTruthy();
|
||||
expect(fleet().getByText('30.0%')).toBeTruthy();
|
||||
expect(fleet().getByLabelText(/download 3.00 KB\/s/i)).toBeTruthy();
|
||||
act(() => vi.advanceTimersByTime(501));
|
||||
expect(fleet().getByText('1/2 reporting')).toBeTruthy();
|
||||
expect(fleet().getByText('40.0%')).toBeTruthy();
|
||||
expect(fleet().getByLabelText(/download 2.00 KB\/s/i)).toBeTruthy();
|
||||
expect(
|
||||
within(screen.getByRole('row', { name: /edge/ })).getByLabelText(/download —/i),
|
||||
).toBeTruthy();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
@@ -18,11 +18,10 @@ const failing: NodeRecord = {
|
||||
lastError: 'dial tcp 10.0.0.2:2053: i/o timeout',
|
||||
};
|
||||
|
||||
function renderList(isMobile: boolean) {
|
||||
function renderList() {
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={[failing]}
|
||||
isMobile={isMobile}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
@@ -42,13 +41,13 @@ function renderList(isMobile: boolean) {
|
||||
// screen reader heard "exclamation-circle" and "switch" (s-ui#1293).
|
||||
describe('NodeList screen-reader names', () => {
|
||||
it('announces the node error from the status column', () => {
|
||||
renderList(false);
|
||||
renderList();
|
||||
|
||||
expect(screen.getByRole('img', { name: failing.lastError }).tagName).toBe('SPAN');
|
||||
});
|
||||
|
||||
it.each([false, true])('names the enable switch (mobile=%s)', (isMobile) => {
|
||||
renderList(isMobile);
|
||||
it('names the enable switch', () => {
|
||||
renderList();
|
||||
|
||||
expect(screen.getByRole('switch', { name: 'Enabled' }).getAttribute('aria-checked')).toBe(
|
||||
'true',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
@@ -9,10 +9,7 @@ import { renderWithProviders } from './test-utils';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
function renderNode(
|
||||
counts: Pick<NodeRecord, 'onlineCount' | 'onlineTotalCount'>,
|
||||
isMobile = false,
|
||||
) {
|
||||
function renderNode(counts: Pick<NodeRecord, 'onlineCount' | 'onlineTotalCount'>) {
|
||||
const node: NodeRecord = {
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
@@ -25,7 +22,6 @@ function renderNode(
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={[node]}
|
||||
isMobile={isMobile}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
@@ -67,14 +63,6 @@ describe('NodeList online total', () => {
|
||||
renderNode(counts);
|
||||
|
||||
expect(screen.getByText('7')).toBeTruthy();
|
||||
expect(screen.queryByText(/\d \/ \d/)).toBeNull();
|
||||
});
|
||||
|
||||
it('shows synced / total in the mobile stats dialog', async () => {
|
||||
renderNode({ onlineCount: 3, onlineTotalCount: 12 }, true);
|
||||
|
||||
await userEvent.click(screen.getByRole('button', { name: 'More Information' }));
|
||||
|
||||
expect(within(await screen.findByRole('dialog')).getByText('3 / 12 Online')).toBeTruthy();
|
||||
expect(screen.queryByText(/^\d+ \/ \d+$/)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +44,6 @@ describe('NodeList re-render', () => {
|
||||
const noop = () => {};
|
||||
const props = {
|
||||
nodes,
|
||||
isMobile: false,
|
||||
latestVersion: '3.0.1',
|
||||
selectedIds: [] as number[],
|
||||
onSelectionChange: noop,
|
||||
|
||||
@@ -24,7 +24,6 @@ describe('NodeList desktop table row keys', () => {
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={sampleNodes()}
|
||||
isMobile={false}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
|
||||
@@ -21,7 +21,6 @@ function renderSubNode(fields: Partial<NodeRecord>) {
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={nodes}
|
||||
isMobile={false}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
|
||||
@@ -8,42 +8,7 @@ import { renderWithProviders } from './test-utils';
|
||||
const noop = () => {};
|
||||
|
||||
describe('node metric availability', () => {
|
||||
it.each([false, true])(
|
||||
'does not present unavailable CPU as measured zero (mobile=%s)',
|
||||
(isMobile) => {
|
||||
const node = NodeRecordSchema.parse({
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
status: 'online',
|
||||
enable: true,
|
||||
cpuPct: 0,
|
||||
memPct: 44.4,
|
||||
uptimeSecs: 0,
|
||||
unavailableMetrics: ['cpu', 'uptime'],
|
||||
});
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={[node]}
|
||||
isMobile={isMobile}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
onMtls={noop}
|
||||
onEdit={noop}
|
||||
onDelete={noop}
|
||||
onProbe={noop}
|
||||
onToggleEnable={noop}
|
||||
onUpdateNode={noop}
|
||||
onUpdateSelected={noop}
|
||||
onRestart={noop}
|
||||
/>,
|
||||
);
|
||||
if (isMobile) fireEvent.click(screen.getByRole('button', { name: 'More Information' }));
|
||||
expect(screen.queryByText('0.0%')).toBeNull();
|
||||
expect(screen.getAllByText('—').length).toBeGreaterThanOrEqual(2);
|
||||
},
|
||||
);
|
||||
it('keeps a measured zero CPU and an unprobed uptime apart', () => {
|
||||
it('does not present unavailable CPU as measured zero', () => {
|
||||
const node = NodeRecordSchema.parse({
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
@@ -52,6 +17,34 @@ describe('node metric availability', () => {
|
||||
cpuPct: 0,
|
||||
memPct: 44.4,
|
||||
uptimeSecs: 0,
|
||||
unavailableMetrics: ['cpu', 'uptime'],
|
||||
});
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
nodes={[node]}
|
||||
selectedIds={[]}
|
||||
onSelectionChange={noop}
|
||||
onAdd={noop}
|
||||
onMtls={noop}
|
||||
onEdit={noop}
|
||||
onDelete={noop}
|
||||
onProbe={noop}
|
||||
onToggleEnable={noop}
|
||||
onUpdateNode={noop}
|
||||
onUpdateSelected={noop}
|
||||
onRestart={noop}
|
||||
/>,
|
||||
);
|
||||
expect(screen.queryByText('0.0%')).toBeNull();
|
||||
expect(screen.getAllByText('—').length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
it('keeps a measured zero CPU and an unprobed uptime apart', () => {
|
||||
const node = NodeRecordSchema.parse({
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
status: 'online',
|
||||
enable: true,
|
||||
telemetry: { sampledAt: Date.now(), cpuPct: 0 },
|
||||
});
|
||||
renderWithProviders(
|
||||
<NodeList
|
||||
@@ -70,9 +63,8 @@ describe('node metric availability', () => {
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText('0.0%')).not.toBeNull();
|
||||
const headers = screen.getAllByRole('columnheader').map((h) => h.textContent);
|
||||
const cells = within(screen.getAllByRole('row')[1]).getAllByRole('cell');
|
||||
expect(cells[headers.indexOf('Uptime')].textContent).toBe('-');
|
||||
const cell = within(screen.getAllByRole('row')[1]).getByTitle('Uptime');
|
||||
expect(cell.textContent).toBe('Up —');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,43 +82,40 @@ describe('node network speed', () => {
|
||||
onUpdateSelected: noop,
|
||||
onRestart: noop,
|
||||
};
|
||||
it.each([false, true])(
|
||||
'renders current directions and preserves measured zero (mobile=%s)',
|
||||
(isMobile) => {
|
||||
const node = NodeRecordSchema.parse({
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
enable: true,
|
||||
status: 'online',
|
||||
lastHeartbeat: Math.floor(Date.now() / 1000),
|
||||
netDown: 2048,
|
||||
netUp: 0,
|
||||
});
|
||||
function Fixture() {
|
||||
const [record, setRecord] = useState(node);
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setRecord({ ...record, lastHeartbeat: (node.lastHeartbeat ?? 0) - 120 })
|
||||
}
|
||||
>
|
||||
Age sample
|
||||
</button>
|
||||
<NodeList {...controls} nodes={[record]} isMobile={isMobile} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
renderWithProviders(<Fixture />);
|
||||
if (isMobile) fireEvent.click(screen.getByRole('button', { name: 'More Information' }));
|
||||
expect(screen.getByLabelText(/^download .*2\.00 KB\/s$/i).textContent).toContain('2.00 KB/s');
|
||||
expect(screen.getByLabelText(/^upload .*0 B\/s$/i).textContent).toContain('0 B/s');
|
||||
// A heartbeat cache update must also refresh the open mobile stats dialog.
|
||||
fireEvent.click(screen.getByText('Age sample'));
|
||||
expect(screen.getByLabelText(/^download .*—$/i).textContent).toContain('—');
|
||||
},
|
||||
);
|
||||
it('renders current directions and preserves measured zero', () => {
|
||||
const node = NodeRecordSchema.parse({
|
||||
id: 1,
|
||||
name: 'edge',
|
||||
enable: true,
|
||||
status: 'online',
|
||||
lastHeartbeat: Math.floor(Date.now() / 1000),
|
||||
telemetry: { sampledAt: Date.now(), netDown: 2048, netUp: 0 },
|
||||
});
|
||||
function Fixture() {
|
||||
const [record, setRecord] = useState(node);
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setRecord({
|
||||
...record,
|
||||
telemetry: { sampledAt: Date.now() - 120_000, netDown: 2048, netUp: 0 },
|
||||
})
|
||||
}
|
||||
>
|
||||
Age sample
|
||||
</button>
|
||||
<NodeList {...controls} nodes={[record]} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
renderWithProviders(<Fixture />);
|
||||
expect(screen.getByLabelText(/^download .*2\.00 KB\/s$/i).textContent).toContain('2.00 KB/s');
|
||||
expect(screen.getByLabelText(/^upload .*0 B\/s$/i).textContent).toContain('0 B/s');
|
||||
fireEvent.click(screen.getByText('Age sample'));
|
||||
expect(screen.getByLabelText(/^download .*—$/i).textContent).toContain('—');
|
||||
});
|
||||
|
||||
it.each([-120, 120])('expires throughput with %s seconds of clock skew', (skew) => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { act, fireEvent, screen, within } from '@testing-library/react';
|
||||
import { expect, it, vi } from 'vitest';
|
||||
|
||||
import { keys } from '@/api/queryKeys';
|
||||
import NodesPage from '@/pages/nodes/NodesPage';
|
||||
import { HttpUtil, Msg } from '@/utils';
|
||||
import { makeTestQueryClient, renderWithProviders } from './test-utils';
|
||||
|
||||
vi.mock('@/layouts/AppSidebar', () => ({ default: () => null }));
|
||||
|
||||
it('keeps node actions and the current filter after an overview refresh fails', async () => {
|
||||
const counts = {
|
||||
inboundCount: 0,
|
||||
clientCount: 0,
|
||||
activeCount: 0,
|
||||
disabledCount: 0,
|
||||
depletedCount: 0,
|
||||
onlineCount: 0,
|
||||
};
|
||||
let available = true;
|
||||
const get = vi.spyOn(HttpUtil, 'get').mockImplementation(async (path) => {
|
||||
if (path !== '/panel/api/nodes/overview') return new Msg(true, '', {});
|
||||
return available
|
||||
? new Msg(true, '', {
|
||||
nodes: [{ id: 1, name: 'edge-one', enable: true, status: 'online' }],
|
||||
master: { counts },
|
||||
fleet: counts,
|
||||
})
|
||||
: new Msg(false, 'Overview unavailable');
|
||||
});
|
||||
const queryClient = makeTestQueryClient();
|
||||
try {
|
||||
renderWithProviders(<NodesPage />, { queryClient });
|
||||
const search = await screen.findByRole('searchbox');
|
||||
fireEvent.change(search, { target: { value: 'edge' } });
|
||||
const row = screen.getByRole('row', { name: /edge-one/ });
|
||||
|
||||
available = false;
|
||||
await act(async () => queryClient.refetchQueries({ queryKey: keys.nodes.overview() }));
|
||||
expect(await screen.findByText('Overview unavailable')).toBeTruthy();
|
||||
expect(screen.getByRole('searchbox')).toBe(search);
|
||||
expect((search as HTMLInputElement).value).toBe('edge');
|
||||
expect(within(row).getByRole('button', { name: 'Edit' })).toBeTruthy();
|
||||
} finally {
|
||||
get.mockRestore();
|
||||
}
|
||||
});
|
||||
@@ -8,29 +8,17 @@ import type { NodeRecord } from '@/schemas/node';
|
||||
import { renderWithProviders } from './test-utils';
|
||||
|
||||
const state = vi.hoisted(() => ({
|
||||
isMobile: false,
|
||||
nodes: [] as NodeRecord[],
|
||||
refetch: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/hooks/useMediaQuery', () => ({ useMediaQuery: () => ({ isMobile: state.isMobile }) }));
|
||||
vi.mock('@/api/queries/useNodesQuery', () => ({
|
||||
useNodesQuery: () => ({
|
||||
useNodeOverviewQuery: () => ({
|
||||
nodes: state.nodes,
|
||||
loading: false,
|
||||
fetched: true,
|
||||
fetchError: '',
|
||||
refetch: state.refetch,
|
||||
totals: {
|
||||
total: state.nodes.length,
|
||||
online: 0,
|
||||
offline: 1,
|
||||
avgLatency: 0,
|
||||
inbounds: 0,
|
||||
clients: 0,
|
||||
onlineClients: 0,
|
||||
depleted: 0,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
vi.mock('@/pages/nodes/NodeFormModal', () => ({ default: () => null }));
|
||||
@@ -38,7 +26,6 @@ vi.mock('@/pages/nodes/NodeHistoryPanel', () => ({ default: () => null }));
|
||||
vi.mock('@/layouts/AppSidebar', () => ({ default: () => null }));
|
||||
|
||||
beforeEach(() => {
|
||||
state.isMobile = false;
|
||||
state.nodes = [{ id: 7, name: 'edge-seven', guid: 'seven', enable: true, status: 'offline' }];
|
||||
vi.spyOn(HttpUtil, 'get').mockResolvedValue(new Msg(true, '', {}));
|
||||
});
|
||||
@@ -51,43 +38,39 @@ async function openRestart(label: string) {
|
||||
}
|
||||
|
||||
describe('remote node restart', () => {
|
||||
it.each([false, true])(
|
||||
'confirms each action and sends only the selected request (mobile=%s)',
|
||||
async (mobile) => {
|
||||
state.isMobile = mobile;
|
||||
const post = vi
|
||||
.spyOn(HttpUtil, 'post')
|
||||
.mockResolvedValue({ success: true, msg: '', obj: null });
|
||||
renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
let dialog = await openRestart('Restart Xray');
|
||||
expect(dialog.textContent).toContain('edge-seven');
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
||||
it('confirms each action and sends only the selected request', async () => {
|
||||
const post = vi
|
||||
.spyOn(HttpUtil, 'post')
|
||||
.mockResolvedValue({ success: true, msg: '', obj: null });
|
||||
renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
let dialog = await openRestart('Restart Xray');
|
||||
expect(dialog.textContent).toContain('edge-seven');
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
||||
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
for (const [label, action, success] of [
|
||||
['Restart Xray', 'restartXray', 'Xray restarted on the node.'],
|
||||
[
|
||||
'Restart Panel',
|
||||
'restartPanel',
|
||||
'Panel restart request accepted. The node may be temporarily unavailable.',
|
||||
],
|
||||
]) {
|
||||
dialog = await openRestart(label);
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: label }));
|
||||
await screen.findByText(success);
|
||||
expect(post.mock.calls.at(-1)?.[0]).toBe(`/panel/api/nodes/${action}/7`);
|
||||
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
for (const [label, action, success] of [
|
||||
['Restart Xray', 'restartXray', 'Xray restarted on the node.'],
|
||||
[
|
||||
'Restart Panel',
|
||||
'restartPanel',
|
||||
'Panel restart request accepted. The node may be temporarily unavailable.',
|
||||
],
|
||||
]) {
|
||||
dialog = await openRestart(label);
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: label }));
|
||||
await screen.findByText(success);
|
||||
expect(post.mock.calls.at(-1)?.[0]).toBe(`/panel/api/nodes/${action}/7`);
|
||||
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
||||
}
|
||||
expect(post).toHaveBeenCalledTimes(2);
|
||||
},
|
||||
);
|
||||
}
|
||||
expect(post).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('keeps both actions disabled while the request is pending and reports a node rejection without retrying', async () => {
|
||||
let finish!: (msg: Msg<never>) => void;
|
||||
@@ -116,32 +99,28 @@ describe('remote node restart', () => {
|
||||
expect(post).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
'does not offer restart for transitive nodes and disables it for disabled nodes (mobile=%s)',
|
||||
async (mobile) => {
|
||||
state.isMobile = mobile;
|
||||
state.nodes = [
|
||||
{ id: 0, name: 'child', guid: 'child', transitive: true, enable: true, status: 'online' },
|
||||
];
|
||||
const view = renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
it('does not offer restart for transitive nodes and disables it for disabled nodes', async () => {
|
||||
state.nodes = [
|
||||
{ id: 0, name: 'child', guid: 'child', transitive: true, enable: true, status: 'online' },
|
||||
];
|
||||
const view = renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
expect(screen.queryByRole('button', { name: /^more$/i })).toBeNull();
|
||||
view.unmount();
|
||||
state.nodes = [{ id: 7, name: 'disabled', enable: false }];
|
||||
renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button', { name: /^more$/i }));
|
||||
for (const name of ['Restart Xray', 'Restart Panel']) {
|
||||
expect((await screen.findByRole('menuitem', { name })).getAttribute('aria-disabled')).toBe(
|
||||
'true',
|
||||
);
|
||||
expect(screen.queryByRole('button', { name: /^more$/i })).toBeNull();
|
||||
view.unmount();
|
||||
state.nodes = [{ id: 7, name: 'disabled', enable: false }];
|
||||
renderWithProviders(
|
||||
<ConfigProvider theme={{ token: { motion: false } }}>
|
||||
<NodesPage />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button', { name: /^more$/i }));
|
||||
for (const name of ['Restart Xray', 'Restart Panel']) {
|
||||
expect((await screen.findByRole('menuitem', { name })).getAttribute('aria-disabled')).toBe(
|
||||
'true',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user