Cost Attribution
The CostAttributionController at /api/v1/cost-attribution provides cost allocation for shared clusters. Since multiple tenants share infrastructure in FREE and STARTER tiers, costs must be attributed proportionally based on actual resource consumption.
Endpoints
| Method | Path | Description | Auth |
|---|---|---|---|
POST | /cost-attribution/cluster/{clusterName}/attribute | Attribute costs for a cluster | PLATFORM_ADMIN |
POST | /cost-attribution/all/attribute | Attribute costs for all clusters | PLATFORM_ADMIN |
GET | /cost-attribution/tenant/{tenantId}/breakdown | Tenant cost breakdown | ADMIN or tenant access |
GET | /cost-attribution/tenant/{tenantId}/trend | Tenant cost trend | ADMIN or tenant access |
GET | /cost-attribution/cluster/{clusterName}/comparison | Compare tenant costs in cluster | PLATFORM_ADMIN |
Attribution Model
Cost attribution uses a weighted resource usage model:
Tenant Cost = Cluster Cost * (Tenant Resource Weight / Total Resource Weight)
Resource Weight = (CPU Usage * CPU_WEIGHT) +
(Memory Usage * MEMORY_WEIGHT) +
(Storage Usage * STORAGE_WEIGHT) +
(Network Usage * NETWORK_WEIGHT)The weighting factors are configurable per cluster and reflect the relative cost of each resource type.
Attributing Cluster Costs
Platform administrators trigger cost attribution for a specific date:
curl -X POST "http://localhost:8082/api/v1/cost-attribution/cluster/shared-west-us/attribute?date=2026-02-11" \
-H "Authorization: Bearer $ADMIN_TOKEN"Returns a ClusterCostAttribution with per-tenant cost breakdowns.
Attribute All Clusters
curl -X POST "http://localhost:8082/api/v1/cost-attribution/all/attribute?date=2026-02-11" \
-H "Authorization: Bearer $ADMIN_TOKEN"Returns a list of ClusterCostAttribution objects for all shared clusters.
Tenant Cost Breakdown
View cost breakdown for a specific tenant over a date range:
curl "http://localhost:8082/api/v1/cost-attribution/tenant/{tenantId}/breakdown?startDate=2026-02-01&endDate=2026-02-12" \
-H "Authorization: Bearer $TOKEN"Response:
{
"tenantId": "e5f6a7b8-...",
"period": {
"start": "2026-02-01T00:00:00Z",
"end": "2026-02-12T00:00:00Z"
},
"totalCost": 127.50,
"breakdown": {
"compute": 68.30,
"storage": 32.15,
"network": 18.05,
"other": 9.00
},
"dailyCosts": [
{ "date": "2026-02-01", "cost": 11.25 },
{ "date": "2026-02-02", "cost": 10.80 }
]
}Tenant Cost Trend
View cost trend over a configurable number of periods:
curl "http://localhost:8082/api/v1/cost-attribution/tenant/{tenantId}/trend?periods=30" \
-H "Authorization: Bearer $TOKEN"Returns a list of CostTrendPoint objects with daily cost data points, enabling visualization of spending over time.
Cluster Cost Comparison
Compare costs across tenants within a single cluster:
curl "http://localhost:8082/api/v1/cost-attribution/cluster/shared-west-us/comparison?date=2026-02-11" \
-H "Authorization: Bearer $ADMIN_TOKEN"Returns a ClusterCostComparison with per-tenant costs, resource usage percentages, and ranking.
Source Files
| File | Path |
|---|---|
| Controller | control-plane/tenant-service/src/main/java/com/matih/tenant/controller/CostAttributionController.java |
| Service | control-plane/tenant-service/src/main/java/com/matih/tenant/service/cost/SharedClusterCostAttributionService.java |