-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[installer] Allow to set default workspace timeout #8576
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
*/ | ||
|
||
import { UserService, CheckSignUpParams, CheckTermsParams } from "../../../src/user/user-service"; | ||
import { User, WorkspaceTimeoutDuration } from "@gitpod/gitpod-protocol"; | ||
import { User, WorkspaceTimeoutDuration, WORKSPACE_TIMEOUT_EXTENDED, WORKSPACE_TIMEOUT_EXTENDED_ALT, WORKSPACE_TIMEOUT_DEFAULT_LONG, WORKSPACE_TIMEOUT_DEFAULT_SHORT } from "@gitpod/gitpod-protocol"; | ||
import { inject } from "inversify"; | ||
import { LicenseEvaluator } from "@gitpod/licensor/lib"; | ||
import { Feature } from "@gitpod/licensor/lib/api"; | ||
|
@@ -14,13 +14,15 @@ import { EligibilityService } from "./eligibility-service"; | |
import { SubscriptionService } from "@gitpod/gitpod-payment-endpoint/lib/accounting"; | ||
import { OssAllowListDB } from "@gitpod/gitpod-db/lib/oss-allowlist-db"; | ||
import { HostContextProvider } from "../../../src/auth/host-context-provider"; | ||
import { Config } from "../../../src/config"; | ||
|
||
export class UserServiceEE extends UserService { | ||
@inject(LicenseEvaluator) protected readonly licenseEvaluator: LicenseEvaluator; | ||
@inject(EligibilityService) protected readonly eligibilityService: EligibilityService; | ||
@inject(SubscriptionService) protected readonly subscriptionService: SubscriptionService; | ||
@inject(OssAllowListDB) protected readonly OssAllowListDb: OssAllowListDB; | ||
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider; | ||
@inject(Config) protected readonly config: Config; | ||
|
||
async getDefaultWorkspaceTimeout(user: User, date: Date): Promise<WorkspaceTimeoutDuration> { | ||
if (this.config.enablePayment) { | ||
|
@@ -32,10 +34,35 @@ export class UserServiceEE extends UserService { | |
|
||
// the self-hosted case | ||
if (!this.licenseEvaluator.isEnabled(Feature.FeatureSetTimeout, userCount)) { | ||
return "30m"; | ||
return WORKSPACE_TIMEOUT_DEFAULT_SHORT; | ||
} | ||
|
||
return "60m"; | ||
return WORKSPACE_TIMEOUT_DEFAULT_LONG; | ||
} | ||
|
||
public workspaceTimeoutToDuration(timeout: WorkspaceTimeoutDuration): string { | ||
switch (timeout) { | ||
case WORKSPACE_TIMEOUT_DEFAULT_SHORT: | ||
return "30m"; | ||
case WORKSPACE_TIMEOUT_DEFAULT_LONG: | ||
return this.config.workspaceDefaults.timeoutDefault || "60m"; | ||
case WORKSPACE_TIMEOUT_EXTENDED: | ||
case WORKSPACE_TIMEOUT_EXTENDED_ALT: | ||
return this.config.workspaceDefaults.timeoutExtended || "180m"; | ||
} | ||
} | ||
|
||
public durationToWorkspaceTimeout(duration: string): WorkspaceTimeoutDuration { | ||
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. I find the types a little confusing in these method signatures:
I feel like Maybe this could be a follow-up issue though. ⏩ |
||
switch (duration) { | ||
case "30m": | ||
return WORKSPACE_TIMEOUT_DEFAULT_SHORT; | ||
case this.config.workspaceDefaults.timeoutDefault || "60m": | ||
return WORKSPACE_TIMEOUT_DEFAULT_LONG; | ||
case this.config.workspaceDefaults.timeoutExtended || "180m": | ||
return WORKSPACE_TIMEOUT_EXTENDED_ALT; | ||
default: | ||
return WORKSPACE_TIMEOUT_DEFAULT_SHORT; | ||
} | ||
Comment on lines
+43
to
+65
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. I don't know if 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. I also have no idea if |
||
} | ||
|
||
async userGetsMoreResources(user: User): Promise<boolean> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ import { | |
Workspace, | ||
FindPrebuildsParams, | ||
TeamMemberRole, | ||
WORKSPACE_TIMEOUT_DEFAULT_SHORT, | ||
} from "@gitpod/gitpod-protocol"; | ||
import { ResponseError } from "vscode-jsonrpc"; | ||
import { | ||
|
@@ -77,7 +78,7 @@ import { | |
import { Plans } from "@gitpod/gitpod-protocol/lib/plans"; | ||
import * as pThrottle from "p-throttle"; | ||
import { formatDate } from "@gitpod/gitpod-protocol/lib/util/date-time"; | ||
import { FindUserByIdentityStrResult } from "../../../src/user/user-service"; | ||
import { FindUserByIdentityStrResult, UserService } from "../../../src/user/user-service"; | ||
import { | ||
Accounting, | ||
AccountService, | ||
|
@@ -133,6 +134,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl { | |
|
||
@inject(UserCounter) protected readonly userCounter: UserCounter; | ||
|
||
@inject(UserService) protected readonly userService: UserService; | ||
|
||
initialize( | ||
client: GitpodClient | undefined, | ||
user: User | undefined, | ||
|
@@ -312,15 +315,15 @@ export class GitpodServerEEImpl extends GitpodServerImpl { | |
instancesWithReset.map((i) => { | ||
const req = new SetTimeoutRequest(); | ||
req.setId(i.id); | ||
req.setDuration(defaultTimeout); | ||
req.setDuration(this.userService.workspaceTimeoutToDuration(defaultTimeout)); | ||
|
||
return client.setTimeout(ctx, req); | ||
}), | ||
); | ||
|
||
const req = new SetTimeoutRequest(); | ||
req.setId(runningInstance.id); | ||
req.setDuration(duration); | ||
req.setDuration(this.userService.workspaceTimeoutToDuration(duration)); | ||
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. Micro-nit: Unfortunate variable naming 🙈 |
||
await client.setTimeout(ctx, req); | ||
|
||
return { | ||
|
@@ -343,7 +346,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl { | |
const runningInstance = await this.workspaceDb.trace(ctx).findRunningInstance(workspaceId); | ||
if (!runningInstance) { | ||
log.warn({ userId: user.id, workspaceId }, "Can only get keep-alive for running workspaces"); | ||
return { duration: "30m", canChange }; | ||
return { duration: WORKSPACE_TIMEOUT_DEFAULT_SHORT, canChange }; | ||
} | ||
await this.guardAccess({ kind: "workspaceInstance", subject: runningInstance, workspace: workspace }, "get"); | ||
|
||
|
@@ -352,7 +355,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl { | |
|
||
const client = await this.workspaceManagerClientProvider.get(runningInstance.region); | ||
const desc = await client.describeWorkspace(ctx, req); | ||
const duration = desc.getStatus()!.getSpec()!.getTimeout() as WorkspaceTimeoutDuration; | ||
const duration = this.userService.durationToWorkspaceTimeout(desc.getStatus()!.getSpec()!.getTimeout()); | ||
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. Micro-nit: Same here, we're calling But let's not fix this now. I understand this came up for historical reasons, and I don't have a good suggestion on how to improve it now. |
||
return { duration, canChange }; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.