Skip to content

Add experiments using ConfigCat #15

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 6 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
run: |
set -e
setSegmentKey="setpath([\"segmentKey\"]; \"${{ secrets.ANALITYCS_KEY }}\")"
jqCommands="${setSegmentKey}"
setConfigcatKey="setpath([\"configcatKey\"]; \"${{ secrets.CONFIGCAT_KEY }}\")"
jqCommands="${setSegmentKey} | ${setConfigcatKey}"
cat package.json | jq "${jqCommands}" > package.json.tmp
mv package.json.tmp package.json

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
run: |
set -e
setSegmentKey="setpath([\"segmentKey\"]; \"${{ secrets.ANALITYCS_KEY }}\")"
jqCommands="${setSegmentKey}"
setConfigcatKey="setpath([\"configcatKey\"]; \"${{ secrets.CONFIGCAT_KEY }}\")"
jqCommands="${setSegmentKey} | ${setConfigcatKey}"
cat package.json | jq "${jqCommands}" > package.json.tmp
mv package.json.tmp package.json

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
},
"main": "./out/extension.js",
"segmentKey": "YErmvd89wPsrCuGcVnF2XAl846W9WIGl",
"configcatKey": "WBLaCPtkjkqKHlHedziE9g/LEAOCNkbuUKiqUZAcVg7dw",
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
Expand Down Expand Up @@ -145,7 +146,8 @@
"@gitpod/gitpod-protocol": "main",
"@gitpod/local-app-api-grpcweb": "main",
"@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
"analytics-node": "^6.0.0",
"analytics-node": "^6.2.0",
"configcat-node": "^8.0.0",
"js-yaml": "^4.1.0",
"node-fetch": "2.6.7",
"pkce-challenge": "^3.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export default class Log {
this.logLevel('Warn', message, data);
}

/**
* @deprecated Use `Log.trace` instead
*/
public log(message: string, data?: any): void {
this.logLevel('Log', message, data);
this.trace(message, data);
}

public logLevel(level: LogLevel, message: string, data?: any): void {
Expand Down
90 changes: 90 additions & 0 deletions src/experiments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Gitpod. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as configcat from 'configcat-node';
import * as configcatcommon from 'configcat-common';
import * as semver from 'semver';
import Log from './common/logger';

const EXPERTIMENTAL_SETTINGS = [
'gitpod.remote.useLocalApp'
];

export class ExperimentalSettings {
private configcatClient: configcatcommon.IConfigCatClient;
private extensionVersion: semver.SemVer;

constructor(key: string, extensionVersion: string, private logger: Log) {
this.configcatClient = configcat.createClientWithLazyLoad(key, {
logger: {
debug(): void { },
log(): void { },
info(): void { },
warn(message: string): void { logger.warn(`ConfigCat: ${message}`); },
error(message: string): void { logger.error(`ConfigCat: ${message}`); }
},
requestTimeoutMs: 1500,
cacheTimeToLiveSeconds: 60
});
this.extensionVersion = new semver.SemVer(extensionVersion);
}

async get<T>(key: string, userId?: string): Promise<T | undefined> {
const config = vscode.workspace.getConfiguration('gitpod');
const values = config.inspect<T>(key.substring('gitpod.'.length));
if (!values || !EXPERTIMENTAL_SETTINGS.includes(key)) {
this.logger.error(`Cannot get invalid experimental setting '${key}'`);
return values?.globalValue ?? values?.defaultValue;
}
if (this.isPreRelease()) {
// PreRelease versions always have experiments enabled by default
return values.globalValue ?? values.defaultValue;
}
if (values.globalValue !== undefined) {
// User setting have priority over configcat so return early
return values.globalValue;
}

const user = userId ? new configcatcommon.User(userId) : undefined;
const configcatKey = key.replace(/\./g, '_'); // '.' are not allowed in configcat
const experimentValue = (await this.configcatClient.getValueAsync(configcatKey, undefined, user)) as T | undefined;

return experimentValue ?? values.defaultValue;
}

async inspect<T>(key: string, userId?: string): Promise<{ key: string; defaultValue?: T; globalValue?: T; experimentValue?: T } | undefined> {
const config = vscode.workspace.getConfiguration('gitpod');
const values = config.inspect<T>(key.substring('gitpod.'.length));
if (!values || !EXPERTIMENTAL_SETTINGS.includes(key)) {
this.logger.error(`Cannot inspect invalid experimental setting '${key}'`);
return values;
}

const user = userId ? new configcatcommon.User(userId) : undefined;
const configcatKey = key.replace(/\./g, '_'); // '.' are not allowed in configcat
const experimentValue = (await this.configcatClient.getValueAsync(configcatKey, undefined, user)) as T | undefined;

return { key, defaultValue: values.defaultValue, globalValue: values.globalValue, experimentValue };
}

isUserOverride(key: string): boolean {
const config = vscode.workspace.getConfiguration('gitpod');
const values = config.inspect(key.substring('gitpod.'.length));
return values?.globalValue !== undefined;
}

forceRefreshAsync(): Promise<void> {
return this.configcatClient.forceRefreshAsync();
}

private isPreRelease() {
return this.extensionVersion.minor % 2 === 1;
}

dispose(): void {
this.configcatClient.dispose();
}
}
6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GitpodServer from './gitpodServer';
import TelemetryReporter from './telemetryReporter';
import { exportLogs } from './exportLogs';
import { registerReleaseNotesView } from './releaseNotes';
import { ExperimentalSettings } from './experiments';

const FIRST_INSTALL_KEY = 'gitpod-desktop.firstInstall';

Expand All @@ -26,6 +27,9 @@ export async function activate(context: vscode.ExtensionContext) {
const logger = new Log('Gitpod');
logger.info(`${extensionId}/${packageJSON.version} (${os.release()} ${os.platform()} ${os.arch()}) vscode/${vscode.version} (${vscode.env.appName})`);

const experiments = new ExperimentalSettings(packageJSON.configcatKey, packageJSON.version, logger);
context.subscriptions.push(experiments);

telemetry = new TelemetryReporter(extensionId, packageJSON.version, packageJSON.segmentKey);

context.subscriptions.push(vscode.commands.registerCommand('gitpod.exportLogs', async () => {
Expand All @@ -41,7 +45,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(new SettingsSync(logger, telemetry));

const authProvider = new GitpodAuthenticationProvider(context, logger, telemetry);
remoteConnector = new RemoteConnector(context, logger, telemetry);
remoteConnector = new RemoteConnector(context, experiments, logger, telemetry);
context.subscriptions.push(authProvider);
context.subscriptions.push(vscode.window.registerUriHandler({
handleUri(uri: vscode.Uri) {
Expand Down
22 changes: 15 additions & 7 deletions src/remoteConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getGitpodVersion, isFeatureSupported } from './featureSupport';
import SSHConfiguration from './ssh/sshConfig';
import { isWindows } from './common/platform';
import { untildify } from './common/files';
import { ExperimentalSettings } from './experiments';

interface SSHConnectionParams {
workspaceId: string;
Expand Down Expand Up @@ -118,7 +119,12 @@ export default class RemoteConnector extends Disposable {

private heartbeatManager: HeartbeatManager | undefined;

constructor(private readonly context: vscode.ExtensionContext, private readonly logger: Log, private readonly telemetry: TelemetryReporter) {
constructor(
private readonly context: vscode.ExtensionContext,
private readonly experiments: ExperimentalSettings,
private readonly logger: Log,
private readonly telemetry: TelemetryReporter
) {
super();

if (isGitpodRemoteWindow(context)) {
Expand Down Expand Up @@ -770,11 +776,13 @@ export default class RemoteConnector extends Disposable {

this.logger.info('Opening Gitpod workspace', uri.toString());

const userOverride = this.experiments.isUserOverride('gitpod.remote.useLocalApp');
const forceUseLocalApp = vscode.workspace.getConfiguration('gitpod').get<boolean>('remote.useLocalApp')!;
// const forceUseLocalApp = (await this.experiments.get<boolean>('gitpod.remote.useLocalApp', session.account.id))!;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable configcat for now before merging

let sshDestination: string | undefined;
if (!forceUseLocalApp) {
try {
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'connecting', ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'connecting', ...params, gitpodVersion: gitpodVersion.raw, userOverride });

const { destination, password } = await this.getWorkspaceSSHDestination(session.accessToken, params);
sshDestination = destination;
Expand All @@ -783,9 +791,9 @@ export default class RemoteConnector extends Disposable {
await this.showSSHPasswordModal(password, params);
}

this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'connected', ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'connected', ...params, gitpodVersion: gitpodVersion.raw, userOverride });
} catch (e) {
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'failed', reason: e.toString(), ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'gateway', status: 'failed', reason: e.toString(), ...params, gitpodVersion: gitpodVersion.raw, userOverride });
if (e instanceof NoSSHGatewayError) {
this.logger.error('No SSH gateway:', e);
vscode.window.showWarningMessage(`${e.host} does not support [direct SSH access](https://github.com/gitpod-io/gitpod/blob/main/install/installer/docs/workspace-ssh-access.md), connecting via the deprecated SSH tunnel over WebSocket.`);
Expand Down Expand Up @@ -817,15 +825,15 @@ export default class RemoteConnector extends Disposable {
let localAppSSHConfigPath: string | undefined;
if (!usingSSHGateway) {
try {
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'connecting', ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'connecting', ...params, gitpodVersion: gitpodVersion.raw, userOverride });

const localAppDestData = await this.getWorkspaceLocalAppSSHDestination(params);
sshDestination = localAppDestData.localAppSSHDest;
localAppSSHConfigPath = localAppDestData.localAppSSHConfigPath;

this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'connected', ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'connected', ...params, gitpodVersion: gitpodVersion.raw, userOverride });
} catch (e) {
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'failed', reason: e.toString(), ...params, gitpodVersion: gitpodVersion.raw });
this.telemetry.sendRawTelemetryEvent('vscode_desktop_ssh', { kind: 'local-app', status: 'failed', reason: e.toString(), ...params, gitpodVersion: gitpodVersion.raw, userOverride });
this.logger.error(`Failed to connect ${params.workspaceId} Gitpod workspace:`, e);
if (e instanceof LocalAppError) {
const seeLogs = 'See Logs';
Expand Down
Loading