diff --git a/internal/graph/resourceusage.resolvers.go b/internal/graph/resourceusage.resolvers.go index 52eca78e5..b12ac74c0 100644 --- a/internal/graph/resourceusage.resolvers.go +++ b/internal/graph/resourceusage.resolvers.go @@ -21,6 +21,11 @@ func (r *queryResolver) ResourceUtilizationTrendForTeam(ctx context.Context, tea if err != nil { return nil, err } + + if trend == nil { + return &model.ResourceUtilizationTrend{}, nil + } + return trend, nil } @@ -44,7 +49,11 @@ func (r *queryResolver) CurrentResourceUtilizationForApp(ctx context.Context, en // CurrentResourceUtilizationForTeam is the resolver for the currentResourceUtilizationForTeam field. func (r *queryResolver) CurrentResourceUtilizationForTeam(ctx context.Context, team slug.Slug) (*model.CurrentResourceUtilization, error) { resp, err := r.resourceUsageClient.CurrentResourceUtilizationForTeam(ctx, team) - if errors.Is(err, pgx.ErrNoRows) { + if err != nil { + return nil, err + } + + if resp == nil { m := model.ResourceUtilization{ Timestamp: time.Now(), } @@ -52,9 +61,8 @@ func (r *queryResolver) CurrentResourceUtilizationForTeam(ctx context.Context, t CPU: m, Memory: m, }, nil - } else if err != nil { - return nil, err } + return resp, nil } diff --git a/internal/resourceusage/client.go b/internal/resourceusage/client.go index 6a86d2cc9..48223d4fe 100644 --- a/internal/resourceusage/client.go +++ b/internal/resourceusage/client.go @@ -175,7 +175,7 @@ func (c *client) CurrentResourceUtilizationForTeam(ctx context.Context, team slu } if timeRange.To.Time.Before(time.Now().UTC().Add(-3 * time.Hour)) { - return nil, fmt.Errorf("no current data available for team %q", team) + return nil, nil } ts := pgtype.Timestamptz{} @@ -207,6 +207,10 @@ func (c *client) ResourceUtilizationTrendForTeam(ctx context.Context, team slug. return nil, err } + if current == nil { + return nil, nil + } + ts := pgtype.Timestamptz{} err = ts.Scan(current.Timestamp) if err != nil {