-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jetbrains/phpstorm-221-5591-58
- Loading branch information
Showing
26 changed files
with
313 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,24 @@ | ||
/** | ||
* 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 { Attributes, Client } from "./client"; | ||
|
||
// AlwaysReturningDefaultValueClient is an implemention of an experiments.Client which performs no lookup/network operation | ||
// and always returns the default value for a given experimentName. | ||
// This client is used for non-SaaS version of Gitpod, in particular for self-hosted installations where external | ||
// network connections are not desirable or even possible. | ||
class AlwaysReturningDefaultValueClient implements Client { | ||
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T> { | ||
return Promise.resolve(defaultValue); | ||
} | ||
|
||
dispose(): void { | ||
// there is nothing to dispose, no-op. | ||
} | ||
} | ||
|
||
export function newAlwaysReturningDefaultValueClient(): Client { | ||
return new AlwaysReturningDefaultValueClient(); | ||
} |
This file contains 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,55 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// Attributes define attributes which can be used to segment audiences. | ||
// Set the attributes which you want to use to group audiences into. | ||
import { newNonProductionConfigCatClient, newProductionConfigCatClient } from "./configcat"; | ||
import { newAlwaysReturningDefaultValueClient } from "./always-default"; | ||
|
||
export interface Attributes { | ||
userID?: string; | ||
email?: string; | ||
|
||
// Gitpod Project ID | ||
projectID?: string; | ||
|
||
// Gitpod Team ID | ||
teamID?: string; | ||
// Gitpod Team Name | ||
teamName?: string; | ||
} | ||
|
||
export interface Client { | ||
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T>; | ||
|
||
// dispose will dispose of the client, no longer retrieving flags | ||
dispose(): void; | ||
} | ||
|
||
let client: Client | undefined; | ||
|
||
export function getExperimentsClient(): Client { | ||
// We have already instantiated a client, we can just re-use it. | ||
if (client !== undefined) { | ||
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(); | ||
} | ||
|
||
return client; | ||
} | ||
|
||
export const PROJECT_ID_ATTRIBUTE = "project_id"; | ||
export const TEAM_ID_ATTRIBUTE = "team_id"; | ||
export const TEAM_NAME_ATTRIBUTE = "team_name"; |
This file contains 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,69 @@ | ||
/** | ||
* 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 * as configcat from "configcat-js"; | ||
import { IConfigCatClient } from "configcat-common/lib/ConfigCatClient"; | ||
import { User } from "configcat-common/lib/RolloutEvaluator"; | ||
import { Attributes, Client, PROJECT_ID_ATTRIBUTE, TEAM_ID_ATTRIBUTE, TEAM_NAME_ATTRIBUTE } from "./client"; | ||
|
||
// newProductionConfigCatClient constructs a new ConfigCat client with production configuration. | ||
// DO NOT USE DIRECTLY! Use getExperimentsClient() instead. | ||
export function newProductionConfigCatClient(): Client { | ||
// clientKey is an identifier of our ConfigCat application. It is not a secret. | ||
const clientKey = "WBLaCPtkjkqKHlHedziE9g/TwAe6YyftEGPnGxVRXd0Ig"; | ||
const client = configcat.createClient(clientKey, { | ||
logger: configcat.createConsoleLogger(2), | ||
}); | ||
|
||
return new ConfigCatClient(client); | ||
} | ||
|
||
// newNonProductionConfigCatClient constructs a new ConfigCat client with non-production configuration. | ||
// DO NOT USE DIRECTLY! Use getExperimentsClient() instead. | ||
export function newNonProductionConfigCatClient(): Client { | ||
// clientKey is an identifier of our ConfigCat application. It is not a secret. | ||
const clientKey = "WBLaCPtkjkqKHlHedziE9g/LEAOCNkbuUKiqUZAcVg7dw"; | ||
const client = configcat.createClient(clientKey, { | ||
pollIntervalSeconds: 60 * 3, // 3 minutes | ||
logger: configcat.createConsoleLogger(3), | ||
}); | ||
|
||
return new ConfigCatClient(client); | ||
} | ||
|
||
class ConfigCatClient implements Client { | ||
private client: IConfigCatClient; | ||
|
||
constructor(cc: IConfigCatClient) { | ||
this.client = cc; | ||
} | ||
|
||
getValueAsync<T>(experimentName: string, defaultValue: T, attributes: Attributes): Promise<T> { | ||
return this.client.getValueAsync(experimentName, defaultValue, attributesToUser(attributes)); | ||
} | ||
|
||
dispose(): void { | ||
return this.client.dispose(); | ||
} | ||
} | ||
|
||
function attributesToUser(attributes: Attributes): User { | ||
const userID = attributes.userID || ""; | ||
const email = attributes.email || ""; | ||
|
||
const custom: { [key: string]: string } = {}; | ||
if (attributes.projectID) { | ||
custom[PROJECT_ID_ATTRIBUTE] = attributes.projectID; | ||
} | ||
if (attributes.teamID) { | ||
custom[TEAM_ID_ATTRIBUTE] = attributes.teamID; | ||
} | ||
if (attributes.teamName) { | ||
custom[TEAM_NAME_ATTRIBUTE] = attributes.teamName; | ||
} | ||
|
||
return new User(userID, email, "", custom); | ||
} |
This file contains 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 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 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
8 changes: 7 additions & 1 deletion
8
components/public-api/typescript/src/gitpod/v1/pagination_grpc_pb.js
This file contains 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 |
---|---|---|
@@ -1 +1,7 @@ | ||
// GENERATED CODE -- NO SERVICES IN PROTO | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// GENERATED CODE -- NO SERVICES IN PROTO |
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/pagination_pb.d.ts
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/pagination_pb.js
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/prebuilds_grpc_pb.d.ts
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/prebuilds_grpc_pb.js
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/prebuilds_pb.d.ts
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/prebuilds_pb.js
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/workspaces_grpc_pb.d.ts
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/workspaces_grpc_pb.js
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/workspaces_pb.d.ts
This file contains 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
6 changes: 6 additions & 0 deletions
6
components/public-api/typescript/src/gitpod/v1/workspaces_pb.js
This file contains 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.