From b8fd5967eefe7e2331f247e9d459d57d0ec32b88 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Tue, 23 Aug 2022 07:48:37 +0000 Subject: [PATCH] regenerate usage-api --- .../server/src/workspace/workspace-starter.ts | 19 +- components/usage-api/go/v1/billing.pb.go | 186 ++++++++++++------ .../typescript/src/usage/v1/billing_pb.d.ts | 12 +- .../typescript/src/usage/v1/billing_pb.js | 28 ++- .../typescript/src/usage/v1/sugar.ts | 24 +-- components/usage-api/usage/v1/billing.proto | 6 +- components/usage/pkg/db/billed_session.go | 18 +- 7 files changed, 192 insertions(+), 101 deletions(-) diff --git a/components/server/src/workspace/workspace-starter.ts b/components/server/src/workspace/workspace-starter.ts index c6e13948ec3d90..fb1aeb6a196dc4 100644 --- a/components/server/src/workspace/workspace-starter.ts +++ b/components/server/src/workspace/workspace-starter.ts @@ -124,6 +124,7 @@ import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution"; import { CachingBillingServiceClientProvider } from "@gitpod/usage-api/lib/usage/v1/sugar"; import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb"; import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode"; +import { System } from "@gitpod/usage-api/lib/usage/v1/billing_pb"; export interface StartWorkspaceOptions { rethrow?: boolean; @@ -545,7 +546,7 @@ export class WorkspaceStarter { const billingMode = await this.billingModes.getBillingMode(parsedAttributionId, creationTime); if (billingMode && billingMode.mode === "chargebee") { const billingClient = this.billingServiceClientProvider.getDefault(); - await billingClient.setBilledSession(instance.id, timestamped, "chargebee"); + await billingClient.setBilledSession(instance.id, timestamped, System.SYSTEM_CHARGEBEE); } } } @@ -1435,17 +1436,23 @@ export class WorkspaceStarter { } } - let volumeSnapshotId = "" + let volumeSnapshotId = ""; // always pick lastValidWorkspaceInstanceId if it is valid, otherwise workspace will be restored from prebuild // even if there was workspace backup available if (lastValidWorkspaceInstanceId != "") { - volumeSnapshotId = lastValidWorkspaceInstanceId - } else if ((SnapshotContext.is(workspace.context) || WithPrebuild.is(workspace.context)) && !!workspace.context.snapshotBucketId) { - volumeSnapshotId = workspace.context.snapshotBucketId + volumeSnapshotId = lastValidWorkspaceInstanceId; + } else if ( + (SnapshotContext.is(workspace.context) || WithPrebuild.is(workspace.context)) && + !!workspace.context.snapshotBucketId + ) { + volumeSnapshotId = workspace.context.snapshotBucketId; } let volumeSnapshotInfo = new VolumeSnapshotInfo(); - const volumeSnapshots = volumeSnapshotId != "" ? await this.workspaceDb.trace(traceCtx).findVolumeSnapshotById(volumeSnapshotId) : undefined; + const volumeSnapshots = + volumeSnapshotId != "" + ? await this.workspaceDb.trace(traceCtx).findVolumeSnapshotById(volumeSnapshotId) + : undefined; if (volumeSnapshots !== undefined) { log.info("starting workspace with volume snapshot info", { lastInstanceId: lastValidWorkspaceInstanceId, diff --git a/components/usage-api/go/v1/billing.pb.go b/components/usage-api/go/v1/billing.pb.go index 822cf9e2b7514c..2005e39075e3ad 100644 --- a/components/usage-api/go/v1/billing.pb.go +++ b/components/usage-api/go/v1/billing.pb.go @@ -25,6 +25,55 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type System int32 + +const ( + System_SYSTEM_UNKNOWN System = 0 + System_SYSTEM_CHARGEBEE System = 1 + System_SYSTEM_STRIPE System = 2 +) + +// Enum value maps for System. +var ( + System_name = map[int32]string{ + 0: "SYSTEM_UNKNOWN", + 1: "SYSTEM_CHARGEBEE", + 2: "SYSTEM_STRIPE", + } + System_value = map[string]int32{ + "SYSTEM_UNKNOWN": 0, + "SYSTEM_CHARGEBEE": 1, + "SYSTEM_STRIPE": 2, + } +) + +func (x System) Enum() *System { + p := new(System) + *p = x + return p +} + +func (x System) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (System) Descriptor() protoreflect.EnumDescriptor { + return file_usage_v1_billing_proto_enumTypes[0].Descriptor() +} + +func (System) Type() protoreflect.EnumType { + return &file_usage_v1_billing_proto_enumTypes[0] +} + +func (x System) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use System.Descriptor instead. +func (System) EnumDescriptor() ([]byte, []int) { + return file_usage_v1_billing_proto_rawDescGZIP(), []int{0} +} + type UpdateInvoicesRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -132,6 +181,7 @@ type GetLatestInvoiceRequest struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Identifier: + // // *GetLatestInvoiceRequest_TeamId // *GetLatestInvoiceRequest_UserId Identifier isGetLatestInvoiceRequest_Identifier `protobuf_oneof:"identifier"` @@ -363,7 +413,7 @@ type SetBilledSessionRequest struct { InstanceId string `protobuf:"bytes,1,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"` From *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=from,proto3" json:"from,omitempty"` - System string `protobuf:"bytes,3,opt,name=system,proto3" json:"system,omitempty"` + System System `protobuf:"varint,3,opt,name=system,proto3,enum=usage.v1.System" json:"system,omitempty"` } func (x *SetBilledSessionRequest) Reset() { @@ -412,11 +462,11 @@ func (x *SetBilledSessionRequest) GetFrom() *timestamppb.Timestamp { return nil } -func (x *SetBilledSessionRequest) GetSystem() string { +func (x *SetBilledSessionRequest) GetSystem() System { if x != nil { return x.System } - return "" + return System_SYSTEM_UNKNOWN } type SetBilledSessionResponse struct { @@ -497,44 +547,50 @@ var file_usage_v1_billing_proto_rawDesc = []byte{ 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0x19, 0x0a, 0x17, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x82, 0x01, 0x0a, 0x17, 0x53, 0x65, 0x74, 0x42, 0x69, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x94, 0x01, 0x0a, 0x17, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x04, 0x66, - 0x72, 0x6f, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x22, 0x1a, 0x0a, 0x18, 0x53, - 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xfb, 0x02, 0x0a, 0x0e, 0x42, 0x69, 0x6c, 0x6c, - 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x55, 0x0a, 0x0e, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x2e, 0x75, - 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, - 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, - 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, - 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x5b, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x49, 0x6e, - 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x21, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, - 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x76, - 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x58, - 0x0a, 0x0f, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, - 0x65, 0x12, 0x20, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, - 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x46, - 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5b, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x42, - 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x75, - 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, - 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x22, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x42, 0x69, - 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, 0x67, 0x69, - 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x76, - 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x6f, 0x6d, 0x12, 0x28, 0x0a, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, + 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x22, 0x1a, 0x0a, + 0x18, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, 0x45, 0x0a, 0x06, 0x53, 0x79, 0x73, + 0x74, 0x65, 0x6d, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x55, 0x4e, + 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x53, 0x59, 0x53, 0x54, 0x45, + 0x4d, 0x5f, 0x43, 0x48, 0x41, 0x52, 0x47, 0x45, 0x42, 0x45, 0x45, 0x10, 0x01, 0x12, 0x11, 0x0a, + 0x0d, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x50, 0x45, 0x10, 0x02, + 0x32, 0xfb, 0x02, 0x0a, 0x0e, 0x42, 0x69, 0x6c, 0x6c, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x55, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, + 0x6f, 0x69, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5b, 0x0a, 0x10, 0x47, 0x65, + 0x74, 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x21, + 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x74, + 0x65, 0x73, 0x74, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x22, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, + 0x4c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x58, 0x0a, 0x0f, 0x46, 0x69, 0x6e, 0x61, 0x6c, + 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x20, 0x2e, 0x75, 0x73, 0x61, + 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x49, 0x6e, + 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x75, + 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, + 0x49, 0x6e, 0x76, 0x6f, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x5b, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x75, 0x73, 0x61, 0x67, 0x65, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x42, 0x69, 0x6c, 0x6c, 0x65, 0x64, 0x53, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2a, + 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, + 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x75, 0x73, + 0x61, 0x67, 0x65, 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -549,37 +605,40 @@ func file_usage_v1_billing_proto_rawDescGZIP() []byte { return file_usage_v1_billing_proto_rawDescData } +var file_usage_v1_billing_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_usage_v1_billing_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_usage_v1_billing_proto_goTypes = []interface{}{ - (*UpdateInvoicesRequest)(nil), // 0: usage.v1.UpdateInvoicesRequest - (*UpdateInvoicesResponse)(nil), // 1: usage.v1.UpdateInvoicesResponse - (*GetLatestInvoiceRequest)(nil), // 2: usage.v1.GetLatestInvoiceRequest - (*GetLatestInvoiceResponse)(nil), // 3: usage.v1.GetLatestInvoiceResponse - (*FinalizeInvoiceRequest)(nil), // 4: usage.v1.FinalizeInvoiceRequest - (*FinalizeInvoiceResponse)(nil), // 5: usage.v1.FinalizeInvoiceResponse - (*SetBilledSessionRequest)(nil), // 6: usage.v1.SetBilledSessionRequest - (*SetBilledSessionResponse)(nil), // 7: usage.v1.SetBilledSessionResponse - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp - (*BilledSession)(nil), // 9: usage.v1.BilledSession + (System)(0), // 0: usage.v1.System + (*UpdateInvoicesRequest)(nil), // 1: usage.v1.UpdateInvoicesRequest + (*UpdateInvoicesResponse)(nil), // 2: usage.v1.UpdateInvoicesResponse + (*GetLatestInvoiceRequest)(nil), // 3: usage.v1.GetLatestInvoiceRequest + (*GetLatestInvoiceResponse)(nil), // 4: usage.v1.GetLatestInvoiceResponse + (*FinalizeInvoiceRequest)(nil), // 5: usage.v1.FinalizeInvoiceRequest + (*FinalizeInvoiceResponse)(nil), // 6: usage.v1.FinalizeInvoiceResponse + (*SetBilledSessionRequest)(nil), // 7: usage.v1.SetBilledSessionRequest + (*SetBilledSessionResponse)(nil), // 8: usage.v1.SetBilledSessionResponse + (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp + (*BilledSession)(nil), // 10: usage.v1.BilledSession } var file_usage_v1_billing_proto_depIdxs = []int32{ - 8, // 0: usage.v1.UpdateInvoicesRequest.start_time:type_name -> google.protobuf.Timestamp - 8, // 1: usage.v1.UpdateInvoicesRequest.end_time:type_name -> google.protobuf.Timestamp - 9, // 2: usage.v1.UpdateInvoicesRequest.sessions:type_name -> usage.v1.BilledSession - 8, // 3: usage.v1.SetBilledSessionRequest.from:type_name -> google.protobuf.Timestamp - 0, // 4: usage.v1.BillingService.UpdateInvoices:input_type -> usage.v1.UpdateInvoicesRequest - 2, // 5: usage.v1.BillingService.GetLatestInvoice:input_type -> usage.v1.GetLatestInvoiceRequest - 4, // 6: usage.v1.BillingService.FinalizeInvoice:input_type -> usage.v1.FinalizeInvoiceRequest - 6, // 7: usage.v1.BillingService.SetBilledSession:input_type -> usage.v1.SetBilledSessionRequest - 1, // 8: usage.v1.BillingService.UpdateInvoices:output_type -> usage.v1.UpdateInvoicesResponse - 3, // 9: usage.v1.BillingService.GetLatestInvoice:output_type -> usage.v1.GetLatestInvoiceResponse - 5, // 10: usage.v1.BillingService.FinalizeInvoice:output_type -> usage.v1.FinalizeInvoiceResponse - 7, // 11: usage.v1.BillingService.SetBilledSession:output_type -> usage.v1.SetBilledSessionResponse - 8, // [8:12] is the sub-list for method output_type - 4, // [4:8] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 9, // 0: usage.v1.UpdateInvoicesRequest.start_time:type_name -> google.protobuf.Timestamp + 9, // 1: usage.v1.UpdateInvoicesRequest.end_time:type_name -> google.protobuf.Timestamp + 10, // 2: usage.v1.UpdateInvoicesRequest.sessions:type_name -> usage.v1.BilledSession + 9, // 3: usage.v1.SetBilledSessionRequest.from:type_name -> google.protobuf.Timestamp + 0, // 4: usage.v1.SetBilledSessionRequest.system:type_name -> usage.v1.System + 1, // 5: usage.v1.BillingService.UpdateInvoices:input_type -> usage.v1.UpdateInvoicesRequest + 3, // 6: usage.v1.BillingService.GetLatestInvoice:input_type -> usage.v1.GetLatestInvoiceRequest + 5, // 7: usage.v1.BillingService.FinalizeInvoice:input_type -> usage.v1.FinalizeInvoiceRequest + 7, // 8: usage.v1.BillingService.SetBilledSession:input_type -> usage.v1.SetBilledSessionRequest + 2, // 9: usage.v1.BillingService.UpdateInvoices:output_type -> usage.v1.UpdateInvoicesResponse + 4, // 10: usage.v1.BillingService.GetLatestInvoice:output_type -> usage.v1.GetLatestInvoiceResponse + 6, // 11: usage.v1.BillingService.FinalizeInvoice:output_type -> usage.v1.FinalizeInvoiceResponse + 8, // 12: usage.v1.BillingService.SetBilledSession:output_type -> usage.v1.SetBilledSessionResponse + 9, // [9:13] is the sub-list for method output_type + 5, // [5:9] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_usage_v1_billing_proto_init() } @@ -695,13 +754,14 @@ func file_usage_v1_billing_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_usage_v1_billing_proto_rawDesc, - NumEnums: 0, + NumEnums: 1, NumMessages: 8, NumExtensions: 0, NumServices: 1, }, GoTypes: file_usage_v1_billing_proto_goTypes, DependencyIndexes: file_usage_v1_billing_proto_depIdxs, + EnumInfos: file_usage_v1_billing_proto_enumTypes, MessageInfos: file_usage_v1_billing_proto_msgTypes, }.Build() File_usage_v1_billing_proto = out.File diff --git a/components/usage-api/typescript/src/usage/v1/billing_pb.d.ts b/components/usage-api/typescript/src/usage/v1/billing_pb.d.ts index e579a1cc2f75af..38e41d0600ba71 100644 --- a/components/usage-api/typescript/src/usage/v1/billing_pb.d.ts +++ b/components/usage-api/typescript/src/usage/v1/billing_pb.d.ts @@ -174,8 +174,8 @@ export class SetBilledSessionRequest extends jspb.Message { clearFrom(): void; getFrom(): google_protobuf_timestamp_pb.Timestamp | undefined; setFrom(value?: google_protobuf_timestamp_pb.Timestamp): SetBilledSessionRequest; - getSystem(): string; - setSystem(value: string): SetBilledSessionRequest; + getSystem(): System; + setSystem(value: System): SetBilledSessionRequest; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): SetBilledSessionRequest.AsObject; @@ -191,7 +191,7 @@ export namespace SetBilledSessionRequest { export type AsObject = { instanceId: string, from?: google_protobuf_timestamp_pb.Timestamp.AsObject, - system: string, + system: System, } } @@ -211,3 +211,9 @@ export namespace SetBilledSessionResponse { export type AsObject = { } } + +export enum System { + SYSTEM_UNKNOWN = 0, + SYSTEM_CHARGEBEE = 1, + SYSTEM_STRIPE = 2, +} diff --git a/components/usage-api/typescript/src/usage/v1/billing_pb.js b/components/usage-api/typescript/src/usage/v1/billing_pb.js index 14078cb55bbf62..6e5a40c593c1f6 100644 --- a/components/usage-api/typescript/src/usage/v1/billing_pb.js +++ b/components/usage-api/typescript/src/usage/v1/billing_pb.js @@ -32,6 +32,7 @@ goog.exportSymbol('proto.usage.v1.GetLatestInvoiceRequest.IdentifierCase', null, goog.exportSymbol('proto.usage.v1.GetLatestInvoiceResponse', null, global); goog.exportSymbol('proto.usage.v1.SetBilledSessionRequest', null, global); goog.exportSymbol('proto.usage.v1.SetBilledSessionResponse', null, global); +goog.exportSymbol('proto.usage.v1.System', null, global); goog.exportSymbol('proto.usage.v1.UpdateInvoicesRequest', null, global); goog.exportSymbol('proto.usage.v1.UpdateInvoicesResponse', null, global); /** @@ -1242,7 +1243,7 @@ proto.usage.v1.SetBilledSessionRequest.toObject = function(includeInstance, msg) var f, obj = { instanceId: jspb.Message.getFieldWithDefault(msg, 1, ""), from: (f = msg.getFrom()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f), - system: jspb.Message.getFieldWithDefault(msg, 3, "") + system: jspb.Message.getFieldWithDefault(msg, 3, 0) }; if (includeInstance) { @@ -1289,7 +1290,7 @@ proto.usage.v1.SetBilledSessionRequest.deserializeBinaryFromReader = function(ms msg.setFrom(value); break; case 3: - var value = /** @type {string} */ (reader.readString()); + var value = /** @type {!proto.usage.v1.System} */ (reader.readEnum()); msg.setSystem(value); break; default: @@ -1337,8 +1338,8 @@ proto.usage.v1.SetBilledSessionRequest.serializeBinaryToWriter = function(messag ); } f = message.getSystem(); - if (f.length > 0) { - writer.writeString( + if (f !== 0.0) { + writer.writeEnum( 3, f ); @@ -1402,20 +1403,20 @@ proto.usage.v1.SetBilledSessionRequest.prototype.hasFrom = function() { /** - * optional string system = 3; - * @return {string} + * optional System system = 3; + * @return {!proto.usage.v1.System} */ proto.usage.v1.SetBilledSessionRequest.prototype.getSystem = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); + return /** @type {!proto.usage.v1.System} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); }; /** - * @param {string} value + * @param {!proto.usage.v1.System} value * @return {!proto.usage.v1.SetBilledSessionRequest} returns this */ proto.usage.v1.SetBilledSessionRequest.prototype.setSystem = function(value) { - return jspb.Message.setProto3StringField(this, 3, value); + return jspb.Message.setProto3EnumField(this, 3, value); }; @@ -1520,4 +1521,13 @@ proto.usage.v1.SetBilledSessionResponse.serializeBinaryToWriter = function(messa }; +/** + * @enum {number} + */ +proto.usage.v1.System = { + SYSTEM_UNKNOWN: 0, + SYSTEM_CHARGEBEE: 1, + SYSTEM_STRIPE: 2 +}; + goog.object.extend(exports, proto.usage.v1); diff --git a/components/usage-api/typescript/src/usage/v1/sugar.ts b/components/usage-api/typescript/src/usage/v1/sugar.ts index f5d3a9b46a4108..4750c7e5f61999 100644 --- a/components/usage-api/typescript/src/usage/v1/sugar.ts +++ b/components/usage-api/typescript/src/usage/v1/sugar.ts @@ -10,7 +10,7 @@ import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing"; import * as opentracing from "opentracing"; import { Metadata } from "@grpc/grpc-js"; import { BilledSession, ListBilledUsageRequest, ListBilledUsageResponse } from "./usage_pb"; -import { SetBilledSessionRequest, SetBilledSessionResponse } from "./billing_pb"; +import { SetBilledSessionRequest, SetBilledSessionResponse, System } from "./billing_pb"; import { injectable, inject, optional } from "inversify"; import { createClientCallMetricsInterceptor, IClientCallMetrics } from "@gitpod/gitpod-protocol/lib/util/grpc"; import * as grpc from "@grpc/grpc-js"; @@ -227,25 +227,21 @@ export class PromisifiedBillingServiceClient { ); } - public async setBilledSession(instanceId: string, instanceCreationTime: Timestamp, system: string) { + public async setBilledSession(instanceId: string, instanceCreationTime: Timestamp, system: System) { const req = new SetBilledSessionRequest(); req.setInstanceId(instanceId); req.setFrom(instanceCreationTime); req.setSystem(system); - const response = await new Promise((resolve, reject) => { - this.client.setBilledSession( - req, - (err: grpc.ServiceError | null, response: SetBilledSessionResponse) => { - if (err) { - reject(err); - return; - } - resolve(response); - }, - )} - ) + this.client.setBilledSession(req, (err: grpc.ServiceError | null, response: SetBilledSessionResponse) => { + if (err) { + reject(err); + return; + } + resolve(response); + }); + }); return response; } diff --git a/components/usage-api/usage/v1/billing.proto b/components/usage-api/usage/v1/billing.proto index 6c6fd80325b671..7ad003f076d9f6 100644 --- a/components/usage-api/usage/v1/billing.proto +++ b/components/usage-api/usage/v1/billing.proto @@ -55,9 +55,9 @@ message FinalizeInvoiceResponse { } enum System { - UNKNOWN = 0; - CHARGEBEE = 1; - STRIPE = 2; + SYSTEM_UNKNOWN = 0; + SYSTEM_CHARGEBEE = 1; + SYSTEM_STRIPE = 2; } // If there are two billable sessions for this instance ID, diff --git a/components/usage/pkg/db/billed_session.go b/components/usage/pkg/db/billed_session.go index 0bb76a72d2b804..6785b617fe1292 100644 --- a/components/usage/pkg/db/billed_session.go +++ b/components/usage/pkg/db/billed_session.go @@ -7,9 +7,12 @@ package db import ( "context" "fmt" + "time" + "github.com/google/uuid" "gorm.io/gorm" - "time" + + v1 "github.com/gitpod-io/gitpod/usage-api/v1" ) // BilledSession represents the underlying DB object @@ -30,10 +33,19 @@ func (d *BilledSession) TableName() string { return "d_b_billed_session" } -func SetBilled(ctx context.Context, conn *gorm.DB, instanceID uuid.UUID, instanceCreationTime time.Time, system string) error { +func SetBilled(ctx context.Context, conn *gorm.DB, instanceID uuid.UUID, instanceCreationTime time.Time, system v1.System) error { database := conn.WithContext(ctx) - billedSession := BilledSession{InstanceID: instanceID, From: NewVarcharTime(instanceCreationTime), System: system} + var sys string + switch system { + case v1.System_SYSTEM_CHARGEBEE: + sys = "chargebee" + case v1.System_SYSTEM_STRIPE: + sys = "stripe" + default: + sys = "unknown" + } + billedSession := BilledSession{InstanceID: instanceID, From: NewVarcharTime(instanceCreationTime), System: sys} return database.Create(&billedSession).Error }