diff --git a/components/gitpod-db/go/cost_center.go b/components/gitpod-db/go/cost_center.go index 48596e40ac828e..728bafe481fe87 100644 --- a/components/gitpod-db/go/cost_center.go +++ b/components/gitpod-db/go/cost_center.go @@ -138,7 +138,8 @@ func (c *CostCenterManager) IncrementBillingCycle(ctx context.Context, attributi } now := time.Now().UTC() if cc.NextBillingTime.Time().After(now) { - return CostCenter{}, status.Errorf(codes.FailedPrecondition, "cannot increment billing cycle before next billing time") + log.Infof("Cost center %s is not yet expired. Skipping increment.", attributionId) + return cc, nil } billingCycleStart := NewVarCharTime(now) if cc.NextBillingTime.IsSet() { diff --git a/components/usage/pkg/apiv1/billing.go b/components/usage/pkg/apiv1/billing.go index 98a2ed3bfdcc89..0dbf8fe3c9c6b9 100644 --- a/components/usage/pkg/apiv1/billing.go +++ b/components/usage/pkg/apiv1/billing.go @@ -299,12 +299,13 @@ func (s *BillingService) FinalizeInvoice(ctx context.Context, in *v1.FinalizeInv logger.WithError(err).Errorf("Failed to insert Invoice usage record into the db.") return nil, status.Errorf(codes.Internal, "Failed to insert Invoice into usage records.") } + logger.WithField("usage_id", usage.ID).Infof("Inserted usage record into database for %f credits against %s attribution", usage.CreditCents.ToCredits(), usage.AttributionID) + _, err = s.ccManager.IncrementBillingCycle(ctx, usage.AttributionID) if err != nil { + // we are just logging at this point, so that we don't see the event again as the usage has been recorded. logger.WithError(err).Errorf("Failed to increment billing cycle.") - return nil, status.Errorf(codes.Internal, "Failed to increment billing cycle.") } - logger.WithField("usage_id", usage.ID).Infof("Inserted usage record into database for %f credits against %s attribution", usage.CreditCents.ToCredits(), usage.AttributionID) return &v1.FinalizeInvoiceResponse{}, nil }