Skip to content

Commit

Permalink
[usage] export creation and stopped time (#19047)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge authored Nov 9, 2023
1 parent 9331ac5 commit 4de3805
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const transformUsageRecord = (usage: Usage): UsageCSVRow | undefined => {
endTime: metadata.endTime ?? "",
userName: metadata.userName,
startTime: metadata.startTime,
creationTime: metadata.creationTime ?? "",
stoppedTime: metadata.stoppedTime ?? "",
contextURL: metadata.contextURL,
workspaceId: metadata.workspaceId,
userAvatarURL: metadata.userAvatarURL,
Expand All @@ -47,9 +49,11 @@ export type UsageCSVRow = {
workspaceInstanceId: string;
kind: string;
userId: string;
creationTime: string;
startTime: string;
endTime: string;
stoppedTime: string;
userName: string;
startTime: string;
contextURL: string;
workspaceId: string;
userAvatarURL: string;
Expand Down
2 changes: 2 additions & 0 deletions components/gitpod-db/go/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ type WorkspaceInstanceUsageData struct {
WorkspaceType WorkspaceType `json:"workspaceType"`
WorkspaceClass string `json:"workspaceClass"`
ContextURL string `json:"contextURL"`
CreationTime string `json:"creationTime"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
StoppedTime string `json:"stoppedTime"`
UserID uuid.UUID `json:"userId"`
UserName string `json:"userName"`
UserAvatarURL string `json:"userAvatarURL"`
Expand Down
2 changes: 2 additions & 0 deletions components/gitpod-db/go/workspace_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func queryWorkspaceInstanceForUsage(ctx context.Context, conn *gorm.DB) *gorm.DB
"ws.type as workspaceType, "+
"wsi.workspaceClass as workspaceClass, "+
"wsi.usageAttributionId as usageAttributionId, "+
"wsi.creationTime as creationTime, "+
"wsi.startedTime as startedTime, "+
"wsi.stoppingTime as stoppingTime, "+
"wsi.stoppedTime as stoppedTime, "+
Expand Down Expand Up @@ -206,6 +207,7 @@ type WorkspaceInstanceForUsage struct {
UserName string `gorm:"column:userName;type:varchar;size:255;" json:"userName"`
UserAvatarURL string `gorm:"column:userAvatarURL;type:varchar;size:255;" json:"userAvatarURL"`

CreationTime VarcharTime `gorm:"column:creationTime;type:varchar;size:255;" json:"creationTime"`
StartedTime VarcharTime `gorm:"column:startedTime;type:varchar;size:255;" json:"startedTime"`
StoppingTime VarcharTime `gorm:"column:stoppingTime;type:varchar;size:255;" json:"stoppingTime"`
StoppedTime VarcharTime `gorm:"column:stoppedTime;type:varchar;size:255;" json:"stoppedTime"`
Expand Down
2 changes: 2 additions & 0 deletions components/gitpod-protocol/src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ export interface WorkspaceInstanceUsageData {
workspaceType: WorkspaceType;
workspaceClass: string;
contextURL: string;
creationTime?: string;
startTime: string;
endTime?: string;
stoppedTime?: string;
userId: string;
userName: string;
userAvatarURL: string;
Expand Down
10 changes: 10 additions & 0 deletions components/usage/pkg/apiv1/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ func newUsageFromInstance(instance db.WorkspaceInstanceForUsage, pricer *Workspa
Draft: draft,
}

creationTime := ""
if instance.CreationTime.IsSet() {
creationTime = db.TimeToISO8601(instance.CreationTime.Time())
}
startedTime := ""
if instance.StartedTime.IsSet() {
startedTime = db.TimeToISO8601(instance.StartedTime.Time())
Expand All @@ -417,13 +421,19 @@ func newUsageFromInstance(instance db.WorkspaceInstanceForUsage, pricer *Workspa
if stopTime.IsSet() {
endTime = db.TimeToISO8601(stopTime.Time())
}
stoppedTime := ""
if instance.StoppedTime.IsSet() {
stoppedTime = db.TimeToISO8601(instance.StoppedTime.Time())
}
err := usage.SetMetadataWithWorkspaceInstance(db.WorkspaceInstanceUsageData{
WorkspaceId: instance.WorkspaceID,
WorkspaceType: instance.Type,
WorkspaceClass: instance.WorkspaceClass,
ContextURL: instance.ContextURL,
CreationTime: creationTime,
StartTime: startedTime,
EndTime: endTime,
StoppedTime: stoppedTime,
UserID: instance.UserID,
UserName: instance.UserName,
UserAvatarURL: instance.UserAvatarURL,
Expand Down

0 comments on commit 4de3805

Please sign in to comment.