Skip to content

Commit b0d2929

Browse files
author
Laurie T. Malau
committed
add ordering
1 parent f46c742 commit b0d2929

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

components/dashboard/src/teams/TeamUsage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function TeamUsage() {
3232
const timestampStartOfCurrentMonth = startOfCurrentMonth.getTime();
3333
const [startDateOfBillMonth, setStartDateOfBillMonth] = useState(timestampStartOfCurrentMonth);
3434
const [endDateOfBillMonth, setEndDateOfBillMonth] = useState(Date.now());
35+
const [startedTimeOrder] = useState(0); // Descending
3536

3637
useEffect(() => {
3738
if (!team) {
@@ -44,6 +45,7 @@ function TeamUsage() {
4445
attributionId,
4546
startDateOfBillMonth,
4647
endDateOfBillMonth,
48+
startedTimeOrder,
4749
);
4850
setBilledUsage(billedUsageResult);
4951
} catch (error) {
@@ -52,7 +54,7 @@ function TeamUsage() {
5254
}
5355
}
5456
})();
55-
}, [team, startDateOfBillMonth, endDateOfBillMonth]);
57+
}, [team, startDateOfBillMonth, endDateOfBillMonth, startedTimeOrder]);
5658

5759
if (!showUsageBasedPricingUI) {
5860
return <Redirect to="/" />;

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
294294
getSpendingLimitForTeam(teamId: string): Promise<number | undefined>;
295295
setSpendingLimitForTeam(teamId: string, spendingLimit: number): Promise<void>;
296296

297-
listBilledUsage(attributionId: string, from?: number, to?: number): Promise<BillableSession[]>;
297+
listBilledUsage(
298+
attributionId: string,
299+
startedTimeOrder: number,
300+
from?: number,
301+
to?: number,
302+
): Promise<BillableSession[]>;
298303
setUsageAttribution(usageAttribution: string): Promise<void>;
299304

300305
/**
@@ -308,7 +313,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
308313
* Frontend notifications
309314
*/
310315
getNotifications(): Promise<string[]>;
311-
316+
312317
getSupportedWorkspaceClasses(): Promise<SupportedWorkspaceClass[]>;
313318
}
314319

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20802080
const result = await super.getNotifications(ctx);
20812081
const user = this.checkAndBlockUser("getNotifications");
20822082
if (user.usageAttributionId) {
2083-
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId);
2083+
const allSessions = await this.listBilledUsage(ctx, user.usageAttributionId, 0);
20842084
const totalUsage = allSessions.map((s) => s.credits).reduce((a, b) => a + b, 0);
20852085
const costCenter = await this.costCenterDB.findById(user.usageAttributionId);
20862086
if (costCenter) {
@@ -2099,6 +2099,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20992099
async listBilledUsage(
21002100
ctx: TraceContext,
21012101
attributionId: string,
2102+
startedTimeOrder: number,
21022103
from?: number,
21032104
to?: number,
21042105
): Promise<BillableSession[]> {
@@ -2116,7 +2117,13 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21162117
timestampTo = Timestamp.fromDate(new Date(to));
21172118
}
21182119
const usageClient = this.usageServiceClientProvider.getDefault();
2119-
const response = await usageClient.listBilledUsage(ctx, attributionId, timestampFrom, timestampTo);
2120+
const response = await usageClient.listBilledUsage(
2121+
ctx,
2122+
attributionId,
2123+
startedTimeOrder,
2124+
timestampFrom,
2125+
timestampTo,
2126+
);
21202127
const sessions = response.getSessionsList().map((s) => this.mapBilledSession(s));
21212128

21222129
return sessions;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
32103210
async listBilledUsage(
32113211
ctx: TraceContext,
32123212
attributionId: string,
3213+
startedTimeOrder: number,
32133214
from?: number,
32143215
to?: number,
32153216
): Promise<BillableSession[]> {

components/usage-api/typescript/src/usage/v1/sugar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ export class PromisifiedUsageServiceClient {
9191
);
9292
}
9393

94-
public async listBilledUsage(_ctx: TraceContext, attributionId: string, from?: Timestamp, to?: Timestamp): Promise<ListBilledUsageResponse> {
94+
public async listBilledUsage(_ctx: TraceContext, attributionId: string, order: ListBilledUsageRequest.Ordering, from?: Timestamp, to?: Timestamp): Promise<ListBilledUsageResponse> {
9595
const ctx = TraceContext.childContext(`/usage-service/listBilledUsage`, _ctx);
9696

9797
try {
9898
const req = new ListBilledUsageRequest();
9999
req.setAttributionId(attributionId);
100100
req.setFrom(from);
101101
req.setTo(to);
102+
req.setOrder(order);
102103

103104
const response = await new Promise<ListBilledUsageResponse>((resolve, reject) => {
104105
this.client.listBilledUsage(

0 commit comments

Comments
 (0)