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

Add spending limit notifications #11556

Merged
merged 2 commits into from
Jul 22, 2022
Merged

Add spending limit notifications #11556

merged 2 commits into from
Jul 22, 2022

Conversation

AlexTugarev
Copy link
Member

@AlexTugarev AlexTugarev commented Jul 22, 2022

Description

This PR add the basic notification to signal reaching of spending limits as described in #11404. The static message is provided by the server API.

Screenshot shows a notification when a spending limit of 1 is reached.

The notification is dismissible, but will reappear on reload until the condition is resolved.

Screen Shot 2022-07-22 at 14 51 36

Related Issue(s)

Relates to #11404

How to test

  • setting up proper refresh rate for usage component
  • setting up a spending limit on a team with billing enabled
  • starting a workspace and waiting for the usage to reach 80% or more
  • reloading the dashboard

Release Notes

Notify when spending limit is reached.

Documentation

Werft options:

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

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Jul 22, 2022

/werft run

👍 started the job as gitpod-build-at-usage-notification.1
(with .werft/ from main)

@AlexTugarev AlexTugarev marked this pull request as ready for review July 22, 2022 13:21
@AlexTugarev AlexTugarev requested a review from a team July 22, 2022 13:21
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jul 22, 2022
async getNotifications(ctx: TraceContext): Promise<string[]> {
const result = await super.getNotifications(ctx);
const user = this.checkAndBlockUser("getNotifications");
if (user.usageAttributionId) {
Copy link
Member

Choose a reason for hiding this comment

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

This has to be replaced by the getBillingMode(user) method. But as it's not there it, this is fine.

const user = this.checkAndBlockUser("getNotifications");
if (user.usageAttributionId) {
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId);
const totalUsage = allSessions.map((s) => s.credits).reduce((a, b) => a + b, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we'd get that from the service as well, but we can replace that once we do.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

LGTM, thank you! 🙏

@roboquat roboquat merged commit 9399771 into main Jul 22, 2022
@roboquat roboquat deleted the at/usage-notification branch July 22, 2022 14:31
@AlexTugarev AlexTugarev restored the at/usage-notification branch July 22, 2022 15:09
@AlexTugarev
Copy link
Member Author

AlexTugarev commented Jul 22, 2022

/werft run

👍 started the job as gitpod-build-at-usage-notification.8
(with .werft/ from main)

@AlexTugarev AlexTugarev deleted the at/usage-notification branch July 22, 2022 15:15
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jul 26, 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 size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants