Skip to content
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

GetUpcomingInvoice for BillingService #12302

Merged
merged 0 commits into from
Aug 25, 2022
Merged

GetUpcomingInvoice for BillingService #12302

merged 0 commits into from
Aug 25, 2022

Conversation

AlexTugarev
Copy link
Member

@AlexTugarev AlexTugarev commented Aug 23, 2022

Description

This PR implements GetLatestInvoice GetUpcomingInvoice. The rename is done intentionally, to a) align with terminology used in stripe, and b) to distinguish between the next invoice and an already paid invoice. The upcoming invoice contains the the amount of credits currently used (🤞🏻 after discounts), which can be compared with the spending limit configured.

  • rename GetLatestInvoice to GetUpcomingInvoice

Related Issue(s)

Fixes #11692

How to test

Setup UBB in for a team and lower the spending limit to 1 or 2 credits for a simple test, then start a workspace or two to hit that limit. After a while, cannot tell it precisely, you'll need to reload the dashboard to refresh the spending limit checks. In the server component you'll find a log message on spending limit events, and the known dashboard notification should be visible:
Screen Shot 2022-08-23 at 16 21 48

Release Notes

NONE

Werft options:

  • /werft with-preview
  • /werft with-payment

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-at-upcoming.8 because the annotations in the pull request description changed
(with .werft/ from main)

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Aug 23, 2022

/werft run

👍 started the job as gitpod-build-at-upcoming.10
(with .werft/ from main)

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-at-upcoming.11 because the annotations in the pull request description changed
(with .werft/ from main)

@roboquat roboquat added size/XXL and removed size/XL labels Aug 23, 2022
@AlexTugarev AlexTugarev changed the title GetUpcomingInvoice GetUpcomingInvoice for BillingService Aug 23, 2022
@AlexTugarev AlexTugarev marked this pull request as ready for review August 24, 2022 06:52
@AlexTugarev AlexTugarev requested a review from a team August 24, 2022 06:52
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Aug 24, 2022
const sessions = response.getSessionsList().map((s) => UsageService.mapBilledSession(s));
return sessions;
async getUpcomingInvoice(teamId: string): Promise<GetUpcomingInvoiceResponse> {
const response = await this.billingServiceClientProvider.getDefault().getUpcomingInvoice(teamId);
Copy link
Member Author

@AlexTugarev AlexTugarev Aug 24, 2022

Choose a reason for hiding this comment

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

WDYT of using attributionId here, and using ParseAttributionID on the side of BillingService? This way, we do not need to make any further changes here once UB is enabled for users.

Copy link
Member

Choose a reason for hiding this comment

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

☝️ Thought about the same. 🧠 ✨ 👍

Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

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

This is a great example where splitting the PR up into the following blocks would greatly help with quality of review:

  1. Proto changes
  2. Implement GetUpcoming rpc
  3. Update Server to use it.

const sessions = response.getSessionsList().map((s) => UsageService.mapBilledSession(s));
return sessions;
async getUpcomingInvoice(teamId: string): Promise<GetUpcomingInvoiceResponse> {
const response = await this.billingServiceClientProvider.getDefault().getUpcomingInvoice(teamId);
Copy link
Member

Choose a reason for hiding this comment

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

When this rolls out, you can't guarantee that when this is executed, the usage component has been rolled out to a newer version and that the getUpcomingInvoice RPC actually exists.

In the happy case, this inconsistency won't happen, but in the bad case, where for example usage fails to start and remains on the old version, it will start failing here.

Copy link
Member

Choose a reason for hiding this comment

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

The way to fix this is to roll-out the RPC first, and only then change the behaviour on server. Alternatively, you can use a feature flag to control this also.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! Let me thinks about where to add the feature flag. First idea is to guard the spending limit check.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I think you can achieve the same thing (with fewer extra pieces) by splitting the PR up and first landing (and deploying) the changes which introduce the RPC on the proto level, but also implement it.

components/usage/pkg/stripe/stripe.go Outdated Show resolved Hide resolved
components/usage/pkg/stripe/stripe.go Outdated Show resolved Hide resolved
components/usage/pkg/stripe/stripe.go Outdated Show resolved Hide resolved
components/usage/pkg/stripe/stripe.go Outdated Show resolved Hide resolved
components/usage/pkg/stripe/stripe_test.go Outdated Show resolved Hide resolved
components/usage/pkg/apiv1/billing.go Outdated Show resolved Hide resolved
@easyCZ easyCZ self-assigned this Aug 24, 2022
@AlexTugarev AlexTugarev merged commit 1cd0fbf into main Aug 25, 2022
@AlexTugarev AlexTugarev deleted the at/upcoming branch August 25, 2022 10:11
@AlexTugarev AlexTugarev restored the at/upcoming branch August 25, 2022 10:12
@AlexTugarev
Copy link
Member Author

GitHub, why? :-(

merged commit 1cd0fbf into main

@AlexTugarev
Copy link
Member Author

Reopened as #12377

@laushinka
Copy link
Contributor

laushinka commented Aug 25, 2022

GitHub, why? :-(

😢

@easyCZ
Copy link
Member

easyCZ commented Aug 25, 2022

How did this PR get merged? I'm really confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/XXL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement BillingService.GetLatestInvoice
5 participants