Skip to content

Commit d10be7f

Browse files
committed
allow to enable PVC feature flag for user via ConfigCat
1 parent 01fda65 commit d10be7f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

components/server/ee/src/workspace/workspace-factory.ts

+15
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ import { UserDB } from "@gitpod/gitpod-db/lib";
3232
import { UserCounter } from "../user/user-counter";
3333
import { increasePrebuildsStartedCounter } from "../../../src/prometheus-metrics";
3434
import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";
35+
import { EntitlementService } from "../../../src/billing/entitlement-service";
36+
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
3537

3638
@injectable()
3739
export class WorkspaceFactoryEE extends WorkspaceFactory {
3840
@inject(LicenseEvaluator) protected readonly licenseEvaluator: LicenseEvaluator;
3941
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
4042
@inject(UserCounter) protected readonly userCounter: UserCounter;
43+
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;
4144

4245
@inject(UserDB) protected readonly userDB: UserDB;
4346

@@ -334,6 +337,18 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
334337
if (user.featureFlags?.permanentWSFeatureFlags?.includes("persistent_volume_claim")) {
335338
config._featureFlags = (config._featureFlags || []).concat(["persistent_volume_claim"]);
336339
}
340+
const billingTier = await this.entitlementService.getBillingTier(user);
341+
const userTeams = await this.teamDB.findTeamsByUser(user.id);
342+
// this allows to control user`s PVC feature flag via ConfigCat
343+
if (
344+
await getExperimentsClientForBackend().getValueAsync("user_pvc", false, {
345+
user,
346+
teams: userTeams,
347+
billingTier,
348+
})
349+
) {
350+
config._featureFlags = (config._featureFlags || []).concat(["persistent_volume_claim"]);
351+
}
337352

338353
const id = await this.generateWorkspaceID(context);
339354
const newWs: Workspace = {

components/server/src/workspace/config-provider.ts

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import { HostContextProvider } from "../auth/host-context-provider";
3131
import { AuthorizationService } from "../user/authorization-service";
3232
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
3333
import { Config } from "../config";
34+
import { EntitlementService } from "../billing/entitlement-service";
35+
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
36+
import { TeamDB } from "@gitpod/gitpod-db/lib";
3437

3538
const POD_PATH_WORKSPACE_BASE = "/workspace";
3639

@@ -48,6 +51,8 @@ export class ConfigProvider {
4851
@inject(AuthorizationService) protected readonly authService: AuthorizationService;
4952
@inject(Config) protected readonly config: Config;
5053
@inject(ConfigurationService) protected readonly configurationService: ConfigurationService;
54+
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;
55+
@inject(TeamDB) protected readonly teamDB: TeamDB;
5156

5257
public async fetchConfig(
5358
ctx: TraceContext,
@@ -129,6 +134,18 @@ export class ConfigProvider {
129134
NamedWorkspaceFeatureFlag.isWorkspacePersisted,
130135
);
131136
}
137+
const billingTier = await this.entitlementService.getBillingTier(user);
138+
const userTeams = await this.teamDB.findTeamsByUser(user.id);
139+
// this allows to control user`s PVC feature flag via ConfigCat
140+
if (
141+
await getExperimentsClientForBackend().getValueAsync("user_pvc", false, {
142+
user,
143+
teams: userTeams,
144+
billingTier,
145+
})
146+
) {
147+
config._featureFlags = (config._featureFlags || []).concat(["persistent_volume_claim"]);
148+
}
132149

133150
return { config, literalConfig };
134151
} catch (e) {

0 commit comments

Comments
 (0)