Skip to content

Commit 3628b6d

Browse files
committed
💄
1 parent 97902a3 commit 3628b6d

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
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?: 'on' | 'off';
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-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as fs from 'fs';
1010
import * as os from 'os';
1111
import * as uuid from 'uuid';
1212
import { GitpodPluginModel, GitpodExtensionContext, setupGitpodContext, registerTasks, registerIpcHookCli } from 'gitpod-shared';
13+
import { TEAM_IDS_ATTRIBUTE } from '@gitpod/gitpod-protocol/lib/experiments/configcat';
1314
import { GetTokenRequest } from '@gitpod/supervisor-api-grpc/lib/token_pb';
1415
import { PortsStatus, ExposedPortInfo, PortsStatusRequest, PortsStatusResponse, PortVisibility, OnPortExposedAction } from '@gitpod/supervisor-api-grpc/lib/status_pb';
1516
import { TunnelVisiblity, TunnelPortRequest, RetryAutoExposeRequest, CloseTunnelRequest } from '@gitpod/supervisor-api-grpc/lib/port_pb';
@@ -498,6 +499,10 @@ class GitpodPortViewProvider implements vscode.WebviewViewProvider {
498499
if (!port) { return; }
499500
if (message.command === 'urlCopy' && port.status.exposed) {
500501
await vscode.env.clipboard.writeText(port.status.exposed.url);
502+
this.context.fireAnalyticsEvent({
503+
eventName: 'vscode_execute_command_gitpod_ports',
504+
properties: { action: 'urlCopy', isWebview: true, userOverride: isUserOverrideSetting('gitpod.experimental.portsView.enabled') ? 'on' : 'off' }
505+
});
501506
return;
502507
}
503508
vscode.commands.executeCommand('gitpod.ports.' + message.command, { port, isWebview: true });
@@ -585,18 +590,12 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
585590

586591
const isSaaSGitpod = context.info.getGitpodHost() === 'https://gitpod.io';
587592
async function getPortsViewExperimentEnable(): Promise<boolean> {
588-
const isEnabled = isSaaSGitpod
589-
? (await experiments.get<boolean>('gitpod.experimental.portsView.enabled', (await context.user).id))!
593+
594+
return isSaaSGitpod
595+
? (await experiments.get<boolean>('gitpod.experimental.portsView.enabled', (await context.user).id, {
596+
[TEAM_IDS_ATTRIBUTE]: (await context.userTeams).map(e => e.id).join(','),
597+
}))!
590598
: 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;
600599
}
601600

602601
context.subscriptions.push(observePortsStatus());
@@ -638,14 +637,14 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
638637
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePrivate', ({ port, isWebview }: PortItem) => {
639638
context.fireAnalyticsEvent({
640639
eventName: 'vscode_execute_command_gitpod_ports',
641-
properties: { action: 'private', isWebview: !!isWebview }
640+
properties: { action: 'private', isWebview: !!isWebview, userOverride: isUserOverrideSetting('gitpod.experimental.portsView.enabled') ? 'on' : 'off' }
642641
});
643642
return port.setPortVisibility('private');
644643
}));
645644
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePublic', ({ port, isWebview }: PortItem) => {
646645
context.fireAnalyticsEvent({
647646
eventName: 'vscode_execute_command_gitpod_ports',
648-
properties: { action: 'public', isWebview: !!isWebview }
647+
properties: { action: 'public', isWebview: !!isWebview, userOverride: isUserOverrideSetting('gitpod.experimental.portsView.enabled') ? 'on' : 'off' }
649648
});
650649
return port.setPortVisibility('public');
651650
}));
@@ -658,14 +657,14 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
658657
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.preview', ({ port, isWebview }: PortItem) => {
659658
context.fireAnalyticsEvent({
660659
eventName: 'vscode_execute_command_gitpod_ports',
661-
properties: { action: 'preview', isWebview: !!isWebview }
660+
properties: { action: 'preview', isWebview: !!isWebview, userOverride: isUserOverrideSetting('gitpod.experimental.portsView.enabled') ? 'on' : 'off' }
662661
});
663662
return openPreview(port);
664663
}));
665664
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.openBrowser', ({ port, isWebview }: PortItem) => {
666665
context.fireAnalyticsEvent({
667666
eventName: 'vscode_execute_command_gitpod_ports',
668-
properties: { action: 'openBrowser', isWebview: !!isWebview }
667+
properties: { action: 'openBrowser', isWebview: !!isWebview, userOverride: isUserOverrideSetting('gitpod.experimental.portsView.enabled') ? 'on' : 'off' }
669668
});
670669
return openExternal(port);
671670
}));

0 commit comments

Comments
 (0)