Skip to content

Commit 70576aa

Browse files
committed
The spending limit is reached
1 parent fcf7402 commit 70576aa

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,26 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20962096
});
20972097
}
20982098

2099+
async getNotifications(ctx: TraceContext): Promise<string[]> {
2100+
const result = await super.getNotifications(ctx);
2101+
const user = this.checkAndBlockUser("getNotifications");
2102+
if (user.usageAttributionId) {
2103+
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId);
2104+
const totalUsage = allSessions.map((s) => s.credits).reduce((a, b) => a + b, 0);
2105+
const costCenter = await this.costCenterDB.findById(user.usageAttributionId);
2106+
if (costCenter) {
2107+
if (totalUsage > costCenter.spendingLimit) {
2108+
result.unshift("The spending limit is reached.");
2109+
} else if (totalUsage > 0.8 * costCenter.spendingLimit * 0.8) {
2110+
result.unshift("The spending limit is almost reached.");
2111+
}
2112+
} else {
2113+
log.warn("No costcenter found.", { userId: user.id, attributionId: user.usageAttributionId });
2114+
}
2115+
}
2116+
return result;
2117+
}
2118+
20992119
async listBilledUsage(ctx: TraceContext, attributionId: string): Promise<BillableSession[]> {
21002120
traceAPIParams(ctx, { attributionId });
21012121
const user = this.checkAndBlockUser("listBilledUsage");

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ import {
108108
} from "@gitpod/gitpod-protocol/lib/team-subscription-protocol";
109109
import { Cancelable } from "@gitpod/gitpod-protocol/lib/util/cancelable";
110110
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";
111-
import {
112-
InterfaceWithTraceContext,
113-
TraceContext,
114-
TraceContextWithSpan,
115-
} from "@gitpod/gitpod-protocol/lib/util/tracing";
111+
import { InterfaceWithTraceContext, TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
116112
import {
117113
IdentifyMessage,
118114
RemoteIdentifyMessage,
@@ -3248,8 +3244,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
32483244
}
32493245
}
32503246

3251-
async getNotifications(ctx: TraceContextWithSpan): Promise<string[]> {
3252-
const user = this.checkAndBlockUser("getNotifications");
3253-
return [`Hi ${user.name}`];
3247+
async getNotifications(ctx: TraceContext): Promise<string[]> {
3248+
this.checkAndBlockUser("getNotifications");
3249+
return [];
32543250
}
32553251
}

0 commit comments

Comments
 (0)