|
| 1 | +import {EFlag} from '../../types/api/enums'; |
| 2 | +import type { |
| 3 | + TEndpoint, |
| 4 | + TNodeInfo, |
| 5 | + TNodesInfo, |
| 6 | + TPoolStats, |
| 7 | + TSystemStateInfo, |
| 8 | +} from '../../types/api/nodes'; |
| 9 | +import {TPDiskState} from '../../types/api/pdisk'; |
| 10 | +import {EVDiskState} from '../../types/api/vdisk'; |
| 11 | + |
| 12 | +// Different disk sizes to simulate variety (in bytes) |
| 13 | +const DISK_SIZES = [ |
| 14 | + '68719476736', // 64 GB |
| 15 | + '137438953472', // 128 GB |
| 16 | + '274877906944', // 256 GB |
| 17 | + '549755813888', // 512 GB |
| 18 | + '1099511627776', // 1 TB |
| 19 | +]; |
| 20 | + |
| 21 | +const getRandomDiskSize = () => DISK_SIZES[Math.floor(Math.random() * DISK_SIZES.length)]; |
| 22 | + |
| 23 | +const generatePoolStats = (count = 5): TPoolStats[] => { |
| 24 | + const poolNames = ['System', 'User', 'Batch', 'IO', 'IC'] as const; |
| 25 | + return poolNames.slice(0, count).map((Name) => ({ |
| 26 | + Name, |
| 27 | + Usage: Math.random() * 0.02, |
| 28 | + Threads: Math.floor(Math.random() * 3) + 1, |
| 29 | + })); |
| 30 | +}; |
| 31 | + |
| 32 | +const generateEndpoints = (): TEndpoint[] => [ |
| 33 | + {Name: 'ic', Address: ':19001'}, |
| 34 | + {Name: 'http-mon', Address: ':8765'}, |
| 35 | + {Name: 'grpcs', Address: ':2135'}, |
| 36 | + {Name: 'grpc', Address: ':2136'}, |
| 37 | +]; |
| 38 | + |
| 39 | +const generateSystemState = (nodeId: number): TSystemStateInfo => ({ |
| 40 | + StartTime: '1734358137851', |
| 41 | + ChangeTime: '1734358421375', |
| 42 | + LoadAverage: [3.381347656, 2.489257813, 1.279296875], |
| 43 | + NumberOfCpus: 8, |
| 44 | + SystemState: EFlag.Green, |
| 45 | + NodeId: nodeId, |
| 46 | + Host: `localhost-${nodeId}`, |
| 47 | + Version: 'main.95ce0df', |
| 48 | + PoolStats: generatePoolStats(), |
| 49 | + Endpoints: generateEndpoints(), |
| 50 | + Roles: ['Bootstrapper', 'StateStorage', 'StateStorageBoard', 'SchemeBoard', 'Storage'], |
| 51 | + MemoryLimit: '2147483648', |
| 52 | + MaxDiskUsage: 0.002349853516, |
| 53 | + Location: { |
| 54 | + DataCenter: '1', |
| 55 | + Rack: '1', |
| 56 | + Unit: '1', |
| 57 | + }, |
| 58 | + TotalSessions: 0, |
| 59 | + CoresUsed: 0.07583969556, |
| 60 | + CoresTotal: 8, |
| 61 | +}); |
| 62 | + |
| 63 | +const generatePDisk = (nodeId: number, pdiskId: number, totalSize = '68719476736') => ({ |
| 64 | + PDiskId: pdiskId, |
| 65 | + ChangeTime: '1734358142074', |
| 66 | + Path: `/ydb_data/pdisk${pdiskId}l3ki78no.data`, |
| 67 | + Guid: pdiskId.toString(), |
| 68 | + Category: '0', |
| 69 | + TotalSize: totalSize, |
| 70 | + AvailableSize: (Number(totalSize) * 0.9).toString(), // 90% available by default |
| 71 | + State: TPDiskState.Normal, |
| 72 | + NodeId: nodeId, |
| 73 | + Device: EFlag.Green, |
| 74 | + Realtime: EFlag.Green, |
| 75 | + SerialNumber: '', |
| 76 | + SystemSize: '213909504', |
| 77 | + LogUsedSize: '35651584', |
| 78 | + LogTotalSize: '68486692864', |
| 79 | + EnforcedDynamicSlotSize: '22817013760', |
| 80 | +}); |
| 81 | + |
| 82 | +const generateVDisk = (nodeId: number, vdiskId: number, pdiskId: number) => ({ |
| 83 | + VDiskId: { |
| 84 | + GroupID: vdiskId, |
| 85 | + GroupGeneration: 1, |
| 86 | + Ring: 0, |
| 87 | + Domain: 0, |
| 88 | + VDisk: 0, |
| 89 | + }, |
| 90 | + ChangeTime: '1734358420919', |
| 91 | + PDiskId: pdiskId, |
| 92 | + VDiskSlotId: vdiskId, |
| 93 | + Guid: '1', |
| 94 | + Kind: '0', |
| 95 | + NodeId: nodeId, |
| 96 | + VDiskState: EVDiskState.OK, |
| 97 | + DiskSpace: EFlag.Green, |
| 98 | + SatisfactionRank: { |
| 99 | + FreshRank: { |
| 100 | + Flag: EFlag.Green, |
| 101 | + }, |
| 102 | + LevelRank: { |
| 103 | + Flag: EFlag.Green, |
| 104 | + }, |
| 105 | + }, |
| 106 | + Replicated: true, |
| 107 | + ReplicationProgress: 1, |
| 108 | + ReplicationSecondsRemaining: 0, |
| 109 | + AllocatedSize: '0', |
| 110 | + AvailableSize: '22817013760', |
| 111 | + HasUnreadableBlobs: false, |
| 112 | + IncarnationGuid: '11528832187803248876', |
| 113 | + InstanceGuid: '14836434871903384493', |
| 114 | + FrontQueues: EFlag.Green, |
| 115 | + StoragePoolName: 'static', |
| 116 | + ReadThroughput: '0', |
| 117 | + WriteThroughput: '420', |
| 118 | +}); |
| 119 | + |
| 120 | +interface NodeGeneratorOptions { |
| 121 | + vdisksCount?: number; |
| 122 | + pdisksCount?: number; |
| 123 | +} |
| 124 | + |
| 125 | +const DEFAULT_OPTIONS: NodeGeneratorOptions = { |
| 126 | + vdisksCount: 12, |
| 127 | + pdisksCount: 4, |
| 128 | +}; |
| 129 | + |
| 130 | +const generateNode = (nodeId: number, options: NodeGeneratorOptions = {}): TNodeInfo => { |
| 131 | + const pdisksCount = options.pdisksCount ?? DEFAULT_OPTIONS.pdisksCount; |
| 132 | + const vdisksCount = options.vdisksCount ?? DEFAULT_OPTIONS.vdisksCount; |
| 133 | + |
| 134 | + return { |
| 135 | + NodeId: nodeId, |
| 136 | + UptimeSeconds: 284, |
| 137 | + CpuUsage: 0.00947996, |
| 138 | + DiskSpaceUsage: 0.234985, |
| 139 | + SystemState: generateSystemState(nodeId), |
| 140 | + PDisks: Array.from({length: pdisksCount!}, (_, i) => |
| 141 | + generatePDisk(nodeId, i + 1, getRandomDiskSize()), |
| 142 | + ), |
| 143 | + VDisks: Array.from({length: vdisksCount!}, (_, i) => { |
| 144 | + // Distribute VDisks evenly across PDisks |
| 145 | + const pdiskId = (i % pdisksCount!) + 1; |
| 146 | + return generateVDisk(nodeId, i, pdiskId); |
| 147 | + }), |
| 148 | + }; |
| 149 | +}; |
| 150 | + |
| 151 | +export const generateNodes = (count = 1, options?: NodeGeneratorOptions): TNodesInfo => { |
| 152 | + const nodes = Array.from({length: count}, (_, i) => generateNode(i + 1, options)); |
| 153 | + return { |
| 154 | + TotalNodes: count.toString(), |
| 155 | + FoundNodes: count.toString(), |
| 156 | + Nodes: nodes, |
| 157 | + }; |
| 158 | +}; |
0 commit comments