|
1 | 1 | import {
|
2 | 2 | type NodeJson, nodePrefix, makeAKeyByDay, dailyActiveNodesSetByDay,
|
3 |
| - dailyActiveNodesByDay, weeklyActiveNodesByDay, monthlyActiveNodesByDay, weeklyActiveNodesSetByDay, monthlyActiveNodesSetByDay |
| 3 | + dailyActiveNodesByDay, weeklyActiveNodesByDay, monthlyActiveNodesByDay, weeklyActiveNodesSetByDay, monthlyActiveNodesSetByDay, |
| 4 | + nodeServicePrefix |
4 | 5 | } from './redisTypes'
|
5 | 6 | import { impactDashRedisClient, iterateSet } from './RedisClient'
|
6 | 7 |
|
@@ -81,9 +82,18 @@ export const indexSingleNodeReport = async (nodeJson: NodeJson): Promise<void> =
|
81 | 82 | }
|
82 | 83 | }
|
83 | 84 |
|
| 85 | +export interface NodeOrServiceSpecificIndex { |
| 86 | + count: number, |
| 87 | + country: Record<string, number>, |
| 88 | + networks: Record<string, number>, |
| 89 | +} |
| 90 | +export interface NodeSpecificIndex extends NodeOrServiceSpecificIndex { |
| 91 | + services: Record<string, NodeOrServiceSpecificIndex> |
| 92 | +} |
84 | 93 | export interface activeNodesIndex {
|
85 | 94 | count: number
|
86 |
| - specId: Record<string, number> |
| 95 | + // specId: Record<string, number> |
| 96 | + specId: Record<string, NodeSpecificIndex> |
87 | 97 | country: Record<string, number>
|
88 | 98 | [key: string]: unknown // redis req
|
89 | 99 | }
|
@@ -154,18 +164,74 @@ const processNode = (
|
154 | 164 | }
|
155 | 165 |
|
156 | 166 | // if undefined, then the node was removed from the active set and should not be counted in the index
|
| 167 | + // todo: turn specId[<spec-Id>] from count to object |
| 168 | + // {"lastReportedTimestamp":1713596400,"serviceIds":["11d4ef39-2f18-40b7-bf5c-6c50b79aa6f9","334b39d6-27d7-4e09-b11c-0e1388240067"],"specId":"ethereum","country":"CA","lastStartedTimestampMs":1713230898615,"region":"British Columbia","network":"Holesky","specVersion":"1.0.0","userId":"7b7fb34e-d840-467e-afb5-35f3028167e2","city":"Kelowna","lastRunningTimestampMs":1713230930219,"nodeId":"e78d8199-60be-4d18-9dad-a2e2fe6625fd","status":"running"} |
157 | 169 | if (indexToUpdate !== undefined) {
|
158 | 170 | console.log(`Indexing ${nodeId} ${JSON.stringify(node)} to ${JSON.stringify(indexToUpdate)} set`)
|
| 171 | + ///// All nodes level indexes |
159 | 172 | indexToUpdate.count++
|
| 173 | + if (indexToUpdate.country[node.country] === undefined) { |
| 174 | + indexToUpdate.country[node.country] = 0 |
| 175 | + } |
| 176 | + indexToUpdate.country[node.country]++ |
| 177 | + |
| 178 | + ///// Specific Node level indexes |
160 | 179 | if (indexToUpdate.specId[node.specId] === undefined) {
|
161 |
| - indexToUpdate.specId[node.specId] = 1 |
162 |
| - } else { |
163 |
| - indexToUpdate.specId[node.specId]++ |
| 180 | + indexToUpdate.specId[node.specId] = { count: 0, services: {}, country: {}, networks: {} } |
| 181 | + if(node.country) { |
| 182 | + indexToUpdate.specId[node.specId].country[node.country] = 0 |
| 183 | + } |
| 184 | + if(node.network) { |
| 185 | + indexToUpdate.specId[node.specId].networks[node.network] = 0 |
| 186 | + } |
164 | 187 | }
|
165 |
| - if (indexToUpdate.country[node.country] === undefined) { |
166 |
| - indexToUpdate.country[node.country] = 1 |
167 |
| - } else { |
168 |
| - indexToUpdate.country[node.country]++ |
| 188 | + indexToUpdate.specId[node.specId].count++ |
| 189 | + if(node.country) { |
| 190 | + if(indexToUpdate.specId[node.specId].country[node.country] === undefined) { |
| 191 | + indexToUpdate.specId[node.specId].country[node.country] = 0 |
| 192 | + } |
| 193 | + indexToUpdate.specId[node.specId].country[node.country]++ |
| 194 | + } |
| 195 | + if(node.network) { |
| 196 | + if(indexToUpdate.specId[node.specId].networks[node.network] === undefined) { |
| 197 | + indexToUpdate.specId[node.specId].networks[node.network] = 0 |
| 198 | + } |
| 199 | + indexToUpdate.specId[node.specId].networks[node.network]++ |
| 200 | + } |
| 201 | + |
| 202 | + ///// Node.service level indexes |
| 203 | + const servicesIndex = indexToUpdate.specId[node.specId].services; |
| 204 | + // for (const serviceId of node.serviceIds) { |
| 205 | + for (let i=0; i < node.serviceIds.length; i++) { |
| 206 | + const serviceId = node.serviceIds[i] |
| 207 | + const service = await impactDashRedisClient.client.json.get(`${nodeServicePrefix}${serviceId}`) |
| 208 | + if(service === null) { |
| 209 | + throw new Error(`Indexing ${nodeId} service ${serviceId} not found in redis`) |
| 210 | + } |
| 211 | + const serviceSpecId = service.specId |
| 212 | + if (servicesIndex[serviceSpecId] === undefined) { |
| 213 | + servicesIndex[serviceSpecId] = { count: 0, country: {}, networks: {} } |
| 214 | + if(service.country) { |
| 215 | + servicesIndex[serviceSpecId].country[service.country] = 0 |
| 216 | + } |
| 217 | + if(service.network) { |
| 218 | + servicesIndex[serviceSpecId].networks[service.network] = 0 |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + servicesIndex[serviceSpecId].count++ |
| 223 | + if(service.country) { |
| 224 | + if(servicesIndex[serviceSpecId].country[service.country] === undefined) { |
| 225 | + servicesIndex[serviceSpecId].country[service.country] = 0 |
| 226 | + } |
| 227 | + servicesIndex[serviceSpecId].country[service.country]++ |
| 228 | + } |
| 229 | + if(service.network) { |
| 230 | + if(servicesIndex[serviceSpecId].networks[service.network] === undefined) { |
| 231 | + servicesIndex[serviceSpecId].networks[service.network] = 0 |
| 232 | + } |
| 233 | + servicesIndex[serviceSpecId].networks[service.network]++ |
| 234 | + } |
169 | 235 | }
|
170 | 236 | } else {
|
171 | 237 | console.error(`Indexing ${nodeId} indexToUpdate is undefined`)
|
|
0 commit comments