Skip to content

pkg: add reusable opencost + prom modules for FinOps v2#492

Draft
nadaverell wants to merge 1 commit intomainfrom
feature/finops-v2
Draft

pkg: add reusable opencost + prom modules for FinOps v2#492
nadaverell wants to merge 1 commit intomainfrom
feature/finops-v2

Conversation

@nadaverell
Copy link
Copy Markdown
Contributor

Summary

  • Extracts OpenCost REST + Prometheus discovery paths into pkg/opencost and pkg/prom so koala-backend and skyhook-connector can share the cost math
  • ComputeCostSummary (REST-primary) + ComputeCostSummaryFromProm (PromQL fallback)
  • ComputeCostTrend with coarse default steps (24h→6h, 7d→1d, 30d→2d) to fit CAC's 30s proxy deadline
  • Pod/controller aggregation + namespace post-filter (works around older OpenCost ignoring the REST filter param)
  • Surfaces NetworkCost per row and TotalNetworkCost in the summary
  • Drops OpenCost's synthetic __unallocated__ controller row so child totals don't exceed the parent namespace
  • Window normalization: OpenCost's /allocation.totalCost is summed over the window; we divide by windowHours() so callers can project monthly by multiplying hourly × 730 regardless of the window selected. Regression test pins this.

Tag published: pkg/v1.4.4. Consumed by:

Test plan

  • go test ./opencost/... (includes window-normalization regression)
  • Live verified against OpenCost v1.108 on nonprod-cluster-us-east1: explore rows per namespace, trend buckets, pod/controller drill-down, namespace post-filter

Extracts the OpenCost REST + Prometheus discovery paths from radar's
internal code into reusable packages that koala-backend and
skyhook-connector consume for the FinOps v2 Costs Explorer.

pkg/opencost:
- ComputeCostSummary (REST-primary) + ComputeCostSummaryFromProm (fallback)
- ComputeCostTrend with coarse default steps (24h->6h, 7d->1d, 30d->2d) to
  fit CAC's 30s proxy deadline
- Window-to-hourly normalization: OpenCost's /allocation.totalCost is summed
  over the window, not hourly; we divide by windowHours() so callers can
  project monthly by multiplying by 730 regardless of the window selected
- Pod/controller aggregation via SummaryOptions.Aggregate
- Client-side namespace post-filter (NamespaceFilter) for OpenCost versions
  that silently ignore the REST filter param
- Drops synthetic __unallocated__ rows in controller/pod drills so child
  totals don't exceed the parent namespace
- Surfaces NetworkCost per row + TotalNetworkCost in the summary

pkg/prom:
- Shared Prometheus client + Discover() used by finops capability probe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant