Skip to content

Commit 3ccbb66

Browse files
committed
💄
1 parent 97902a3 commit 3ccbb66

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

extensions/gitpod-shared/src/analytics.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export type GitpodAnalyticsEvent =
3838
action: 'share' | 'stop-sharing' | 'stop' | 'snapshot' | 'extend-timeout';
3939
}> |
4040
GAET<'vscode_execute_command_gitpod_ports', {
41-
action: 'private' | 'public' | 'preview' | 'openBrowser';
41+
action: 'private' | 'public' | 'preview' | 'openBrowser' | 'urlCopy';
4242
isWebview?: boolean;
43+
userOverride?: string; // 'true' | 'false'
4344
}> |
4445
GAET<'vscode_execute_command_gitpod_config', {
4546
action: 'remove' | 'add';
@@ -49,9 +50,6 @@ export type GitpodAnalyticsEvent =
4950
}> |
5051
GAET<'ide_close_signal', {
5152
clientKind: 'vscode';
52-
}> |
53-
GAET<'vscode_experimental_ports_view', {
54-
enabled: boolean; userOverride: boolean;
5553
}>;
5654

5755
export function registerUsageAnalytics(context: GitpodExtensionContext): void {

extensions/gitpod-shared/src/features.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require('reflect-metadata');
88
import { GitpodClient, GitpodServer, GitpodServiceImpl, WorkspaceInstanceUpdateListener } from '@gitpod/gitpod-protocol/lib/gitpod-service';
99
import { JsonRpcProxyFactory } from '@gitpod/gitpod-protocol/lib/messaging/proxy-factory';
1010
import { NavigatorContext, User } from '@gitpod/gitpod-protocol/lib/protocol';
11+
import { Team } from '@gitpod/gitpod-protocol/lib/teams-projects-protocol';
1112
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error';
1213
import { GitpodHostUrl } from '@gitpod/gitpod-protocol/lib/util/gitpod-host-url';
1314
import { ControlServiceClient } from '@gitpod/supervisor-api-grpc/lib/control_grpc_pb';
@@ -70,7 +71,7 @@ export class SupervisorConnection {
7071
}
7172
}
7273

73-
type UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
74+
type UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent', 'getTeams'];
7475
type Union<Tuple extends any[], Union = never> = Tuple[number] | Union;
7576
export type GitpodConnection = Omit<GitpodServiceImpl<GitpodClient, GitpodServer>, 'server'> & {
7677
server: Pick<GitpodServer, Union<UsedGitpodFunction>>;
@@ -93,6 +94,7 @@ export class GitpodExtensionContext implements vscode.ExtensionContext {
9394
readonly info: WorkspaceInfoResponse,
9495
readonly owner: Promise<User>,
9596
readonly user: Promise<User>,
97+
readonly userTeams: Promise<Team[]>,
9698
readonly instanceListener: Promise<WorkspaceInstanceUpdateListener>,
9799
readonly workspaceOwned: Promise<boolean>,
98100
readonly logger: Log,
@@ -241,7 +243,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
241243
const gitpodApi = workspaceInfo.getGitpodApi()!;
242244

243245
const factory = new JsonRpcProxyFactory<GitpodServer>();
244-
const gitpodFunctions: UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
246+
const gitpodFunctions: UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent', 'getTeams'];
245247
const gitpodService: GitpodConnection = new GitpodServiceImpl<GitpodClient, GitpodServer>(factory.createProxy()) as any;
246248
const gitpodScopes = new Set<string>([
247249
'resource:workspace::' + workspaceId + '::get/update',
@@ -302,6 +304,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
302304
}
303305
return vscode.commands.executeCommand('gitpod.api.getLoggedInUser') as typeof pendingGetOwner;
304306
})();
307+
const pendingGetUserTeams = gitpodService.server.getTeams();
305308
const pendingInstanceListener = gitpodService.listenToInstance(workspaceId);
306309
const pendingWorkspaceOwned = (async () => {
307310
const owner = await pendingGetOwner;
@@ -325,6 +328,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
325328
workspaceInfo,
326329
pendingGetOwner,
327330
pendingGetUser,
331+
pendingGetUserTeams,
328332
pendingInstanceListener,
329333
pendingWorkspaceOwned,
330334
logger,

extensions/gitpod-web/src/experiments.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ExperimentalSettings {
3131
this.extensionVersion = new semver.SemVer(extensionVersion);
3232
}
3333

34-
async get<T>(key: string, userId?: string): Promise<T | undefined> {
34+
async get<T>(key: string, userId?: string, custom?: { [key: string]: string }): Promise<T | undefined> {
3535
const config = vscode.workspace.getConfiguration('gitpod');
3636
const values = config.inspect<T>(key.substring('gitpod.'.length));
3737
if (!values || !EXPERTIMENTAL_SETTINGS.includes(key)) {
@@ -47,22 +47,22 @@ export class ExperimentalSettings {
4747
return values.globalValue;
4848
}
4949

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

5454
return experimentValue ?? values.defaultValue;
5555
}
5656

57-
async inspect<T>(key: string, userId?: string): Promise<{ key: string; defaultValue?: T; globalValue?: T; experimentValue?: T } | undefined> {
57+
async inspect<T>(key: string, userId?: string, custom?: { [key: string]: string }): Promise<{ key: string; defaultValue?: T; globalValue?: T; experimentValue?: T } | undefined> {
5858
const config = vscode.workspace.getConfiguration('gitpod');
5959
const values = config.inspect<T>(key.substring('gitpod.'.length));
6060
if (!values || !EXPERTIMENTAL_SETTINGS.includes(key)) {
6161
this.logger.error(`Cannot inspect invalid experimental setting '${key}'`);
6262
return values;
6363
}
6464

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

extensions/gitpod-web/src/extension.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ class GitpodPortViewProvider implements vscode.WebviewViewProvider {
498498
if (!port) { return; }
499499
if (message.command === 'urlCopy' && port.status.exposed) {
500500
await vscode.env.clipboard.writeText(port.status.exposed.url);
501+
this.context.fireAnalyticsEvent({
502+
eventName: 'vscode_execute_command_gitpod_ports',
503+
properties: { action: 'urlCopy', isWebview: true, userOverride: String(isUserOverrideSetting('gitpod.experimental.portsView.enabled')) }
504+
});
501505
return;
502506
}
503507
vscode.commands.executeCommand('gitpod.ports.' + message.command, { port, isWebview: true });
@@ -580,23 +584,17 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
580584
}
581585

582586
const packageJSON = context.extension.packageJSON;
583-
const experiments = new ExperimentalSettings(packageJSON.configcatKey, packageJSON.version, context.logger);
587+
const experiments = new ExperimentalSettings(process.env['GITPOD_CONFIGCAT_SDK_KEY'] ?? packageJSON.configcatKey, packageJSON.version, context.logger);
584588
context.subscriptions.push(experiments);
585589

586590
const isSaaSGitpod = context.info.getGitpodHost() === 'https://gitpod.io';
587591
async function getPortsViewExperimentEnable(): Promise<boolean> {
588-
const isEnabled = isSaaSGitpod
589-
? (await experiments.get<boolean>('gitpod.experimental.portsView.enabled', (await context.user).id))!
592+
593+
return isSaaSGitpod
594+
? (await experiments.get<boolean>('gitpod.experimental.portsView.enabled', (await context.user).id, {
595+
team_ids: (await context.userTeams).map(e => e.id).join(','),
596+
}))!
590597
: vscode.workspace.getConfiguration('gitpod').get<boolean>('experimental.portsView.enabled')!;
591-
const userOverride = isUserOverrideSetting('gitpod.remote.useLocalApp');
592-
context.fireAnalyticsEvent({
593-
eventName: 'vscode_experimental_ports_view',
594-
properties: {
595-
enabled: isEnabled,
596-
userOverride,
597-
}
598-
});
599-
return isEnabled;
600598
}
601599

602600
context.subscriptions.push(observePortsStatus());
@@ -638,14 +636,14 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
638636
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePrivate', ({ port, isWebview }: PortItem) => {
639637
context.fireAnalyticsEvent({
640638
eventName: 'vscode_execute_command_gitpod_ports',
641-
properties: { action: 'private', isWebview: !!isWebview }
639+
properties: { action: 'private', isWebview: !!isWebview, userOverride: String(isUserOverrideSetting('gitpod.experimental.portsView.enabled')) }
642640
});
643641
return port.setPortVisibility('private');
644642
}));
645643
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePublic', ({ port, isWebview }: PortItem) => {
646644
context.fireAnalyticsEvent({
647645
eventName: 'vscode_execute_command_gitpod_ports',
648-
properties: { action: 'public', isWebview: !!isWebview }
646+
properties: { action: 'public', isWebview: !!isWebview, userOverride: String(isUserOverrideSetting('gitpod.experimental.portsView.enabled')) }
649647
});
650648
return port.setPortVisibility('public');
651649
}));
@@ -658,14 +656,14 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
658656
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.preview', ({ port, isWebview }: PortItem) => {
659657
context.fireAnalyticsEvent({
660658
eventName: 'vscode_execute_command_gitpod_ports',
661-
properties: { action: 'preview', isWebview: !!isWebview }
659+
properties: { action: 'preview', isWebview: !!isWebview, userOverride: String(isUserOverrideSetting('gitpod.experimental.portsView.enabled')) }
662660
});
663661
return openPreview(port);
664662
}));
665663
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.openBrowser', ({ port, isWebview }: PortItem) => {
666664
context.fireAnalyticsEvent({
667665
eventName: 'vscode_execute_command_gitpod_ports',
668-
properties: { action: 'openBrowser', isWebview: !!isWebview }
666+
properties: { action: 'openBrowser', isWebview: !!isWebview, userOverride: String(isUserOverrideSetting('gitpod.experimental.portsView.enabled')) }
669667
});
670668
return openExternal(port);
671669
}));

0 commit comments

Comments
 (0)