-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[usage] Persist credits used for each instance in the usage store #11406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Instance pricing is a usage concern, not just a billing concern.
started the job as gitpod-build-af-persist-credits-used-in-usage-store.1 because the annotations in the pull request description changed |
@@ -247,7 +248,7 @@ func usageReportToUsageRecords(report UsageReport) []db.WorkspaceInstanceUsage { | |||
AttributionID: attributionId, | |||
StartedAt: instance.CreationTime.Time(), | |||
StoppedAt: stoppedAt, | |||
CreditsUsed: 0, | |||
CreditsUsed: float64(pricer.CreditsUsedByInstance(&instance, now)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about the float64: I faintly recall we report credits as ints to stripe, right? If yes, we probably should do the same here, and adjust the DB/gRPC model if they don't agree.
@andrew-farries WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The designs here internal show credits displayed with fractions.
But I think you are right in that we should be consistent in allowing the credits per minute for a workspace class be fractional but always bill and display whole numbers of credits.
I'll update the types in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding was that we have to report total usage to Stripe as an int, but we should collect usage per session in fractional units to avoid rounding errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Really cool to see the piece snap together 🙃
/hold because of float vs int question. We can also do that as a follwo-up 👍
/unhold |
Description
Calculate and persist credits used for each instance in the usage store.
On each usage reconciliation run, we store the reconciled usage in the database. This information should include the number of credits consumed by each instance.
Previously, this value was set to 0 for all instances.
Related Issue(s)
Part of #10323
How to test
Unit tests.
To test manually, run the usage component locally against the database from a preview environment that has had at least one workspace started in it. When the reconciler runs, see that the value for
creditsUsed
is populated in thed_b_workspace_instance_usage
table:Release Notes
Documentation
Werft options: