From 933cebf625cb901bd25bf36b370469aaec48064f Mon Sep 17 00:00:00 2001 From: Serhii Stotskyi Date: Tue, 21 Jan 2025 20:31:56 +0200 Subject: [PATCH] fix(stats): fixes mistake in provider stats (#691) refs #645 --- apps/api/src/utils/map/provider.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/api/src/utils/map/provider.ts b/apps/api/src/utils/map/provider.ts index c9d682383..0697bbbea 100644 --- a/apps/api/src/utils/map/provider.ts +++ b/apps/api/src/utils/map/provider.ts @@ -13,14 +13,14 @@ export const mapProviderToList = ( const isValidSdkVersion = provider.cosmosSdkVersion ? semver.gte(provider.cosmosSdkVersion, "v0.45.9") : false; const name = provider.isOnline ? new URL(provider.hostUri).hostname : null; const gpuModels = getDistinctGpuModelsFromNodes(lastSuccessfulSnapshot?.nodes || []); - const stats: ProviderList['stats'] = { - cpu: buildStatsItem('CPU', lastSuccessfulSnapshot, isValidSdkVersion), - gpu: buildStatsItem('GPU', lastSuccessfulSnapshot, isValidSdkVersion), - memory: buildStatsItem('Memory', lastSuccessfulSnapshot, isValidSdkVersion), + const stats: ProviderList["stats"] = { + cpu: buildStatsItem("CPU", lastSuccessfulSnapshot, isValidSdkVersion), + gpu: buildStatsItem("GPU", lastSuccessfulSnapshot, isValidSdkVersion), + memory: buildStatsItem("Memory", lastSuccessfulSnapshot, isValidSdkVersion), storage: { - ephemeral: buildStatsItem('EphemeralStorage', lastSuccessfulSnapshot, isValidSdkVersion), - persistent: buildStatsItem('PersistentStorage', lastSuccessfulSnapshot, isValidSdkVersion), - }, + ephemeral: buildStatsItem("EphemeralStorage", lastSuccessfulSnapshot, isValidSdkVersion), + persistent: buildStatsItem("PersistentStorage", lastSuccessfulSnapshot, isValidSdkVersion) + } }; return { @@ -42,9 +42,9 @@ export const mapProviderToList = ( ipLat: provider.ipLat, ipLon: provider.ipLon, stats, - activeStats: buildLegacyStatsItem(stats, 'active'), - pendingStats: buildLegacyStatsItem(stats, 'pending'), - availableStats: buildLegacyStatsItem(stats, 'pending'), + activeStats: buildLegacyStatsItem(stats, "active"), + pendingStats: buildLegacyStatsItem(stats, "pending"), + availableStats: buildLegacyStatsItem(stats, "available"), gpuModels: gpuModels, uptime1d: provider.uptime1d, uptime7d: provider.uptime7d, @@ -88,29 +88,29 @@ export const mapProviderToList = ( } as ProviderList; }; -type StatsEntry = 'CPU' | 'GPU' | 'Memory' | 'PersistentStorage' | 'EphemeralStorage'; +type StatsEntry = "CPU" | "GPU" | "Memory" | "PersistentStorage" | "EphemeralStorage"; function buildStatsItem(suffix: T, snapshot: ProviderSnapshot | undefined | null, isValidSdkVersion: boolean): StatsItem { if (!isValidSdkVersion) { return { active: snapshot?.[`active${suffix}`] || 0, available: 0, - pending: 0, + pending: 0 }; } return { active: snapshot?.[`active${suffix}`] || 0, available: snapshot?.[`available${suffix}`] || 0, - pending: snapshot?.[`pending${suffix}`] || 0, + pending: snapshot?.[`pending${suffix}`] || 0 }; } -function buildLegacyStatsItem(stats: ProviderList['stats'], type: keyof StatsItem) { +function buildLegacyStatsItem(stats: ProviderList["stats"], type: keyof StatsItem) { return { cpu: stats.cpu[type], gpu: stats.gpu[type], memory: stats.memory[type], - storage: stats.storage.ephemeral[type] + stats.storage.persistent[type], + storage: stats.storage.ephemeral[type] + stats.storage.persistent[type] }; }