-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[usage] Find running and stopped instances in ledger reconciler #12645
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -556,3 +556,41 @@ func TestReportGenerator_GenerateUsageReportTable(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestUsageService_ReconcileUsageWithLedger(t *testing.T) { | ||
dbconn := dbtest.ConnectForTests(t) | ||
from := time.Date(2022, 05, 1, 0, 00, 00, 00, time.UTC) | ||
to := time.Date(2022, 05, 1, 1, 00, 00, 00, time.UTC) | ||
|
||
// stopped instances | ||
dbtest.CreateWorkspaceInstances(t, dbconn, dbtest.NewWorkspaceInstance(t, db.WorkspaceInstance{ | ||
StoppingTime: db.NewVarcharTime(from.Add(1 * time.Minute)), | ||
})) | ||
|
||
// running instances | ||
dbtest.CreateWorkspaceInstances(t, dbconn, dbtest.NewWorkspaceInstance(t, db.WorkspaceInstance{})) | ||
|
||
// usage drafts | ||
dbtest.CreateUsageRecords(t, dbconn, dbtest.NewUsage(t, db.Usage{ | ||
Kind: db.WorkspaceInstanceUsageKind, | ||
Draft: true, | ||
})) | ||
|
||
srv := baseserver.NewForTests(t, | ||
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)), | ||
) | ||
|
||
v1.RegisterUsageServiceServer(srv.GRPC(), NewUsageService(dbconn, nil, nil)) | ||
baseserver.StartServerForTests(t, srv) | ||
|
||
conn, err := grpc.Dial(srv.GRPCAddress(), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
require.NoError(t, err) | ||
|
||
client := v1.NewUsageServiceClient(conn) | ||
|
||
_, err = client.ReconcileUsageWithLedger(context.Background(), &v1.ReconcileUsageWithLedgerRequest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't assert the right instances were found because we don't yet update the records in any way. Once we start updating, the test here will be extended to do that. |
||
From: timestamppb.New(from), | ||
To: timestamppb.New(to), | ||
}) | ||
require.NoError(t, err) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,20 @@ import ( | |
"gorm.io/gorm/clause" | ||
) | ||
|
||
type UsageKind string | ||
|
||
const ( | ||
WorkspaceInstanceUsageKind UsageKind = "workspaceinstance" | ||
InvoiceUsageKind = "invoice" | ||
) | ||
|
||
type Usage struct { | ||
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;" json:"id"` | ||
AttributionID AttributionID `gorm:"column:attributionId;type:varchar;size:255;" json:"attributionId"` | ||
Description string `gorm:"column:description;type:varchar;size:255;" json:"description"` | ||
CreditCents int64 `gorm:"column:creditCents;type:bigint;" json:"creditCents"` | ||
EffectiveTime VarcharTime `gorm:"column:effectiveTime;type:varchar;size:255;" json:"effectiveTime"` | ||
Kind string `gorm:"column:kind;type:char;size:10;" json:"kind"` | ||
Kind UsageKind `gorm:"column:kind;type:char;size:10;" json:"kind"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
WorkspaceInstanceID uuid.UUID `gorm:"column:workspaceInstanceId;type:char;size:36;" json:"workspaceInstanceId"` | ||
Draft bool `gorm:"column:draft;type:boolean;" json:"draft"` | ||
Metadata datatypes.JSON `gorm:"column:metadata;type:text;size:65535" json:"metadata"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll also need to fetch the instances for the drafts and then combine the three slices of instances. But that's part of the next iteration I guess?