Skip to content

Commit 05c183e

Browse files
committed
[usage] added costcenter nextBillingTime
1 parent 6c669f7 commit 05c183e

File tree

21 files changed

+403
-133
lines changed

21 files changed

+403
-133
lines changed

.werft/jobs/build/installer/installer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ EOF`);
241241
private configureUsage(slice: string) {
242242
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.enabled true`, { slice: slice })
243243
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.schedule 1m`, { slice: slice })
244-
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.billInstancesAfter "2022-08-11T08:05:32.499Z"`, { slice: slice })
244+
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.defaultSpendingLimit['forUsers'] 500`, { slice: slice })
245+
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.defaultSpendingLimit['forTeams'] 0`, { slice: slice })
245246
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.creditsPerMinuteByWorkspaceClass['default'] 0.1666666667`, { slice: slice })
246247
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.creditsPerMinuteByWorkspaceClass['gitpodio-internal-xl'] 0.3333333333`, { slice: slice })
247248
}

components/dashboard/src/components/UsageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
141141
return new Date(time).toLocaleDateString(undefined, options).replace("at ", "");
142142
};
143143

144-
const currentPaginatedResults = usagePage?.usageEntriesList ?? [];
144+
const currentPaginatedResults = usagePage?.usageEntriesList.filter((u) => u.kind === "workspaceinstance") ?? [];
145145

146146
return (
147147
<>
@@ -208,7 +208,7 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
208208
</div>
209209
</div>
210210
{!isLoading &&
211-
(usagePage === undefined || usagePage.usageEntriesList.length === 0) &&
211+
(usagePage === undefined || currentPaginatedResults.length === 0) &&
212212
!errorMessage && (
213213
<div className="flex flex-col w-full mb-8">
214214
<h3 className="text-center text-gray-500 mt-8">No sessions found.</h3>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { columnExists } from "./helper/helper";
9+
10+
const D_B_COST_CENTER = "d_b_cost_center";
11+
const COL_NEXT_BILLING_TIME = "nextBillingTime";
12+
13+
export class CostCenterNextBillingTime1663055856941 implements MigrationInterface {
14+
public async up(queryRunner: QueryRunner): Promise<void> {
15+
if (!(await columnExists(queryRunner, D_B_COST_CENTER, COL_NEXT_BILLING_TIME))) {
16+
await queryRunner.query(
17+
`ALTER TABLE ${D_B_COST_CENTER} ADD COLUMN ${COL_NEXT_BILLING_TIME} varchar(30) NOT NULL, ALGORITHM=INPLACE, LOCK=NONE `,
18+
);
19+
await queryRunner.query(
20+
`ALTER TABLE ${D_B_COST_CENTER} ADD INDEX(${COL_NEXT_BILLING_TIME}), ALGORITHM=INPLACE, LOCK=NONE `,
21+
);
22+
}
23+
}
24+
25+
public async down(queryRunner: QueryRunner): Promise<void> {}
26+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2324,7 +2324,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
23242324
draft: u.draft,
23252325
workspaceInstanceId: u.workspaceInstanceId,
23262326
kind: u.kind === Usage_Kind.KIND_WORKSPACE_INSTANCE ? "workspaceinstance" : "invoice",
2327-
metadata: JSON.parse(u.metadata),
2327+
metadata: !!u.metadata ? JSON.parse(u.metadata) : undefined,
23282328
};
23292329
}),
23302330
pagination: response.pagination

components/usage-api/go/v1/usage.pb.go

Lines changed: 59 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export interface CostCenter {
186186
attributionId: string;
187187
spendingLimit: number;
188188
billingStrategy: CostCenter_BillingStrategy;
189+
/** next_billing_time specifies when the next billing cycle happens. Only set when billing strategy is 'other'. This property is readonly. */
190+
nextBillingTime: Date | undefined;
189191
}
190192

191193
export enum CostCenter_BillingStrategy {
@@ -961,7 +963,12 @@ export const GetCostCenterResponse = {
961963
};
962964

963965
function createBaseCostCenter(): CostCenter {
964-
return { attributionId: "", spendingLimit: 0, billingStrategy: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE };
966+
return {
967+
attributionId: "",
968+
spendingLimit: 0,
969+
billingStrategy: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE,
970+
nextBillingTime: undefined,
971+
};
965972
}
966973

967974
export const CostCenter = {
@@ -975,6 +982,9 @@ export const CostCenter = {
975982
if (message.billingStrategy !== CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE) {
976983
writer.uint32(24).int32(costCenter_BillingStrategyToNumber(message.billingStrategy));
977984
}
985+
if (message.nextBillingTime !== undefined) {
986+
Timestamp.encode(toTimestamp(message.nextBillingTime), writer.uint32(34).fork()).ldelim();
987+
}
978988
return writer;
979989
},
980990

@@ -994,6 +1004,9 @@ export const CostCenter = {
9941004
case 3:
9951005
message.billingStrategy = costCenter_BillingStrategyFromJSON(reader.int32());
9961006
break;
1007+
case 4:
1008+
message.nextBillingTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
1009+
break;
9971010
default:
9981011
reader.skipType(tag & 7);
9991012
break;
@@ -1009,6 +1022,7 @@ export const CostCenter = {
10091022
billingStrategy: isSet(object.billingStrategy)
10101023
? costCenter_BillingStrategyFromJSON(object.billingStrategy)
10111024
: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE,
1025+
nextBillingTime: isSet(object.nextBillingTime) ? fromJsonTimestamp(object.nextBillingTime) : undefined,
10121026
};
10131027
},
10141028

@@ -1018,6 +1032,7 @@ export const CostCenter = {
10181032
message.spendingLimit !== undefined && (obj.spendingLimit = Math.round(message.spendingLimit));
10191033
message.billingStrategy !== undefined &&
10201034
(obj.billingStrategy = costCenter_BillingStrategyToJSON(message.billingStrategy));
1035+
message.nextBillingTime !== undefined && (obj.nextBillingTime = message.nextBillingTime.toISOString());
10211036
return obj;
10221037
},
10231038

@@ -1026,6 +1041,7 @@ export const CostCenter = {
10261041
message.attributionId = object.attributionId ?? "";
10271042
message.spendingLimit = object.spendingLimit ?? 0;
10281043
message.billingStrategy = object.billingStrategy ?? CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE;
1044+
message.nextBillingTime = object.nextBillingTime ?? undefined;
10291045
return message;
10301046
},
10311047
};

components/usage-api/usage/v1/usage.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,7 @@ message CostCenter {
114114
BILLING_STRATEGY_OTHER = 1;
115115
}
116116
BillingStrategy billing_strategy = 3;
117+
118+
// next_billing_time specifies when the next billing cycle happens. Only set when billing strategy is 'other'. This property is readonly.
119+
google.protobuf.Timestamp next_billing_time = 4;
117120
}

components/usage/config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"controllerSchedule": "1h",
3+
"defaultSpendingLimit": {
4+
"forUsers": 5000,
5+
"forTeams": 0
6+
},
37
"creditsPerMinuteByWorkspaceClass": {
48
"default": 0.1666666667,
59
"gitpodio-internal-xl": 0.3333333333
610
},
7-
"billInstancesAfter":"2022-08-11T08:05:32.499Z",
811
"server": {
912
"services": {
1013
"grpc": {

0 commit comments

Comments
 (0)