-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ws-gc] WS soft deletion improvements #20271
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
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
01661f9
[ws-gc] Additional logging
filiptronicek fa953e8
typo fix
filiptronicek c7d01ea
test update
filiptronicek c428b1e
Workspace is active now if it just stopped, started or just got created
filiptronicek 97c0929
Don't ever GC currently running workspaces
filiptronicek 2947014
Fix tests
filiptronicek 440a4c4
Fix tests
filiptronicek 13e1a76
No more async filter predicates
filiptronicek 39065c7
More prevention logging
filiptronicek 00af0fe
Log all timestamps and don't update `lastActive` when `activeNow === …
filiptronicek 8442491
Merge branch 'main' into ft/additional-ws-gc-logging
filiptronicek bb26298
even cooler timestamps
filiptronicek 743ae10
Add instance id to log context
filiptronicek f286566
Remove filtering for only non-running workspaces
filiptronicek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ class WorkspaceDBSpec { | |
readonly timeWs = new Date(2018, 2, 16, 10, 0, 0).toISOString(); | ||
readonly timeBefore = new Date(2018, 2, 16, 11, 5, 10).toISOString(); | ||
readonly timeAfter = new Date(2019, 2, 16, 11, 5, 10).toISOString(); | ||
readonly timeAfter2 = new Date(2019, 2, 17, 4, 20, 10).toISOString(); | ||
readonly userId = "12345"; | ||
readonly projectAID = "projectA"; | ||
readonly projectBID = "projectB"; | ||
|
@@ -101,6 +102,30 @@ class WorkspaceDBSpec { | |
deleted: false, | ||
usageAttributionId: undefined, | ||
}; | ||
readonly wsi3: WorkspaceInstance = { | ||
workspaceId: this.ws.id, | ||
id: "12345", | ||
ideUrl: "example.org", | ||
region: "unknown", | ||
workspaceClass: undefined, | ||
workspaceImage: "abc.io/test/image:123", | ||
creationTime: this.timeAfter2, | ||
startedTime: undefined, | ||
deployedTime: undefined, | ||
stoppingTime: undefined, | ||
stoppedTime: undefined, | ||
status: { | ||
version: 1, | ||
phase: "stopped", | ||
conditions: {}, | ||
}, | ||
configuration: { | ||
theiaVersion: "unknown", | ||
ideImage: "unknown", | ||
}, | ||
deleted: false, | ||
usageAttributionId: undefined, | ||
}; | ||
readonly ws2: Workspace = { | ||
id: "2", | ||
type: "regular", | ||
|
@@ -235,7 +260,7 @@ class WorkspaceDBSpec { | |
} | ||
|
||
@test(timeout(10000)) | ||
public async testFindEligableWorkspacesForSoftDeletion_markedEligable_Prebuild() { | ||
public async testFindEligibleWorkspacesForSoftDeletion_markedEligible_Prebuild() { | ||
const { ws } = await this.createPrebuild(20, 15); | ||
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(), 10, "prebuild"); | ||
expect(dbResult.length).to.equal(1); | ||
|
@@ -244,7 +269,7 @@ class WorkspaceDBSpec { | |
} | ||
|
||
@test(timeout(10000)) | ||
public async testFindEligableWorkspacesForSoftDeletion_notMarkedEligable_Prebuild() { | ||
public async testFindEligibleWorkspacesForSoftDeletion_notMarkedEligible_Prebuild() { | ||
await this.createPrebuild(20, -7); | ||
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(), 10, "prebuild"); | ||
expect(dbResult.length).to.eq(0); | ||
|
@@ -254,7 +279,7 @@ class WorkspaceDBSpec { | |
public async testPrebuildGarbageCollection() { | ||
const { pbws } = await this.createPrebuild(20, 15); | ||
|
||
// mimick the behavior of the Garbage Collector | ||
// mimic the behavior of the Garbage Collector | ||
const gcWorkspaces = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(), 10, "prebuild"); | ||
expect(gcWorkspaces.length).to.equal(1); | ||
|
||
|
@@ -311,16 +336,34 @@ class WorkspaceDBSpec { | |
} | ||
|
||
@test(timeout(10000)) | ||
public async testFindEligableWorkspacesForSoftDeletion_markedEligable() { | ||
public async testFindEligibleWorkspacesForSoftDeletion_markedEligible() { | ||
this.ws.deletionEligibilityTime = this.timeWs; | ||
await Promise.all([this.db.store(this.ws), this.db.storeInstance(this.wsi1), this.db.storeInstance(this.wsi2)]); | ||
await Promise.all([ | ||
this.db.store(this.ws), | ||
this.db.storeInstance(this.wsi1), | ||
this.db.storeInstance(this.wsi2), | ||
this.db.storeInstance(this.wsi3), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧡 |
||
]); | ||
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(this.timeAfter), 10); | ||
expect(dbResult[0].id).to.eq(this.ws.id); | ||
expect(dbResult[0].ownerId).to.eq(this.ws.ownerId); | ||
} | ||
|
||
@test(timeout(10000)) | ||
public async testFindEligableWorkspacesForSoftDeletion_notMarkedEligable() { | ||
public async testFindEligibleWorkspacesForSoftDeletion_notMarkedEligible() { | ||
await Promise.all([ | ||
this.db.store(this.ws), | ||
this.db.storeInstance(this.wsi1), | ||
this.db.storeInstance(this.wsi2), | ||
this.db.storeInstance(this.wsi3), | ||
]); | ||
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(this.timeAfter), 10); | ||
expect(dbResult.length).to.eq(0); | ||
} | ||
|
||
@test(timeout(10000)) | ||
public async testFindEligibleWorkspacesForSoftDeletion_notMarkedEligibleRunningInstance() { | ||
this.ws.deletionEligibilityTime = this.timeWs; | ||
await Promise.all([this.db.store(this.ws), this.db.storeInstance(this.wsi1), this.db.storeInstance(this.wsi2)]); | ||
const dbResult = await this.db.findEligibleWorkspacesForSoftDeletion(new Date(this.timeAfter), 10); | ||
expect(dbResult.length).to.eq(0); | ||
|
@@ -768,6 +811,7 @@ class WorkspaceDBSpec { | |
{ | ||
id: "1", | ||
ownerId, | ||
contentDeletedTime: d20180131, | ||
}, | ||
]); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wanted to align this with
findWorkspacesForPurging
by converting from a raw SQL statement, but maybe it's too out of scope here. I'm curious if anyone has thoughts about itThere 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.
Looking at the "async predicate" which looks way too much like a join in disguise, let' snot do this right now. 👍 🙃
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.
WDYT about the readability of this with
13e1a76
(#20271)? I tried putting everything into a single query and think that it makes a bit more sense.The benefit of using this join is not too big though so I'm happy to revert if you think it's not that helpful.