Skip to content

Commit 9e07410

Browse files
committed
[server] Inject process.env.HOST_URL into feature flag attributes
1 parent 57c33a4 commit 9e07410

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

components/gitpod-protocol/src/experiments/configcat-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ export function getExperimentsClientForBackend(): Client {
5454
baseUrl: process.env.CONFIGCAT_BASE_URL,
5555
});
5656

57-
client = new ConfigCatClient(configCatClient);
57+
client = new ConfigCatClient(configCatClient, process.env.HOST_URL);
5858
return client;
5959
}

components/gitpod-protocol/src/experiments/configcat.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ export const BILLING_TIER_ATTRIBUTE = "billing_tier";
1717
export const GITPOD_HOST = "gitpod_host";
1818

1919
export class ConfigCatClient implements Client {
20-
private client: IConfigCatClient;
21-
22-
constructor(cc: IConfigCatClient) {
23-
this.client = cc;
24-
}
20+
constructor(private readonly client: IConfigCatClient, private readonly gitpodHost?: string) {}
2521

2622
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T> {
27-
return this.client.getValueAsync(experimentName, defaultValue, attributesToUser(attributes));
23+
return this.client.getValueAsync(
24+
experimentName,
25+
defaultValue,
26+
attributesToUser({
27+
gitpodHost: this.gitpodHost,
28+
...attributes,
29+
}),
30+
);
2831
}
2932

3033
dispose(): void {

components/server/src/container-module.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
import { ContainerModule } from "inversify";
88

99
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics";
10-
import {
11-
ConfigCatClientFactory,
12-
getExperimentsClientForBackend,
13-
} from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
1410
import { GitpodFileParser } from "@gitpod/gitpod-protocol/lib/gitpod-file-parser";
1511
import { PrometheusClientCallMetrics } from "@gitpod/gitpod-protocol/lib/messaging/client-call-metrics";
1612
import { newAnalyticsWriterFromEnv } from "@gitpod/gitpod-protocol/lib/util/analytics";
@@ -296,12 +292,6 @@ export const productionContainerModule = new ContainerModule(
296292
})
297293
.inSingletonScope();
298294

299-
bind(ConfigCatClientFactory)
300-
.toDynamicValue((ctx) => {
301-
return () => getExperimentsClientForBackend();
302-
})
303-
.inSingletonScope();
304-
305295
bind(VerificationService).toSelf().inSingletonScope();
306296

307297
bind(UsageService).toSelf().inSingletonScope();

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ import { IDEService } from "../ide-service";
141141
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
142142
import { CostCenterJSON } from "@gitpod/gitpod-protocol/lib/usage";
143143
import { createCookielessId, maskIp } from "../analytics";
144-
import {
145-
ConfigCatClientFactory,
146-
getExperimentsClientForBackend,
147-
} from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
144+
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
148145
import { increaseDashboardErrorBoundaryCounter } from "../prometheus-metrics";
149146
import { LinkedInService } from "../linkedin-service";
150147
import { SnapshotService, WaitForSnapshotOptions } from "./snapshot-service";
@@ -235,8 +232,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
235232
@inject(VerificationService) private readonly verificationService: VerificationService,
236233
@inject(EntitlementService) private readonly entitlementService: EntitlementService,
237234

238-
@inject(ConfigCatClientFactory) private readonly configCatClientFactory: ConfigCatClientFactory,
239-
240235
@inject(Authorizer) private readonly auth: Authorizer,
241236

242237
@inject(BillingModes) private readonly billingModes: BillingModes,
@@ -672,7 +667,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
672667
const user = await this.checkUser("sendPhoneNumberVerificationToken");
673668

674669
// Check if verify via call is enabled
675-
const phoneVerificationByCall = await this.configCatClientFactory().getValueAsync(
670+
const phoneVerificationByCall = await getExperimentsClientForBackend().getValueAsync(
676671
"phoneVerificationByCall",
677672
false,
678673
{
@@ -3178,7 +3173,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
31783173

31793174
private async guardWithFeatureFlag(flagName: string, user: User, teamId: string) {
31803175
// Guard method w/ a feature flag check
3181-
const isEnabled = await this.configCatClientFactory().getValueAsync(flagName, false, {
3176+
const isEnabled = await getExperimentsClientForBackend().getValueAsync(flagName, false, {
31823177
user: user,
31833178
teamId,
31843179
});

0 commit comments

Comments
 (0)