Skip to content

Commit 4de3805

Browse files
authored
[usage] export creation and stopped time (#19047)
1 parent 9331ac5 commit 4de3805

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

components/dashboard/src/usage/download/transform-usage-record.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const transformUsageRecord = (usage: Usage): UsageCSVRow | undefined => {
2727
endTime: metadata.endTime ?? "",
2828
userName: metadata.userName,
2929
startTime: metadata.startTime,
30+
creationTime: metadata.creationTime ?? "",
31+
stoppedTime: metadata.stoppedTime ?? "",
3032
contextURL: metadata.contextURL,
3133
workspaceId: metadata.workspaceId,
3234
userAvatarURL: metadata.userAvatarURL,
@@ -47,9 +49,11 @@ export type UsageCSVRow = {
4749
workspaceInstanceId: string;
4850
kind: string;
4951
userId: string;
52+
creationTime: string;
53+
startTime: string;
5054
endTime: string;
55+
stoppedTime: string;
5156
userName: string;
52-
startTime: string;
5357
contextURL: string;
5458
workspaceId: string;
5559
userAvatarURL: string;

components/gitpod-db/go/usage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ type WorkspaceInstanceUsageData struct {
8585
WorkspaceType WorkspaceType `json:"workspaceType"`
8686
WorkspaceClass string `json:"workspaceClass"`
8787
ContextURL string `json:"contextURL"`
88+
CreationTime string `json:"creationTime"`
8889
StartTime string `json:"startTime"`
8990
EndTime string `json:"endTime"`
91+
StoppedTime string `json:"stoppedTime"`
9092
UserID uuid.UUID `json:"userId"`
9193
UserName string `json:"userName"`
9294
UserAvatarURL string `json:"userAvatarURL"`

components/gitpod-db/go/workspace_instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func queryWorkspaceInstanceForUsage(ctx context.Context, conn *gorm.DB) *gorm.DB
135135
"ws.type as workspaceType, "+
136136
"wsi.workspaceClass as workspaceClass, "+
137137
"wsi.usageAttributionId as usageAttributionId, "+
138+
"wsi.creationTime as creationTime, "+
138139
"wsi.startedTime as startedTime, "+
139140
"wsi.stoppingTime as stoppingTime, "+
140141
"wsi.stoppedTime as stoppedTime, "+
@@ -206,6 +207,7 @@ type WorkspaceInstanceForUsage struct {
206207
UserName string `gorm:"column:userName;type:varchar;size:255;" json:"userName"`
207208
UserAvatarURL string `gorm:"column:userAvatarURL;type:varchar;size:255;" json:"userAvatarURL"`
208209

210+
CreationTime VarcharTime `gorm:"column:creationTime;type:varchar;size:255;" json:"creationTime"`
209211
StartedTime VarcharTime `gorm:"column:startedTime;type:varchar;size:255;" json:"startedTime"`
210212
StoppingTime VarcharTime `gorm:"column:stoppingTime;type:varchar;size:255;" json:"stoppingTime"`
211213
StoppedTime VarcharTime `gorm:"column:stoppedTime;type:varchar;size:255;" json:"stoppedTime"`

components/gitpod-protocol/src/usage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export interface WorkspaceInstanceUsageData {
5858
workspaceType: WorkspaceType;
5959
workspaceClass: string;
6060
contextURL: string;
61+
creationTime?: string;
6162
startTime: string;
6263
endTime?: string;
64+
stoppedTime?: string;
6365
userId: string;
6466
userName: string;
6567
userAvatarURL: string;

components/usage/pkg/apiv1/usage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ func newUsageFromInstance(instance db.WorkspaceInstanceForUsage, pricer *Workspa
409409
Draft: draft,
410410
}
411411

412+
creationTime := ""
413+
if instance.CreationTime.IsSet() {
414+
creationTime = db.TimeToISO8601(instance.CreationTime.Time())
415+
}
412416
startedTime := ""
413417
if instance.StartedTime.IsSet() {
414418
startedTime = db.TimeToISO8601(instance.StartedTime.Time())
@@ -417,13 +421,19 @@ func newUsageFromInstance(instance db.WorkspaceInstanceForUsage, pricer *Workspa
417421
if stopTime.IsSet() {
418422
endTime = db.TimeToISO8601(stopTime.Time())
419423
}
424+
stoppedTime := ""
425+
if instance.StoppedTime.IsSet() {
426+
stoppedTime = db.TimeToISO8601(instance.StoppedTime.Time())
427+
}
420428
err := usage.SetMetadataWithWorkspaceInstance(db.WorkspaceInstanceUsageData{
421429
WorkspaceId: instance.WorkspaceID,
422430
WorkspaceType: instance.Type,
423431
WorkspaceClass: instance.WorkspaceClass,
424432
ContextURL: instance.ContextURL,
433+
CreationTime: creationTime,
425434
StartTime: startedTime,
426435
EndTime: endTime,
436+
StoppedTime: stoppedTime,
427437
UserID: instance.UserID,
428438
UserName: instance.UserName,
429439
UserAvatarURL: instance.UserAvatarURL,

0 commit comments

Comments
 (0)