Skip to content

Commit

Permalink
fix some cost management stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Dec 20, 2024
1 parent 73e495a commit 42c8c85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions assets/src/components/cost-management/CostManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from './ClusterUsagesTableCols'
import {
CostManagementTreeMap,
nodeCostByCluster,
cpuCostByCluster,
memoryCostByCluster,
} from './CostManagementTreeMap'

Expand Down Expand Up @@ -100,14 +100,14 @@ export function CostManagement() {
content: (
<Flex gap="small">
<CpuIcon />
<OverlineH1 as="h3">node cost by cluster</OverlineH1>
<OverlineH1 as="h3">CPU cost by cluster</OverlineH1>
</Flex>
),
}}
>
<CostManagementTreeMap
colorScheme="blue"
data={nodeCostByCluster(usages)}
data={cpuCostByCluster(usages)}
dataSize={usages.length}
/>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ const WrapperSC = styled.div(({ theme }) => ({
},
}))

export function nodeCostByCluster(usages: ClusterUsageTinyFragment[]) {
export function cpuCostByCluster(usages: ClusterUsageTinyFragment[]) {
const avg =
usages.reduce((acc, usage) => acc + (usage.nodeCost ?? 0), 0) /
usages.length
const projectMap: Record<string, TreeMapData> = {}

for (const usage of usages) {
if (!usage.nodeCost || !usage.cluster?.project) continue
if (!usage.cpuCost || !usage.cluster?.project) continue

const project = usage.cluster.project.name
if (!projectMap[project])
projectMap[project] = { name: project, children: [] }

if (usage.nodeCost / avg > MIN_COST_PERCENTAGE)
if (usage.cpuCost / avg > MIN_COST_PERCENTAGE)
projectMap[project].children?.push({
name: usage.cluster?.name ?? usage.id,
amount: usage.nodeCost,
amount: usage.cpuCost,
})
}

Expand Down

0 comments on commit 42c8c85

Please sign in to comment.