-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Usage-based] Adjust Stripe usage limits to spec #13746
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
started the job as gitpod-build-jx-adjust-usage-limits.1 because the annotations in the pull request description changed |
3695ea1
to
3a08597
Compare
3a08597
to
a73cbac
Compare
Issue: Immediately after upgrading, the limit shows up wrong. After a refresh it's okay. I guess we need to refresh that state somehow. |
Okay, this now works almost as expected. 🎉 Except for the final step:
(When you cancel, the limit seems to remain unchanged? I think this should be fixed in the CostCenter as part of #13389) |
components/dashboard/src/components/UsageBasedBillingConfig.tsx
Outdated
Show resolved
Hide resolved
components/dashboard/src/components/UsageBasedBillingConfig.tsx
Outdated
Show resolved
Hide resolved
const [newLimit, setNewLimit] = useState<string | undefined>( | ||
props.currentValue ? String(props.currentValue) : undefined, | ||
typeof props.currentValue === "number" ? String(props.currentValue) : undefined, | ||
); |
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.
Why is the limit a string?
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.
That's how the modal code was initially written 🤷 I left it unchanged, but I assume it's because <input>
natively deal with strings (i.e. when you get the value of an input, it's always a string, even if it's of type="number"
).
My personal preference would be to have it a number, and always parse whatever value we get out of the input, but I generally tend not to change existing code based on my sole personal preference. Happy to refactor that bit if you also have a preference for a number state.
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.
LGTM with the exception of step 11 (usage limit does not revert to 500 when you cancel)
I think that's ok for this PR - we have to decide if we will refund or give users the remaining credits.
Thank you @jankeromnes 🙏
/hold for final technical 👍
let limit = 1000; | ||
const attrId = AttributionId.parse(attributionId); | ||
if (attrId?.kind === "team") { | ||
const members = await getGitpodService().server.getTeamMembers(attrId.teamId); | ||
limit = 1000 * members.length; | ||
} | ||
await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId, limit); |
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.
Thinking about this, I think we can shift this to server also.
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.
Thanks! But I moved this out of server and into dashboard at Sven's request, because maybe in the future we'll want to ask users to define or confirm their usage limit while they're upgrading. I think we can leave this as is for 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.
IMO, we should move it. If we'd like to suggest a limit which the user then confirms, we can suggest it in the Intent flow (teamSize * X), and send along with the subscribeToStripe
call for actual persistence. We make the UI unnecessarily complex with the extra logic and introduce more failure modes.
Would like to also understand the context of Sven's request, do you have a link? What held true then, may no longer be the case. In general, the less logic the client side has, the better and given we're not doing the suggestion now .. YAGNI
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.
Hmm, if the code works as is, I'd be keen to merge it as is, then figure out how to improve it in follow-up PRs. Happy to file a follow-up issue for this! 😇
Would like to also understand the context of Sven's request, do you have a link?
YAGNI
Sorry, I can never remember what those acronyms mean, and I'm too lazy to look them up, so I just glaze over them and lose their meaning 😝 (also reminds me of https://acronyms-suck.com 😇)
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.
Follow-up issue is here: #13835
The counterpart PR which adds validation is here #13798 |
Having a look here as well. |
components/dashboard/src/components/UsageBasedBillingConfig.tsx
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
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.
Code LGTM, tested and:
- step 11. does not work (yet) as per this comment
- there are further potential improvements, but those are out of scope IMO
So: ✔️
/hold for this nit.
Before landing this, we'll want to do a rebase to avoid having to do a get after set, and we should also shift more of the logic into server - we want these calls to be "transactional" on the server side, not on the client side (when one fails, we don't want it to fail in the client without the subsequent requests being done and us not having visibility into it) |
Many thanks for the reviews! Briefly taking this back to Draft in order to:
|
eaf0685
to
7e53b57
Compare
…its package you get when subscribed to Stripe as an individual
7e53b57
to
f0b4217
Compare
@geropl Fixed (it's now an
@easyCZ Rebased and now using the new limit returned by I've also uncoupled the Pull Requests again due to https://github.com/gitpod-io/gitpod/pull/13798/files -- happy to pair on that one if you'd like. Maybe it's a missing webhook? I see that the user cost center never goes back to |
Okay, majority of nits addressed, and this works 90% in preview environments (with a chance to work 100% in staging/production if webhooks work there -- in any case this problem pre-dates & is unrelated to this PR). Happy to make any further adjustments as follow-up issues. I'll file these today, but please let me know if you think I forgot anything. /unhold |
async subscribeToStripe( | ||
ctx: TraceContext, | ||
attributionId: string, | ||
setupIntentId: string, | ||
usageLimit: number, | ||
): Promise<number | undefined> { |
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.
FWIW, this API is now super awkward in terms of the response. A consumer wouldn't expect to get a number as a response to subscribeToStripe
. subscribe
should return a Subscription, which can have a property of usageLimit
.
Description
Adjust Stripe usage limits to spec
Related Issue(s)
Part of #13389
Depends on #13798How to test
1000 * team_size
(but you can set it to any value)500
(not editable)1000
, and you should be able to set any value >= 1000 (but not < )500
(not editable)Release Notes
Documentation
Werft options:
If enabled this will build
install/preview
Valid options are
all
,workspace
,webapp
,ide