Skip to content

Commit

Permalink
fix: check if request from db is 0 before dividing
Browse files Browse the repository at this point in the history
  • Loading branch information
rbjornstad committed Jul 5, 2024
1 parent 40c4751 commit fbec99b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/database/gensql/resourceusage.sql.go

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

4 changes: 2 additions & 2 deletions internal/database/queries/resourceusage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ ORDER BY
-- ResourceUtilizationForTeam will return resource utilization records for a given team.
-- name: ResourceUtilizationForTeam :many
SELECT
COALESCE(SUM(usage),0)::double precision AS usage,
COALESCE(SUM(request),0)::double precision AS request,
SUM(usage)::double precision AS usage,
SUM(request)::double precision AS request,
timestamp
FROM
resource_utilization_metrics
Expand Down
3 changes: 3 additions & 0 deletions internal/resourceusage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func (c *client) ResourceUtilizationTrendForTeam(ctx context.Context, team slug.
if err != nil {
return nil, err
}
if cpuAverage.Request == 0 || memoryAverage.Request == 0 {
return nil, nil
}

averageCpuUtilization := cpuAverage.Usage / cpuAverage.Request * 100
averageMemoryUtilization := memoryAverage.Usage / memoryAverage.Request * 100
Expand Down

0 comments on commit fbec99b

Please sign in to comment.