Skip to content

[usage] store more data for in usage entry #12736

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

Merged
merged 1 commit into from
Sep 7, 2022
Merged

Conversation

svenefftinge
Copy link
Member

Description

Fetch additional data for workspace instances and store it in d_b_usage.

Related Issue(s)

Fixes #

How to test

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview

@svenefftinge svenefftinge requested a review from a team September 7, 2022 13:00
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Sep 7, 2022
@roboquat roboquat added size/XL and removed size/L labels Sep 7, 2022
return "d_b_user"
}

func NewUser(t *testing.T, user User) User {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bit of an anti-pattern to have a testing.T used in a non test package. Normally we'd pull this into a separate package - it also has the benefit of not being included in the resulting binary if it's in a different package (not referenced by "prod" code)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in a testing package

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got confused. The User model definition should be moved out of the dbtest package into the db package

@@ -23,7 +24,7 @@ func NewWorkspaceInstance(t *testing.T, instance db.WorkspaceInstance) db.Worksp
t.Helper()

id := uuid.New()
if instance.ID.ID() != 0 { // empty value
if instance.ID != uuid.Nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I didn't know about this.

Comment on lines +17 to +25
type User struct {
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;"`
AvatarURL string `gorm:"column:avatarUrl;type:char;size:255;"`
Name string `gorm:"column:name;type:char;size:255;"`
FullName string `gorm:"column:fullName;type:char;size:255;"`
CreationDate db.VarcharTime `gorm:"column:creationDate;type:varchar;size:255;"`

// user has more field but we don't care here as they are just used in tests.
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the db package, not the dbtest package

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 put it here, because we don't need this in production code, it's only used for setting up testing state in DB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess I can live with this, but I'd generally define it on the db package as someone else will come along and not find the User object there so they would go and define it again

for _, ws := range retrieved {
ids = append(ids, ws.ID)
}
retrieved := dbtest.ListWorkspaceInstancesInRange(t, conn, startOfMay, startOfJune, workspace.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The listing methods should not be in the dbtest package, should be in the db package instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a testing utility that requires to provide a workspaceId and filters the result on it to make tests more stable. Should I name it differently to make it clearer?

Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's land it like this to unblock, we can move it around later if needed.

@svenefftinge
Copy link
Member Author

svenefftinge commented Sep 7, 2022

/werft run

👍 started the job as gitpod-build-se-usage-more-data.5
(with .werft/ from main)

@svenefftinge
Copy link
Member Author

svenefftinge commented Sep 7, 2022

/werft run

👍 started the job as gitpod-build-se-usage-more-data.6
(with .werft/ from main)

@roboquat roboquat merged commit 1fe5162 into main Sep 7, 2022
@roboquat roboquat deleted the se/usage-more-data branch September 7, 2022 15:10
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Sep 8, 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 release-note-none size/XL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants