-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Introduce max_parallel_running_workspaces for orgs
#20448
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd5d325
Introduce `max_parallel_running_workspaces` for orgs
filiptronicek 9ddf926
Add migration
filiptronicek 6463197
Add UI and org settings server changes
filiptronicek 2ebdf30
Rough edges
filiptronicek 7188a5c
Number inputs (:trollface:)
filiptronicek 969c030
Move LazyOrganizationService to UBP entitlement service to get rid of…
filiptronicek 5474c7d
Fix tests
filiptronicek 37dd291
Update components/gitpod-db/src/typeorm/entity/db-team-settings.ts
filiptronicek ea621ca
Rename `isPaidPlan` to `isPaidOrDedicated` and get rid of `update_max…
filiptronicek 748421d
Update components/server/src/workspace/workspace-service.ts
filiptronicek 1abd308
Deduplicate instance counting logic
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
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
89 changes: 89 additions & 0 deletions
89
components/dashboard/src/teams/policies/MaxParallelWorkspaces.tsx
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /** | ||
| * Copyright (c) 2024 Gitpod GmbH. All rights reserved. | ||
| * Licensed under the GNU Affero General Public License (AGPL). | ||
| * See License.AGPL.txt in the project root for license information. | ||
| */ | ||
|
|
||
| import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb"; | ||
| import { FormEvent, useEffect, useState } from "react"; | ||
| import { ConfigurationSettingsField } from "../../repositories/detail/ConfigurationSettingsField"; | ||
| import { Heading3, Subheading } from "@podkit/typography/Headings"; | ||
| import { InputField } from "../../components/forms/InputField"; | ||
| import { NumberInput } from "../../components/forms/TextInputField"; | ||
| import { LoadingButton } from "@podkit/buttons/LoadingButton"; | ||
| import { MAX_PARALLEL_WORKSPACES_FREE, MAX_PARALLEL_WORKSPACES_PAID } from "@gitpod/gitpod-protocol"; | ||
| import { PlainMessage } from "@bufbuild/protobuf"; | ||
| import { useInstallationConfiguration } from "../../data/installation/default-workspace-image-query"; | ||
|
|
||
| type Props = { | ||
| isOwner: boolean; | ||
| isLoading: boolean; | ||
| isPaidOrDedicated: boolean; | ||
| settings?: OrganizationSettings; | ||
| handleUpdateTeamSettings: ( | ||
| newSettings: Partial<PlainMessage<OrganizationSettings>>, | ||
| options?: { | ||
| throwMutateError?: boolean; | ||
| }, | ||
| ) => Promise<void>; | ||
| }; | ||
|
|
||
| export const MaxParallelWorkspaces = ({ | ||
| isOwner, | ||
| isLoading, | ||
| settings, | ||
| isPaidOrDedicated, | ||
| handleUpdateTeamSettings, | ||
| }: Props) => { | ||
| const [error, setError] = useState<string | undefined>(undefined); | ||
| const [maxParallelWorkspaces, setMaxParallelWorkspaces] = useState<number>( | ||
| settings?.maxParallelRunningWorkspaces ?? 0, | ||
| ); | ||
|
|
||
| const organizationDefault = isPaidOrDedicated ? MAX_PARALLEL_WORKSPACES_PAID : MAX_PARALLEL_WORKSPACES_FREE; | ||
| const { data: installationConfig } = useInstallationConfiguration(); | ||
| const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation; | ||
|
|
||
| const handleSubmit = async (e: FormEvent) => { | ||
| e.preventDefault(); | ||
| if (maxParallelWorkspaces < 0) { | ||
| setError("The maximum parallel running workspaces must be a positive number."); | ||
| return; | ||
| } | ||
| await handleUpdateTeamSettings({ | ||
| maxParallelRunningWorkspaces: maxParallelWorkspaces, | ||
| }); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| setMaxParallelWorkspaces(settings?.maxParallelRunningWorkspaces ?? 0); | ||
| }, [settings?.maxParallelRunningWorkspaces]); | ||
|
|
||
| return ( | ||
| <ConfigurationSettingsField> | ||
| <Heading3>Maximum parallel running workspaces</Heading3> | ||
| <Subheading> | ||
| By default, every user in your organization can have <strong>{organizationDefault}</strong> workspaces | ||
| running at the same time. You can change this limit below or revert to this default by specifying{" "} | ||
| <strong>0</strong> as the limit. | ||
| </Subheading> | ||
| <form onSubmit={handleSubmit}> | ||
| <InputField label="Maximum parallel running workspaces" error={error} className="mb-4"> | ||
| <NumberInput | ||
| value={maxParallelWorkspaces ?? ""} | ||
| onChange={(newValue) => { | ||
| setMaxParallelWorkspaces(newValue); | ||
| setError(undefined); | ||
| }} | ||
| disabled={isLoading || !isOwner} | ||
| min={0} | ||
| max={isDedicatedInstallation ? undefined : organizationDefault} | ||
| /> | ||
| </InputField> | ||
| <LoadingButton type="submit" loading={isLoading} disabled={!isOwner}> | ||
| Save | ||
| </LoadingButton> | ||
| </form> | ||
| </ConfigurationSettingsField> | ||
| ); | ||
| }; |
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
25 changes: 25 additions & 0 deletions
25
...ents/gitpod-db/src/typeorm/migration/1734079239772-AddOrgSettingsMaxParallelWorkspaces.ts
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Copyright (c) 2024 Gitpod GmbH. All rights reserved. | ||
| * Licensed under the GNU Affero General Public License (AGPL). | ||
| * See License.AGPL.txt in the project root for license information. | ||
| */ | ||
|
|
||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
| import { columnExists } from "./helper/helper"; | ||
|
|
||
| const table = "d_b_org_settings"; | ||
| const newColumn = "maxParallelRunningWorkspaces"; | ||
|
|
||
| export class AddOrgSettingsMaxParallelWorkspaces1734079239772 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| if (!(await columnExists(queryRunner, table, newColumn))) { | ||
| await queryRunner.query(`ALTER TABLE ${table} ADD COLUMN ${newColumn} INTEGER NOT NULL DEFAULT 0`); | ||
| } | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| if (await columnExists(queryRunner, table, newColumn)) { | ||
| await queryRunner.query(`ALTER TABLE ${table} DROP COLUMN ${newColumn}`); | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.