Skip to content

[server] migrate ws without usageattribution #17485

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
May 3, 2023

Conversation

svenefftinge
Copy link
Contributor

@svenefftinge svenefftinge commented May 3, 2023

Description

In the migration we didn't anticipate that we have only updated usageAttribuitionIds for workspace instances from last June until now.

This change makes sure that workspaces get an orgId oin migration and because we already have executed many migrations we unfortunately also need to fix this on the fly.

Related Issue(s)

Fixes #17482
Fixes WEB-294

How to test

Documentation

Preview status

gitpod:summary

Build Options:

  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish Options
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer Options
  • analytics=segment
  • with-dedicated-emulation
  • with-ws-manager-mk2
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated

Preview Environment Options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

/hold

@svenefftinge svenefftinge requested a review from a team May 3, 2023 13:03
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label May 3, 2023
// we need to update old workspaces on the fly that didn't get an orgId because we lack attribution on their instances.
// this can be removed eventually.
if (user.additionalData?.isMigratedToTeamOnlyAttribution) {
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this runs the same tested code, but just to be sure is wrapped in try-catch.

async updateWorkspacesOrganizationId(workspaces: WorkspaceInfo[], userOrgId: string): Promise<WorkspaceInfo[]> {
return await Promise.all(
workspaces.map(async (ws) => {
if (!ws.workspace.organizationId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only doies something on workspaces without an organizationId. So should be fast in other cases.

@@ -158,4 +158,41 @@ describe("Migration Service", () => {
const teams = await teamDB.findTeamsByUser(user.id);
expect(teams[0].name).to.be.eq("X Organization");
});

it("should update 'organizationId' for workspace without attributionId", async () => {
Copy link
Contributor Author

@svenefftinge svenefftinge May 3, 2023

Choose a reason for hiding this comment

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

This test fails without the addition in the migration code

throw new ResponseError(ErrorCodes.NOT_FOUND, "Workspace not found.");
}
return ws;
if (!workspace.organizationId && this.user?.additionalData?.isMigratedToTeamOnlyAttribution) {
try {
Copy link
Contributor Author

@svenefftinge svenefftinge May 3, 2023

Choose a reason for hiding this comment

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

try-catch here as well. Also only runs for workspaces without orgId and after migration

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.

LGTM, thanks for the test

@svenefftinge
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit 0d85286 into main May 3, 2023
@roboquat roboquat deleted the svenefftinge/very-old-pinned-workspaces-17482 branch May 3, 2023 13:26
log.info({ userId: this.user.id }, "Updating workspace without orgId.");
const userOrg = await this.userToTeamMigrationService.getUserOrganization(this.user);
const latestInstance = await this.workspaceDb.trace({}).findCurrentInstance(workspace.id);
this.userToTeamMigrationService.updateWorkspacesOrganizationId(
Copy link
Member

Choose a reason for hiding this comment

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

Missing await? Or is this supposed to be not awaited on?
#17489 to fix the build

@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels May 15, 2023
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 size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Very old pinned workspaces not shown after migration
4 participants