Skip to content

Commit

Permalink
fix: Update cost calculations to use direct values and aggregate dail…
Browse files Browse the repository at this point in the history
…y costs
  • Loading branch information
rbjornstad committed Nov 27, 2024
1 parent c4e6736 commit 5a9cc42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/cost/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (client) DailyForTeamEnvironment(ctx context.Context, teamSlug slug.Slug, e

if row.AppLabel != nil {
daily[row.Date].Workloads = append(daily[row.Date].Workloads, &WorkloadCostSample{
Cost: float64(ptr.Deref(row.DailyCost, 0)),
Cost: float64(row.DailyCost),
TeamSlug: teamSlug,
EnvironmentName: environmentName,
WorkloadName: *row.AppLabel,
Expand Down
9 changes: 7 additions & 2 deletions internal/cost/costsql/cost.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion internal/cost/queries/cost.sql
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ SELECT
cost.environment,
cost.team_slug,
cost.app_label,
cost.daily_cost
SUM(cost.daily_cost)::REAL AS daily_cost
FROM
date_range
LEFT OUTER JOIN cost ON cost.date = date_range.date
Expand All @@ -233,6 +233,11 @@ WHERE
environment = @environment::TEXT
AND team_slug = @team_slug::slug
)
GROUP BY
date_range.date,
cost.environment,
cost.team_slug,
cost.app_label
ORDER BY
date_range.date,
cost.app_label ASC
Expand Down

0 comments on commit 5a9cc42

Please sign in to comment.