Is your feature request related to a problem? Please describe.
The spec describes network and load balancer costs as usage based, but the implementation prices LBs at a flat hourly rate and that's it.
From spec/opencost-specv01.md:
Resource Usage Costs accumulate on a per-unit basis (e.g. cost per byte egressed)
Load balancers ... amount = bytes ingressed
Amount of ingress or egress across zones, regions, or the wide internet measured in bytes or gigabytes
What the code actually does today (allocation_helpers.go#L1661-L1670):
lb.TotalCost += lbPricePerHr * resultHours * scaleFactor
getLoadBalancerCosts only consumes QueryLBPricePerHr and QueryLBActiveMinutes, so there is no bytes or connections dimension anywhere in the LB path. Same flat math on the assets side in cluster.go#L604-L623.
The practical fallout is that anyone not on a big cloud gets nothing useful here: #2871 (bare metal + MetalLB, closed without a fix), #3287 (network cost calculation broken without the external network-costs component), #2411 (LB coverage gaps), and #3949 is asking for richer network pricing topology right now. Network costs have repeatedly come up as one of the most requested capabilities.
Describe the solution you'd like
Nothing is decided here, this is a proposal I am floating for community discussion. It is scoped so it could run well as an LFX mentorship if a maintainer wants to take it on, but the point right now is to get feedback on the direction. It would land in three phases, and the building blocks already exist:
Proposed work items for the mentorship:
| Complete |
Work Item |
Data Source / Query |
Area |
Description |
Difficulty |
|
LB usage pricing config schema |
N/A |
pkg/cloud/models, configs/ |
Add per-GiB (and optional per-connection) LB rates to custom pricing config, alongside the existing ZoneNetworkEgress style rates. Documented defaults, no behavior change when unset |
Low |
|
LB bytes query |
container_network_receive_bytes_total / container_network_transmit_bytes_total (service endpoint attribution) or MetalLB speaker metrics |
core/pkg/source |
New datasource query attributing traffic bytes to LB backed services, following the QueryNetZoneGiB pattern |
Medium |
|
Usage component in LB cost math |
output of the above |
pkg/costmodel |
Extend getLoadBalancerCosts and the assets path so LB cost = hourly rate x hours + bytes x per-GiB rate (+ connections x rate), behind a flag, default off |
Medium |
|
Metric export |
kubecost_load_balancer_cost (+ usage component) |
pkg/metrics |
Expose the usage based component so dashboards and the integration harness can see it |
Low |
|
Unit tests for cost math |
N/A |
pkg/costmodel |
Flag on/off, zero usage, missing metrics fallback to flat rate, config validation |
Low |
|
Ground truth network bytes test |
container_network_receive_bytes_total / container_network_transmit_bytes_total |
opencost-integration-tests |
Implement opencost/opencost-integration-tests#93: reported allocation bytes vs known ground truth |
Low |
|
Network costs without external component |
existing egress queries |
pkg/costmodel |
Close the gap described in #3287 so basic network costing works without the external network-costs daemonset where the metrics allow it |
High |
|
Zone/region/internet split validation |
QueryNetZoneGiB / QueryNetRegionGiB / QueryNetInternetGiB |
opencost-integration-tests |
Verify the split and the per-GiB rates against config on the test cluster (pairs with the cross-region iperf work already in progress) |
Medium |
|
AWS LB usage pricing |
AWS pricing API (LCU model for ALB/NLB) |
pkg/cloud/aws |
Map bytes + connections to LCU dimensions so cloud LB costs reflect usage, not just hours |
High |
|
GCP LB usage pricing |
GCP billing API (forwarding rules + data processing per GiB) |
pkg/cloud/gcp |
Same, using the existing billing API plumbing |
Medium |
|
Azure LB usage pricing |
Azure retail prices API (LB rules + data processed) |
pkg/cloud/azure |
Same, using the existing retail price plumbing |
Medium |
|
Docs + spec conformance note |
N/A |
opencost.io docs, spec/ |
Document the new config, flag, and how the implementation now matches the spec language above |
Low |
Expected outcome
- Usage based LB costing (bytes, optionally connections) available in OSS core behind a flag, so bare metal / MetalLB users get real LB costs instead of nothing
- Cloud LB usage pricing for at least AWS, ideally GCP and Azure
- Ground truth network/LB tests green in the integration harness (building on the merged LB cost test and the open network test)
- Docs and spec conformance updated
Recommended skills
Go, Kubernetes, Prometheus/PromQL, and some familiarity with cloud billing models (AWS LCU pricing especially). Nothing here requires prior OpenCost internals knowledge that can't be picked up in the first weeks.
If it runs as a mentorship
Not scheduled, and not confirmed. @ameijer mentioned it could be a fit for LFX Term 3 if a maintainer is available to run it. If that happens, a rough shape would be weeks 1 to 4 bare metal LB slice, weeks 5 to 8 network costing hardening + tests, weeks 9 to 12 cloud LB pricing + docs. Either way the work items above stand on their own as community contributions.
Additional context
This came out of discussion with @ameijer about LFX Term 3, and is the detailed version of scoping notes shared there. Open questions where community input would help:
- bare metal first (where users currently get nothing) or cloud LB pricing first (bigger install base)?
- config surface: custom pricing json vs env vars?
- best source for LB bytes on bare metal: service pod
container_network_* metrics, or MetalLB speaker metrics?
Happy to do a walkthrough at a community meeting. cc @Manas23601 since the test work this builds on is yours.
Is your feature request related to a problem? Please describe.
The spec describes network and load balancer costs as usage based, but the implementation prices LBs at a flat hourly rate and that's it.
From spec/opencost-specv01.md:
What the code actually does today (allocation_helpers.go#L1661-L1670):
getLoadBalancerCostsonly consumesQueryLBPricePerHrandQueryLBActiveMinutes, so there is no bytes or connections dimension anywhere in the LB path. Same flat math on the assets side in cluster.go#L604-L623.The practical fallout is that anyone not on a big cloud gets nothing useful here: #2871 (bare metal + MetalLB, closed without a fix), #3287 (network cost calculation broken without the external network-costs component), #2411 (LB coverage gaps), and #3949 is asking for richer network pricing topology right now. Network costs have repeatedly come up as one of the most requested capabilities.
Describe the solution you'd like
Nothing is decided here, this is a proposal I am floating for community discussion. It is scoped so it could run well as an LFX mentorship if a maintainer wants to take it on, but the point right now is to get feedback on the direction. It would land in three phases, and the building blocks already exist:
QueryNetZoneGiB/QueryNetRegionGiB/QueryNetInternetGiBin datasource.go#L385-L389, consumed in allocation.go#L318-L321. Today those bytes are just multiplied by static per-GiB rates from provider config.Proposed work items for the mentorship:
pkg/cloud/models,configs/ZoneNetworkEgressstyle rates. Documented defaults, no behavior change when unsetcontainer_network_receive_bytes_total/container_network_transmit_bytes_total(service endpoint attribution) or MetalLB speaker metricscore/pkg/sourceQueryNetZoneGiBpatternpkg/costmodelgetLoadBalancerCostsand the assets path so LB cost = hourly rate x hours + bytes x per-GiB rate (+ connections x rate), behind a flag, default offkubecost_load_balancer_cost(+ usage component)pkg/metricspkg/costmodelcontainer_network_receive_bytes_total/container_network_transmit_bytes_totalpkg/costmodelQueryNetZoneGiB/QueryNetRegionGiB/QueryNetInternetGiBpkg/cloud/awspkg/cloud/gcppkg/cloud/azurespec/Expected outcome
Recommended skills
Go, Kubernetes, Prometheus/PromQL, and some familiarity with cloud billing models (AWS LCU pricing especially). Nothing here requires prior OpenCost internals knowledge that can't be picked up in the first weeks.
If it runs as a mentorship
Not scheduled, and not confirmed. @ameijer mentioned it could be a fit for LFX Term 3 if a maintainer is available to run it. If that happens, a rough shape would be weeks 1 to 4 bare metal LB slice, weeks 5 to 8 network costing hardening + tests, weeks 9 to 12 cloud LB pricing + docs. Either way the work items above stand on their own as community contributions.
Additional context
This came out of discussion with @ameijer about LFX Term 3, and is the detailed version of scoping notes shared there. Open questions where community input would help:
container_network_*metrics, or MetalLB speaker metrics?Happy to do a walkthrough at a community meeting. cc @Manas23601 since the test work this builds on is yours.