Skip to content

Commit c1baa42

Browse files
authored
Add telemetry for start/stop/setup cluster commands (#2183)
Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent 7f4f2bb commit c1baa42

File tree

3 files changed

+160
-73
lines changed

3 files changed

+160
-73
lines changed

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,21 @@
791791
"title": "Open Add CRC Cluster Wizard",
792792
"category": "OpenShift"
793793
},
794+
{
795+
"command": "openshift.explorer.addCluster.crcSetup",
796+
"title": "Run CRC Setup Command",
797+
"category": "OpenShift"
798+
},
799+
{
800+
"command": "openshift.explorer.addCluster.crcStart",
801+
"title": "Run CRC Setup Command",
802+
"category": "OpenShift"
803+
},
804+
{
805+
"command": "openshift.explorer.addCluster.crcStop",
806+
"title": "Run CRC Setup Command",
807+
"category": "OpenShift"
808+
},
794809
{
795810
"command": "openshift.component.revealContextInExplorer",
796811
"title": "Reveal in Explorer"
@@ -1065,6 +1080,18 @@
10651080
"command": "openshift.explorer.addCluster.openCreateClusterPage",
10661081
"when": "false"
10671082
},
1083+
{
1084+
"command": "openshift.explorer.addCluster.crcSetup",
1085+
"when": "false"
1086+
},
1087+
{
1088+
"command": "openshift.explorer.addCluster.crcStart",
1089+
"when": "false"
1090+
},
1091+
{
1092+
"command": "openshift.explorer.addCluster.crcStop",
1093+
"when": "false"
1094+
},
10681095
{
10691096
"command": "openshift.component.revealInExplorer",
10701097
"when": "false"

src/webview/cluster/app/clusterView.tsx

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ export default function addClusterView(props) {
8484
const steps = getSteps();
8585

8686
const setCrcStatus = (message) => {
87-
setStatus({ crcStatus: message.status.crcStatus,
88-
openshiftStatus: message.status.openshiftStatus,
89-
diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A',
90-
cacheUsage: prettyBytes(message.status.cacheUsage),
91-
cacheDir: message.status.cacheDir,
92-
crcVer: message.versionInfo.version,
93-
openshiftVer: message.versionInfo.openshiftVersion,
94-
creds: message.creds
95-
});
87+
setStatus({
88+
crcStatus: message.status.crcStatus,
89+
openshiftStatus: message.status.openshiftStatus,
90+
diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A',
91+
cacheUsage: prettyBytes(message.status.cacheUsage),
92+
cacheDir: message.status.cacheDir,
93+
crcVer: message.versionInfo.version,
94+
openshiftVer: message.versionInfo.openshiftVersion,
95+
creds: message.creds
96+
});
9697
}
9798

9899
const messageListener = (event) => {
@@ -167,25 +168,41 @@ export default function addClusterView(props) {
167168
setProgress(true);
168169
setCrcStartError(false);
169170
if (settingPresent) {
170-
props.vscode.postMessage({action: 'start', isSetting: true });
171+
props.vscode.postMessage({action: 'crcStart', isSetting: true });
171172
} else {
172173
const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`:
173174
`${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`;
174175

175-
props.vscode.postMessage({action: 'start',
176-
data: crcStartCommand,
177-
pullSecret: pullSecretPath,
178-
crcLoc: fileName,
179-
cpuSize,
180-
memory,
181-
isSetting: false
182-
});
176+
props.vscode.postMessage({
177+
action: 'crcStart',
178+
data: crcStartCommand,
179+
pullSecret: pullSecretPath,
180+
crcLoc: fileName,
181+
cpuSize,
182+
memory,
183+
nameserver: crcNameserver,
184+
isSetting: false
185+
});
183186
}
184187
}
188+
const SaveSettings = 2;
189+
190+
const handleSaveSettings = ()=> {
191+
props.vscode.postMessage({
192+
action: 'crcSaveSettings',
193+
pullSecret: pullSecretPath,
194+
crcLoc: fileName,
195+
cpuSize,
196+
memory,
197+
nameserver: crcNameserver
198+
});
199+
}
185200

186201
const handleNext = () => {
187202
if (activeStep === steps.length - 1) {
188203
handleStartProcess()
204+
} else if (activeStep === SaveSettings) {
205+
handleSaveSettings();
189206
}
190207
setActiveStep((prevActiveStep) => prevActiveStep + 1);
191208
};
@@ -202,21 +219,21 @@ export default function addClusterView(props) {
202219
const handleStopProcess = () => {
203220
setStopProgress(true);
204221
setCrcStopError(false);
205-
props.vscode.postMessage({action: 'stop', data: `${fileName}`});
222+
props.vscode.postMessage({action: 'crcStop', data: `${fileName}`});
206223
}
207224

208225
const handleCrcSetup = () => {
209-
props.vscode.postMessage({action: 'run', data: `${fileName}` })
226+
props.vscode.postMessage({action: 'crcSetup', data: `${fileName}` })
210227
}
211228

212229
const handleCrcLogin = (loginDetails, clusterUrl) => {
213-
props.vscode.postMessage({action: 'crclogin', data: loginDetails, url: clusterUrl })
230+
props.vscode.postMessage({action: 'crcLogin', data: loginDetails, url: clusterUrl })
214231
}
215232

216233
const handleRefresh = () => {
217234
setStatusSkeleton(true);
218235
if (settingPresent) {
219-
props.scode.postMessage({action: 'checksetting'});
236+
props.vscode.postMessage({action: 'checksetting'});
220237
} else {
221238
props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
222239
}

src/webview/cluster/clusterViewLoader.ts

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,96 @@ let panel: vscode.WebviewPanel;
1515

1616
const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs');
1717

18+
/*
19+
interface ViewEvent {
20+
action: string;
21+
}
22+
23+
24+
interface OpenPageEvent extends ViewEvent {
25+
params: {
26+
url: string;
27+
}
28+
}
29+
30+
interface CrcStartEvent extends ViewEvent {
31+
data: string;
32+
pullSecret: string;
33+
crcLoc: string;
34+
cpuSize: number;
35+
memory: number;
36+
isSetting: boolean;
37+
}
38+
*/
1839
async function clusterEditorMessageListener (event: any ): Promise<any> {
19-
if (['openLaunchSandboxPage', 'openCreateClusterPage', 'openCrcAddClusterPage'].includes(event.action)) {
20-
await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event.params?.url);
40+
switch (event.action) {
41+
case 'openLaunchSandboxPage':
42+
case 'openCreateClusterPage':
43+
case 'openCrcAddClusterPage':
44+
case 'crcSetup':
45+
case 'crcStart':
46+
case 'crcStop':
47+
await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event);
48+
break;
49+
50+
case 'crcSaveSettings':
51+
ClusterViewLoader.crcSaveSettings(event);
52+
break;
53+
54+
case 'checksetting':
55+
const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
56+
if (binaryFromSetting) {
57+
panel.webview.postMessage({action: 'crcsetting'});
58+
ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel);
59+
}
60+
break;
61+
62+
case 'checkcrcstatus':
63+
ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel);
64+
break
65+
66+
case 'crcLogin':
67+
vscode.commands.executeCommand(
68+
'openshift.explorer.login.credentialsLogin',
69+
true,
70+
event.url,
71+
event.data.username,
72+
event.data.password
73+
);
74+
break;
75+
}
76+
}
77+
78+
export default class ClusterViewLoader {
79+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
80+
static get extensionPath() {
81+
return vscode.extensions.getExtension(ExtenisonID).extensionPath
2182
}
2283

23-
if (event.action === 'run') {
84+
@vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage')
85+
static async openLaunchSandboxPage(url: string) {
86+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
87+
}
88+
89+
@vsCommand('openshift.explorer.addCluster.openCreateClusterPage')
90+
static async openCreateClusterPage(url: string) {
91+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
92+
}
93+
94+
@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
95+
static async openCrcAddClusterPage() {
96+
// fake command to report crc selection through telemetry
97+
}
98+
99+
@vsCommand('openshift.explorer.addCluster.crcSetup')
100+
static async crcSetup(event: any) {
24101
const terminal: vscode.Terminal = WindowUtil.createTerminal('OpenShift: CRC Setup', undefined);
25102
terminal.sendText(`${event.data} setup`);
26103
terminal.show();
27104
}
28-
if (event.action === 'start') {
105+
106+
@vsCommand('openshift.explorer.addCluster.crcStart')
107+
static async crcStart(event: any) {
29108
let startProcess: ChildProcess;
30109
channel.show();
31110
if (event.isSetting) {
@@ -37,11 +116,6 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
37116
startProcess = spawn(`${binaryFromSetting}`, crcOptions);
38117
channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`);
39118
} else {
40-
const configuration = vscode.workspace.getConfiguration('openshiftConnector');
41-
configuration.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global);
42-
configuration.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global);
43-
configuration.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global);
44-
configuration.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global);
45119
const [tool, ...params] = event.data.split(' ');
46120
startProcess = spawn(tool, params);
47121
channel.append(`\n\n${tool} ${params.join(' ')}\n`);
@@ -64,7 +138,9 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
64138
ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel);
65139
});
66140
}
67-
if (event.action === 'stop') {
141+
142+
@vsCommand('openshift.explorer.addCluster.crcStop')
143+
static async crcStop(event) {
68144
let filePath: string;
69145
channel.show();
70146
if (event.data === '') {
@@ -88,47 +164,14 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
88164
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
89165
});
90166
}
91-
if (event.action === 'checksetting') {
92-
const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
93-
if (binaryFromSetting) {
94-
panel.webview.postMessage({action: 'crcsetting'});
95-
ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel);
96-
}
97-
}
98-
if (event.action === 'checkcrcstatus') {
99-
ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel);
100-
}
101167

102-
if (event.action === 'crclogin') {
103-
vscode.commands.executeCommand(
104-
'openshift.explorer.login.credentialsLogin',
105-
true,
106-
event.url,
107-
event.data.username,
108-
event.data.password
109-
);
110-
}
111-
}
112-
113-
export default class ClusterViewLoader {
114-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
115-
static get extensionPath() {
116-
return vscode.extensions.getExtension(ExtenisonID).extensionPath
117-
}
118-
119-
@vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage')
120-
static async openLaunchSandboxPage(url: string) {
121-
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
122-
}
123-
124-
@vsCommand('openshift.explorer.addCluster.openCreateClusterPage')
125-
static async openCreateClusterPage(url: string) {
126-
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
127-
}
128-
129-
@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
130-
static async openCrcAddClusterPage(url: string) {
131-
// fake command to report crc selection through telemetry
168+
static async crcSaveSettings(event) {
169+
const cfg = vscode.workspace.getConfiguration('openshiftConnector');
170+
await cfg.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global);
171+
await cfg.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global);
172+
await cfg.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global);
173+
await cfg.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global);
174+
await cfg.update('crcNameserver', event.nameserver);
132175
}
133176

134177
// eslint-disable-next-line @typescript-eslint/require-await
@@ -192,7 +235,7 @@ export default class ClusterViewLoader {
192235
const reactAppUri = p.webview.asWebviewUri(reactAppPathOnDisk);
193236
const htmlString:Buffer = fs.readFileSync(path.join(reactAppRootOnDisk, 'index.html'));
194237
const meta = `<meta http-equiv="Content-Security-Policy"
195-
content="connect-src *;
238+
content="connect-src *;
196239
default-src 'none';
197240
img-src ${p.webview.cspSource} https: 'self' data:;
198241
script-src 'unsafe-eval' 'unsafe-inline' vscode-resource:;

0 commit comments

Comments
 (0)