Skip to content

Use the actual billing cycle dates in all usage-based Billing pages #14485

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

Merged
merged 3 commits into from
Nov 11, 2022

Conversation

jankeromnes
Copy link
Contributor

@jankeromnes jankeromnes commented Nov 7, 2022

Description

Use the actual billing cycle dates in all usage-based Billing pages

Related Issue(s)

Fixes #14363

How to test

  1. Create a team called "Gitpod [Something]"
    a. this enables usage-based for your user
  2. Go to your personal billing page (/billing)
    a. notice the billing cycle dates (from ~now to ~a month from now)
  3. Upgrade by adding a credit card
    a. notice the new billing cycle dates (from ~now to the last UTC millisecond of the month)

Hint: You can hover on the billing cycle dates to see their exact times.

Release Notes

NONE

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-jx-actual-billing-cycle.1 because the annotations in the pull request description changed
(with .werft/ from main)

@roboquat roboquat added the size/M label Nov 7, 2022
@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch from 28a9896 to e6b8596 Compare November 7, 2022 16:05
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 8, 2022

Insert coin to try again 🎰

/werft run

👍 started the job as gitpod-build-jx-actual-billing-cycle.3
(with .werft/ from main)

@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch from e6b8596 to 9bad6c3 Compare November 8, 2022 10:32
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 8, 2022

Testing

Free Tier After Adding Card After Cancelling
Screenshot 2022-11-08 at 12 00 37 Screenshot 2022-11-08 at 12 01 26 Screenshot 2022-11-08 at 12 00 37

DB state

mysql> select * from d_b_cost_center;
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+
| id                                        | spendingLimit | deleted | _lastModified              | creationTime             | billingStrategy | nextBillingTime          |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+
| team:05b72264-1898-460f-abb2-bc0cc7711756 |             0 |       0 | 2022-11-08 09:51:53.479825 | 2022-11-08T09:51:53.474Z | other           | 2022-12-08T09:51:53.474Z |
| user:d99f1715-3c02-432b-bf5f-4326315b3fd2 |           500 |       0 | 2022-11-08 09:51:53.482185 | 2022-11-08T09:51:53.474Z | other           | 2022-12-08T09:51:53.474Z |
| user:d99f1715-3c02-432b-bf5f-4326315b3fd2 |          1000 |       0 | 2022-11-08 10:01:09.646614 | 2022-11-08T10:01:09.626Z | stripe          |                          |
| user:d99f1715-3c02-432b-bf5f-4326315b3fd2 |           500 |       0 | 2022-11-08 11:00:13.057955 | 2022-11-08T11:00:13.051Z | other           | 2022-12-08T11:00:13.051Z |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+

@jankeromnes jankeromnes marked this pull request as ready for review November 8, 2022 11:11
@jankeromnes jankeromnes requested a review from a team November 8, 2022 11:11
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Nov 8, 2022
Copy link
Member

@svenefftinge svenefftinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add an explicit BillingCycleStart property to cost center. (see comment above)

@jankeromnes
Copy link
Contributor Author

jankeromnes commented Nov 8, 2022

Need an explicit billing cycle start date in cost centers. Back to Draft 📝

@jankeromnes jankeromnes marked this pull request as draft November 8, 2022 13:17
@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch from 9bad6c3 to 4893567 Compare November 8, 2022 16:39
@roboquat roboquat added size/L and removed size/M labels Nov 8, 2022
@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch 6 times, most recently from dc8d8a7 to e8e124c Compare November 9, 2022 14:03
@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch 2 times, most recently from de11def to 7822137 Compare November 10, 2022 20:29
@jankeromnes jankeromnes force-pushed the jx/actual-billing-cycle branch from 7822137 to e65dc3a Compare November 11, 2022 10:18
@jankeromnes jankeromnes marked this pull request as ready for review November 11, 2022 10:43
@jankeromnes jankeromnes requested a review from a team November 11, 2022 10:43
Copy link
Member

@svenefftinge svenefftinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Comments are mostly nits. The only thing we should look into soon is how to update the introduced column on the existing cost centers.

@@ -180,6 +184,7 @@ func (c *CostCenterManager) UpdateCostCenter(ctx context.Context, newCC CostCent
return CostCenter{}, err
}

newCC.BillingCycleStart = NewVarcharTime(now)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little assymmetrical to have the start time but not the end time.
Do we know the end time for stripe as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svenefftinge Good catch. We know the (approximate) end time for Stripe -- it's the last millisecond of the calendar month.

However, I wasn't fully sure of the implications of setting it. Will Gitpod do anything when it reaches a nextBillingTime for a Stripe CostCenter? (This would be problematic, because it's in fact Stripe's responsibility to issue and finalize an invoice, so I think Gitpod shouldn't do anything proactively on the Cost Center and instead wait for Stripe's callback.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we wouldn't do the invoice finalization, of course. But this is clearly communicated through the billingStrategy. I just thought it seems strange that we have a starting time but no end time. One could argue that the start time is managed by stripe as well.

@@ -311,6 +318,9 @@ func (c *CostCenterManager) ResetUsage(ctx context.Context, cc CostCenter) (Cost

now := time.Now().UTC()

// Resetting the usage always resets the billing cycle start time
billingCycleStart := now
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: non-needed variable

@@ -325,11 +335,12 @@ func (c *CostCenterManager) ResetUsage(ctx context.Context, cc CostCenter) (Cost

// All fields on the new cost center remain the same, except for CreationTime and NextBillingTime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the comment is no longer 100% correct

BillingCycleStart := timestamppb.New(c.BillingCycleStart.Time())
if !c.BillingCycleStart.IsSet() {
BillingCycleStart = nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be good to introduce a method that does the conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svenefftinge Good idea. Where should this method live? Is it possible to add it to go.Time or timestamppb somehow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put it into /workspace/gitpod/components/usage/pkg/db/types.go. @easyCZ wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DB package shouldn't have any dependency on API level packages. If we need a conversion, it should be in the API package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@easyCZ So in usage.go is fine? 😇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create apiv1/time.go or apiv1/types.go and put it there. There's nothing wrong with it being in usage.go but it could make it harder to discover that the helper exists. As per go guidance, avoiding files such as util or helper or tools is recommended to avoid kitchen-sink scenarios.

types.go is fairly standard and often used for the underlying types and conversions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the guidance 👍

As per go guidance, avoiding files such as util or helper or tools is recommended to avoid kitchen-sink scenarios.

💯 💯 💯 (love this about Go -- util is one of my pet peeves)

@roboquat roboquat merged commit 0d740fc into main Nov 11, 2022
@roboquat roboquat deleted the jx/actual-billing-cycle branch November 11, 2022 11:32
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Nov 11, 2022
jankeromnes added a commit that referenced this pull request Nov 15, 2022
jankeromnes added a commit that referenced this pull request Nov 15, 2022
jankeromnes added a commit that referenced this pull request Nov 16, 2022
jankeromnes added a commit that referenced this pull request Nov 16, 2022
jankeromnes added a commit that referenced this pull request Nov 16, 2022
roboquat pushed a commit that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UBP] Free tier Balance Used and Usage page do not show correct credits used
4 participants