Skip to content

Commit

Permalink
fix(stats): fixes mistake in provider stats (#691)
Browse files Browse the repository at this point in the history
refs #645
  • Loading branch information
stalniy authored Jan 21, 2025
1 parent e393532 commit 933cebf
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions apps/api/src/utils/map/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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<T extends StatsEntry>(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]
};
}

Expand Down

0 comments on commit 933cebf

Please sign in to comment.