-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Join workspace instances with workspaces to get project and type #11312
Conversation
workspace := dbtest.CreateWorkspaces(t, conn, dbtest.NewWorkspace(t, db.Workspace{}))[0] | ||
|
||
valid := []db.WorkspaceInstance{ | ||
// In the middle of May | ||
dbtest.NewWorkspaceInstance(t, db.WorkspaceInstance{ | ||
WorkspaceID: workspaceID, | ||
WorkspaceID: workspace.ID, |
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.
Was this change necessary or just tidying up?
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.
To ensure the joining works correctly, we needed to create an actual Workspace record in the DB (line 21). That Workspace gets a random ID each time, so it's references here.
Aside, getting a random ID is a good thing, as it allows tests against the DB to run concurrently without interfering with each other.
Table(fmt.Sprintf("%s as wsi", (&WorkspaceInstance{}).TableName())). | ||
Select("wsi.id as id, ws.projectId as projectId, ws.type as workspaceType, wsi.workspaceClass as workspaceClass, wsi.usageAttributionId as usageAttributionId, wsi.stoppedTime as stoppedTime, wsi.creationTime as creationTime"). | ||
Joins(fmt.Sprintf("LEFT JOIN %s AS ws ON wsi.workspaceId = ws.id", (&Workspace{}).TableName())). | ||
Where( | ||
conn.Where("stoppedTime >= ?", TimeToISO8601(from)).Or("stoppedTime = ?", ""), | ||
conn.Where("wsi.stoppedTime >= ?", TimeToISO8601(from)).Or("wsi.stoppedTime = ?", ""), | ||
). | ||
Where("creationTime < ?", TimeToISO8601(to)). | ||
Where("startedTime != ?", ""). | ||
Where("usageAttributionId != ?", ""). | ||
Where("wsi.creationTime < ?", TimeToISO8601(to)). | ||
Where("wsi.startedTime != ?", ""). | ||
Where("wsi.usageAttributionId != ?", ""). |
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.
Do we need to test this query against larger data sets to see how it performs, or happy to deploy to prod as is?
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.
I can give it a go against prod data
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.
/hold incase you wanted to try against some real data before merging
Description
Such that our usage reporting can display information about workspace instances and their type.
Related Issue(s)
Part of #10985
How to test
Unit tests
Release Notes
Documentation
NONE
Werft options: