feat(init): close the OpenCost cost loop — scrape OpenCost + bundle kube-state-metrics#23
Open
mayur-tolexo wants to merge 1 commit into
Open
feat(init): close the OpenCost cost loop — scrape OpenCost + bundle kube-state-metrics#23mayur-tolexo wants to merge 1 commit into
mayur-tolexo wants to merge 1 commit into
Conversation
…ube-state-metrics
OpenCost computes allocation cost by reading metrics BACK from Prometheus: its
own exported pricing metrics (node_total_hourly_cost, ...) plus
kube-state-metrics. The bundled Prometheus scraped only cAdvisor, so OpenCost
had usage but no pricing/capacity metrics and returned zero cost — kubetidy
then fell back to derived pricing ("no cost data returned"). Found on a real
cluster.
- Bundled Prometheus now scrapes OpenCost's /metrics and kube-state-metrics in
addition to kubelet/cAdvisor.
- Bundle a minimal, read-only kube-state-metrics (prefixed kubetidy- so it
never collides with a user's own) alongside the Prometheus stack. Removed by
uninstall --with-prometheus, which still preserves the monitoring namespace.
- Docs: README Tier-2 section, CHANGELOG. Allow ~10–15 min post-install to warm up.
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.
Why (follow-up to #22)
After #22,
init --with-opencostdeploys OpenCost + a bundled Prometheus and the proxy makes both reachable — but on a real cluster OpenCost still reported "no cost data returned" and kubetidy fell back to derived pricing.Root cause: OpenCost computes allocation cost by reading metrics back from Prometheus — its own exported pricing metrics (
node_total_hourly_cost, …) plus kube-state-metrics (node/pod capacity). The bundled Prometheus scraped only cAdvisor, so OpenCost had the usage half but neither the pricing nor the capacity half → zero cost.What this does
Closes the loop so the bundled stack actually produces Tier-2 cost:
/metrics(opencost.opencost.svc:9003), and kube-state-metrics (kubetidy-kube-state-metrics.monitoring.svc:8080). The OpenCost target is simply down until--with-opencostdeploys it — harmless.registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.13.0) alongside the Prometheus stack. All objects are prefixedkubetidy-so they never collide with a user's own KSM, anduninstall --with-prometheusremoves them while still preserving the sharedmonitoringnamespace.Tests
internal/installer/opencost_test.go: object count 7 → 12 (Prometheus 7 + KSM 5); new assertion that the manifest contains the opencost + kube-state-metrics scrape jobs and the bundled KSM image.Full gate green: build, vet, gofmt,
go test ./..., golangci-lint (0 issues).Caveats (honest)
🤖 Generated with Claude Code