mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Uniformly use proxy to get the configuration of configcat * Add configcat enabled in workspace info api * enabled configcat in ide-service
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) 2022 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 { Client } from "./types";
|
|
import * as configcat from "configcat-node";
|
|
import { LogLevel } from "configcat-common";
|
|
import { ConfigCatClient } from "./configcat";
|
|
import { newAlwaysReturningDefaultValueClient } from "./always-default";
|
|
|
|
let client: Client | undefined;
|
|
|
|
export type ConfigCatClientFactory = () => Client;
|
|
export const ConfigCatClientFactory = Symbol("ConfigCatClientFactory");
|
|
|
|
export function getExperimentsClientForBackend(): Client {
|
|
// We have already instantiated a client, we can just re-use it.
|
|
if (client !== undefined) {
|
|
return client;
|
|
}
|
|
|
|
// Retrieve SDK key from ENV Variable
|
|
const sdkKey = process.env.CONFIGCAT_SDK_KEY;
|
|
|
|
// Self-hosted installations do not set the ConfigCat SDK key, so always use a client which returns the default value.
|
|
if (sdkKey === undefined || sdkKey === "") {
|
|
client = newAlwaysReturningDefaultValueClient();
|
|
return client;
|
|
}
|
|
|
|
const configCatClient = configcat.createClient(sdkKey, {
|
|
pollIntervalSeconds: 3 * 60, // 3 minutes
|
|
requestTimeoutMs: 2000,
|
|
logger: configcat.createConsoleLogger(LogLevel.Error),
|
|
maxInitWaitTimeSeconds: 0,
|
|
baseUrl: process.env.CONFIGCAT_BASE_URL,
|
|
});
|
|
|
|
client = new ConfigCatClient(configCatClient);
|
|
return client;
|
|
}
|