nais / api

MIT License
1 stars 0 forks source link

Utilization trend when all applications uses more than requested #24

Closed thokra-nav closed 5 months ago

thokra-nav commented 5 months ago

Earlier today, for a team which used more than requested of cpu/memory, the following query would result in an error:

query Overview($team: Slug!) {
  currentResourceUtilizationForTeam(team: $team) {
    cpu {
      utilization
      estimatedAnnualOverageCost
    }
    memory {
      utilization
      estimatedAnnualOverageCost
    }
  }
  resourceUtilizationTrendForTeam(team: $team) {
    cpuUtilizationTrend
    memoryUtilizationTrend
  }
}

Both currentResourceUtilizationForTeam and resourceUtilizationTrendForTeam would fail because of the following query would return no rows:

SELECT
    SUM(usage)::double precision AS usage,
    SUM(request)::double precision AS request,
    timestamp
FROM
    resource_utilization_metrics
WHERE
    team_slug = @team_slug
    AND resource_type = @resource_type
    AND timestamp = @timestamp
    AND request > usage
GROUP BY
    timestamp;

The problem is likely AND request > usage which was added to solve nais/console-backend#40

I made a workaround in 0a5cd996c3d58ebb6eb2f90fe15612d64c83d167 which returns empty data when there's no rows.