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

[usage] Cost centers get nextBillingTime #12913

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .werft/jobs/build/installer/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ EOF`);
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.enabled true`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.schedule 1m`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.billInstancesAfter "2022-08-11T08:05:32.499Z"`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.defaultSpendingLimit.forUsers 500`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.defaultSpendingLimit.forTeams 0`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.creditsPerMinuteByWorkspaceClass['default'] 0.1666666667`, { slice: slice })
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.usage.creditsPerMinuteByWorkspaceClass['gitpodio-internal-xl'] 0.3333333333`, { slice: slice })
}
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/src/components/UsageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
return new Date(time).toLocaleDateString(undefined, options).replace("at ", "");
};

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

return (
<>
Expand Down Expand Up @@ -208,7 +208,7 @@ function UsageView({ attributionId, billingMode }: UsageViewProps) {
</div>
</div>
{!isLoading &&
(usagePage === undefined || usagePage.usageEntriesList.length === 0) &&
(usagePage === undefined || currentPaginatedResults.length === 0) &&
!errorMessage && (
<div className="flex flex-col w-full mb-8">
<h3 className="text-center text-gray-500 mt-8">No sessions found.</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { MigrationInterface, QueryRunner } from "typeorm";
import { columnExists } from "./helper/helper";

const D_B_COST_CENTER = "d_b_cost_center";
const COL_NEXT_BILLING_TIME = "nextBillingTime";

export class CostCenterNextBillingTime1663055856941 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, D_B_COST_CENTER, COL_NEXT_BILLING_TIME))) {
await queryRunner.query(
`ALTER TABLE ${D_B_COST_CENTER} ADD COLUMN ${COL_NEXT_BILLING_TIME} varchar(30) NOT NULL, ALGORITHM=INPLACE, LOCK=NONE `,
);
await queryRunner.query(
`ALTER TABLE ${D_B_COST_CENTER} ADD INDEX(${COL_NEXT_BILLING_TIME}), ALGORITHM=INPLACE, LOCK=NONE `,
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {}
}
2 changes: 1 addition & 1 deletion components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
draft: u.draft,
workspaceInstanceId: u.workspaceInstanceId,
kind: u.kind === Usage_Kind.KIND_WORKSPACE_INSTANCE ? "workspaceinstance" : "invoice",
metadata: JSON.parse(u.metadata),
metadata: !!u.metadata ? JSON.parse(u.metadata) : undefined,
};
}),
pagination: response.pagination
Expand Down
104 changes: 59 additions & 45 deletions components/usage-api/go/v1/usage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion components/usage-api/typescript/src/usage/v1/usage.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export interface CostCenter {
attributionId: string;
spendingLimit: number;
billingStrategy: CostCenter_BillingStrategy;
/** next_billing_time specifies when the next billing cycle happens. Only set when billing strategy is 'other'. This property is readonly. */
nextBillingTime: Date | undefined;
}

export enum CostCenter_BillingStrategy {
Expand Down Expand Up @@ -961,7 +963,12 @@ export const GetCostCenterResponse = {
};

function createBaseCostCenter(): CostCenter {
return { attributionId: "", spendingLimit: 0, billingStrategy: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE };
return {
attributionId: "",
spendingLimit: 0,
billingStrategy: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE,
nextBillingTime: undefined,
};
}

export const CostCenter = {
Expand All @@ -975,6 +982,9 @@ export const CostCenter = {
if (message.billingStrategy !== CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE) {
writer.uint32(24).int32(costCenter_BillingStrategyToNumber(message.billingStrategy));
}
if (message.nextBillingTime !== undefined) {
Timestamp.encode(toTimestamp(message.nextBillingTime), writer.uint32(34).fork()).ldelim();
}
return writer;
},

Expand All @@ -994,6 +1004,9 @@ export const CostCenter = {
case 3:
message.billingStrategy = costCenter_BillingStrategyFromJSON(reader.int32());
break;
case 4:
message.nextBillingTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -1009,6 +1022,7 @@ export const CostCenter = {
billingStrategy: isSet(object.billingStrategy)
? costCenter_BillingStrategyFromJSON(object.billingStrategy)
: CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE,
nextBillingTime: isSet(object.nextBillingTime) ? fromJsonTimestamp(object.nextBillingTime) : undefined,
};
},

Expand All @@ -1018,6 +1032,7 @@ export const CostCenter = {
message.spendingLimit !== undefined && (obj.spendingLimit = Math.round(message.spendingLimit));
message.billingStrategy !== undefined &&
(obj.billingStrategy = costCenter_BillingStrategyToJSON(message.billingStrategy));
message.nextBillingTime !== undefined && (obj.nextBillingTime = message.nextBillingTime.toISOString());
return obj;
},

Expand All @@ -1026,6 +1041,7 @@ export const CostCenter = {
message.attributionId = object.attributionId ?? "";
message.spendingLimit = object.spendingLimit ?? 0;
message.billingStrategy = object.billingStrategy ?? CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE;
message.nextBillingTime = object.nextBillingTime ?? undefined;
return message;
},
};
Expand Down
3 changes: 3 additions & 0 deletions components/usage-api/usage/v1/usage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ message CostCenter {
BILLING_STRATEGY_OTHER = 1;
}
BillingStrategy billing_strategy = 3;

// next_billing_time specifies when the next billing cycle happens. Only set when billing strategy is 'other'. This property is readonly.
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of proto comments to describe semantics!

google.protobuf.Timestamp next_billing_time = 4;
}
5 changes: 4 additions & 1 deletion components/usage/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"controllerSchedule": "1h",
"defaultSpendingLimit": {
"forUsers": 5000,
"forTeams": 0
},
"creditsPerMinuteByWorkspaceClass": {
"default": 0.1666666667,
"gitpodio-internal-xl": 0.3333333333
},
"billInstancesAfter":"2022-08-11T08:05:32.499Z",
"server": {
"services": {
"grpc": {
Expand Down
Loading