Skip to content

[dashboard] Use proxy endpoint to fetch feature flags #16819

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 5 commits into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions components/dashboard/src/experiments/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* See License.AGPL.txt in the project root for license information.
*/

import { newAlwaysReturningDefaultValueClient } from "@gitpod/gitpod-protocol/lib/experiments/always-default";
import * as configcat from "configcat-js";
import { ConfigCatClient } from "@gitpod/gitpod-protocol/lib/experiments/configcat";
import { Client } from "@gitpod/gitpod-protocol/lib/experiments/types";
Expand All @@ -18,40 +17,17 @@ export function getExperimentsClient(): Client {
return client;
}

const host = window.location.hostname;
if (host === "gitpod.io") {
client = newProductionConfigCatClient();
} else if (host === "gitpod-staging.com" || host.endsWith("gitpod-dev.com") || host.endsWith("gitpod-io-dev.com")) {
client = newNonProductionConfigCatClient();
} else {
// We're gonna use a client which always returns the default value.
client = newAlwaysReturningDefaultValueClient();
}

client = newProxyConfigCatClient();
return client;
}

// newProductionConfigCatClient constructs a new ConfigCat client with production configuration.
function newProductionConfigCatClient(): Client {
// clientKey is an identifier of our ConfigCat application. It is not a secret.
const clientKey = "WBLaCPtkjkqKHlHedziE9g/TwAe6YyftEGPnGxVRXd0Ig";
const client = configcat.createClientWithLazyLoad(clientKey, {
logger: configcat.createConsoleLogger(LogLevel.Error),
cacheTimeToLiveSeconds: 60 * 3, // 3 minutes
requestTimeoutMs: 1500,
});

return new ConfigCatClient(client);
}

// newNonProductionConfigCatClient constructs a new ConfigCat client with non-production configuration.
function newNonProductionConfigCatClient(): Client {
// clientKey is an identifier of our ConfigCat application. It is not a secret.
const clientKey = "WBLaCPtkjkqKHlHedziE9g/LEAOCNkbuUKiqUZAcVg7dw";
function newProxyConfigCatClient(): Client {
const clientKey = "gitpod"; // the client key is populated by the proxy
const client = configcat.createClientWithLazyLoad(clientKey, {
logger: configcat.createConsoleLogger(LogLevel.Error),
cacheTimeToLiveSeconds: 60 * 3, // 3 minutes
requestTimeoutMs: 1500,
baseUrl: `${window.location.origin}/configcat`,
});

return new ConfigCatClient(client);
Expand Down