Add workload and application cost tabs#1101
Open
nadaverell wants to merge 12 commits into
Open
Conversation
9fe6e3c to
9cf2aa5
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cdcb372. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds OpenCost-backed cost views at the workload, application, and cluster surfaces covered by this PR:
providerIDis parseable; cluster-level cloud-console links render only for high-confidence GKE/EKS contexts.Application and workload cost use OpenCost/Prometheus historical allocation instead of only projecting from the current hourly rate. They aggregate CPU and memory allocation across supported steady-state workloads, show partial coverage clearly, and let contributor rows drill into the workload-level Cost tab.
What changed
GET /api/opencost/workload/{kind}/{namespace}/{name}GET /api/opencost/workload/{kind}/{namespace}/{name}/trend?range=6h|24h|7dPOST /api/opencost/applicationPOST /api/opencost/application/trendScope notes
Testing
make tscmake testmake buildgo test ./opencostfrompkg/go test ./internal/servernpx tsc --noEmitnpx vitest run web/src/components/cost/format.test.ts web/src/components/cost/ApplicationCostTab.test.ts web/src/components/cost/WorkloadCostTab.test.tsnpx vitest run web/src/components/cost/ApplicationCostTab.test.ts web/src/components/cost/WorkloadCostTab.test.ts packages/k8s-ui/src/components/applications/ApplicationDetail.test.tsxnpx vitest run web/src/components/cost/ApplicationCostTab.test.ts web/src/components/cost/WorkloadCostTab.test.ts web/src/components/cost/cloud-console.test.ts web/src/components/cost/format.test.tsgit diff --checkgke_koalabackend_us-east1-b_nonprod-cluster-us-east1with real OpenCost/Prometheus data:?view=costnormalization to workloadtab=costNote
Medium Risk
Touches Prometheus discovery concurrency, many new cost APIs and PromQL paths, and RBAC-sensitive workload preflight; impact is mostly additive UI and read-only metrics, with regression risk on existing cluster cost queries.
Overview
Adds OpenCost-backed cost at workload, multi-workload application, and cluster surfaces, with monthly-first budget framing and hourly rates kept for splits and tooltips.
Backend: New RBAC-preflighted routes for per-workload current/trend cost and POST application current/trend (batched by namespace, partial coverage for denied/missing/unsupported workloads). PromQL now dedupes duplicate node and PV series, enriches node rows with providerID from the node cache, and attributes workload history via Pod → ReplicaSet → Deployment or direct StatefulSet/DaemonSet owners. Scaled-to-zero workloads return valid zero cost. Prometheus EnsureConnected serializes discovery, caches failed discovery for 5s, and avoids clearing a good connection when a probe is context-canceled.
UI: Optional Cost tab on shared
ApplicationDetail/WorkloadView;ApplicationCostTaband workload cost tabs with stacked trends, contributor drill-down to workloadtab=cost, and a short “looking for Prometheus” grace before hardno_prometheus. React Query hooks add discovery-aware refetch for OpenCost endpoints.Reviewed by Cursor Bugbot for commit b5cc97f. Bugbot is set up for automated code reviews on this repo. Configure here.