Skip to content
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

Merged
merged 4 commits into from
Jul 12, 2022

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Jul 12, 2022

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

NONE

Documentation

NONE

Werft options:

  • /werft with-preview

@roboquat roboquat added size/M and removed size/L labels Jul 12, 2022
@roboquat roboquat added size/L and removed size/M labels Jul 12, 2022
@easyCZ easyCZ marked this pull request as ready for review July 12, 2022 12:19
@easyCZ easyCZ requested a review from a team July 12, 2022 12:19
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jul 12, 2022
Comment on lines +21 to +26
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,
Copy link
Contributor

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?

Copy link
Member Author

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.

Comment on lines +64 to +72
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 != ?", "").
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@andrew-farries andrew-farries left a 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

@roboquat roboquat merged commit de91fda into main Jul 12, 2022
@roboquat roboquat deleted the mp/usage-records-with-type-and-project branch July 12, 2022 15:00
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production do-not-merge/hold release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants