From 067d6ae07e4bbf499a32ee4162ea979ff9921389 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 30 Jun 2021 00:54:04 -0700 Subject: [PATCH 1/5] Add telemetry for start/stop/setup cluster commands This PR fixes #1962. Signed-off-by: Denis Golovin dgolovin@redhat.com --- package.json | 27 +++++ src/webview/cluster/app/clusterView.tsx | 61 ++++++---- src/webview/cluster/clusterViewLoader.ts | 143 +++++++++++++++-------- 3 files changed, 158 insertions(+), 73 deletions(-) diff --git a/package.json b/package.json index 8a1cdd003..441b5c6cd 100644 --- a/package.json +++ b/package.json @@ -791,6 +791,21 @@ "title": "Open Add CRC Cluster Wizard", "category": "OpenShift" }, + { + "command": "openshift.explorer.addCluster.crcSetup", + "title": "Run CRC Setup Command", + "category": "OpenShift" + }, + { + "command": "openshift.explorer.addCluster.crcStart", + "title": "Run CRC Setup Command", + "category": "OpenShift" + }, + { + "command": "openshift.explorer.addCluster.crcStop", + "title": "Run CRC Setup Command", + "category": "OpenShift" + }, { "command": "openshift.component.revealContextInExplorer", "title": "Reveal in Explorer" @@ -1065,6 +1080,18 @@ "command": "openshift.explorer.addCluster.openCreateClusterPage", "when": "false" }, + { + "command": "openshift.explorer.addCluster.crcSetup", + "when": "false" + }, + { + "command": "openshift.explorer.addCluster.crcStart", + "when": "false" + }, + { + "command": "openshift.explorer.addCluster.crcStop", + "when": "false" + }, { "command": "openshift.component.revealInExplorer", "when": "false" diff --git a/src/webview/cluster/app/clusterView.tsx b/src/webview/cluster/app/clusterView.tsx index 5e9cbf769..5fa1f582f 100644 --- a/src/webview/cluster/app/clusterView.tsx +++ b/src/webview/cluster/app/clusterView.tsx @@ -84,15 +84,16 @@ export default function addClusterView(props) { const steps = getSteps(); const setCrcStatus = (message) => { - setStatus({ crcStatus: message.status.crcStatus, - openshiftStatus: message.status.openshiftStatus, - diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A', - cacheUsage: prettyBytes(message.status.cacheUsage), - cacheDir: message.status.cacheDir, - crcVer: message.versionInfo.version, - openshiftVer: message.versionInfo.openshiftVersion, - creds: message.creds - }); + setStatus({ + crcStatus: message.status.crcStatus, + openshiftStatus: message.status.openshiftStatus, + diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A', + cacheUsage: prettyBytes(message.status.cacheUsage), + cacheDir: message.status.cacheDir, + crcVer: message.versionInfo.version, + openshiftVer: message.versionInfo.openshiftVersion, + creds: message.creds + }); } const messageListener = (event) => { @@ -167,25 +168,41 @@ export default function addClusterView(props) { setProgress(true); setCrcStartError(false); if (settingPresent) { - props.vscode.postMessage({action: 'start', isSetting: true }); + props.vscode.postMessage({action: 'crcStart', isSetting: true }); } else { const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`: `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`; - props.vscode.postMessage({action: 'start', - data: crcStartCommand, - pullSecret: pullSecretPath, - crcLoc: fileName, - cpuSize, - memory, - isSetting: false - }); + props.vscode.postMessage({ + action: 'crcStart', + data: crcStartCommand, + pullSecret: pullSecretPath, + crcLoc: fileName, + cpuSize, + memory, + nameserver: crcNameserver, + isSetting: false + }); } } + const SaveSettings = 2; + + const handleSaveSettings = ()=> { + props.vscode.postMessage({ + action: 'crcSaveSettings', + pullSecret: pullSecretPath, + crcLoc: fileName, + cpuSize, + memory, + nameserver: crcNameserver + }); + } const handleNext = () => { if (activeStep === steps.length - 1) { handleStartProcess() + } else if (activeStep === SaveSettings) { + handleSaveSettings(); } setActiveStep((prevActiveStep) => prevActiveStep + 1); }; @@ -202,21 +219,21 @@ export default function addClusterView(props) { const handleStopProcess = () => { setStopProgress(true); setCrcStopError(false); - props.vscode.postMessage({action: 'stop', data: `${fileName}`}); + props.vscode.postMessage({action: 'crcStop', data: `${fileName}`}); } const handleCrcSetup = () => { - props.vscode.postMessage({action: 'run', data: `${fileName}` }) + props.vscode.postMessage({action: 'crcSetup', data: `${fileName}` }) } const handleCrcLogin = (loginDetails, clusterUrl) => { - props.vscode.postMessage({action: 'crclogin', data: loginDetails, url: clusterUrl }) + props.vscode.postMessage({action: 'crcLogin', data: loginDetails, url: clusterUrl }) } const handleRefresh = () => { setStatusSkeleton(true); if (settingPresent) { - props.scode.postMessage({action: 'checksetting'}); + props.vscode.postMessage({action: 'checksetting'}); } else { props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`}); } diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index 58a7ce9d6..edcffcb2c 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -15,17 +15,94 @@ let panel: vscode.WebviewPanel; const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs'); +interface ViewEvent { + action: string; +} + +interface OpenPageEvent extends ViewEvent { + params: { + url: string; + } +} + +interface CrcStartEvent extends ViewEvent { + data: string; + pullSecret: string; + crcLoc: string; + cpuSize: number; + memory: number; + isSetting: boolean; +} + async function clusterEditorMessageListener (event: any ): Promise { - if (['openLaunchSandboxPage', 'openCreateClusterPage', 'openCrcAddClusterPage'].includes(event.action)) { - await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event.params?.url); + switch (event.action) { + case 'openLaunchSandboxPage': + case 'openCreateClusterPage': + case 'openCrcAddClusterPage': + case 'crcSetup': + case 'crcStart': + case 'crcStop': + await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event); + break; + + case 'crcSaveSettings': + ClusterViewLoader.crcSaveSettings(event); + break; + + case 'checksetting': + const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'); + if (binaryFromSetting) { + panel.webview.postMessage({action: 'crcsetting'}); + ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel); + } + break; + + case 'checkcrcstatus': + ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel); + break + + case 'crcLogin': + vscode.commands.executeCommand( + 'openshift.explorer.login.credentialsLogin', + true, + event.url, + event.data.username, + event.data.password + ); + break; + } +} + +export default class ClusterViewLoader { + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + static get extensionPath() { + return vscode.extensions.getExtension(ExtenisonID).extensionPath } - if (event.action === 'run') { + @vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage') + static async openLaunchSandboxPage(url: string) { + await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); + } + + @vsCommand('openshift.explorer.addCluster.openCreateClusterPage') + static async openCreateClusterPage(url: string) { + await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); + } + + @vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage') + static async openCrcAddClusterPage() { + // fake command to report crc selection through telemetry + } + + @vsCommand('openshift.explorer.addCluster.crcSetup') + static async crcSetup(event: any) { const terminal: vscode.Terminal = WindowUtil.createTerminal('OpenShift: CRC Setup', undefined); terminal.sendText(`${event.data} setup`); terminal.show(); } - if (event.action === 'start') { + + @vsCommand('openshift.explorer.addCluster.crcStart') + static async crcStart(event: any) { let startProcess: ChildProcess; channel.show(); if (event.isSetting) { @@ -37,11 +114,6 @@ async function clusterEditorMessageListener (event: any ): Promise { startProcess = spawn(`${binaryFromSetting}`, crcOptions); channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`); } else { - const configuration = vscode.workspace.getConfiguration('openshiftConnector'); - configuration.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global); - configuration.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global); - configuration.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global); - configuration.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global); const [tool, ...params] = event.data.split(' '); startProcess = spawn(tool, params); channel.append(`\n\n${tool} ${params.join(' ')}\n`); @@ -64,7 +136,9 @@ async function clusterEditorMessageListener (event: any ): Promise { ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel); }); } - if (event.action === 'stop') { + + @vsCommand('openshift.explorer.addCluster.crcStop') + static async crcStop(event) { let filePath: string; channel.show(); if (event.data === '') { @@ -88,47 +162,14 @@ async function clusterEditorMessageListener (event: any ): Promise { ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel); }); } - if (event.action === 'checksetting') { - const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'); - if (binaryFromSetting) { - panel.webview.postMessage({action: 'crcsetting'}); - ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel); - } - } - if (event.action === 'checkcrcstatus') { - ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel); - } - if (event.action === 'crclogin') { - vscode.commands.executeCommand( - 'openshift.explorer.login.credentialsLogin', - true, - event.url, - event.data.username, - event.data.password - ); - } -} - -export default class ClusterViewLoader { - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - static get extensionPath() { - return vscode.extensions.getExtension(ExtenisonID).extensionPath - } - - @vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage') - static async openLaunchSandboxPage(url: string) { - await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); - } - - @vsCommand('openshift.explorer.addCluster.openCreateClusterPage') - static async openCreateClusterPage(url: string) { - await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); - } - - @vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage') - static async openCrcAddClusterPage(url: string) { - // fake command to report crc selection through telemetry + static async crcSaveSettings(event) { + const cfg = vscode.workspace.getConfiguration('openshiftConnector'); + await cfg.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global); + await cfg.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global); + await cfg.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global); + await cfg.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global); + await cfg.update('crcNameserver', event.nameserver); } // eslint-disable-next-line @typescript-eslint/require-await @@ -193,7 +234,7 @@ export default class ClusterViewLoader { const htmlString:Buffer = fs.readFileSync(path.join(reactAppRootOnDisk, 'index.html')); const meta = ``; From 686a1f8bcaaf933ae4e907429d7a124ca469b9db Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 30 Jun 2021 11:28:00 -0700 Subject: [PATCH 2/5] Fix esling issues Signed-off-by: Denis Golovin dgolovin@redhat.com --- src/webview/cluster/clusterViewLoader.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index edcffcb2c..453600d8f 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -19,6 +19,7 @@ interface ViewEvent { action: string; } +/* interface OpenPageEvent extends ViewEvent { params: { url: string; @@ -33,7 +34,7 @@ interface CrcStartEvent extends ViewEvent { memory: number; isSetting: boolean; } - +*/ async function clusterEditorMessageListener (event: any ): Promise { switch (event.action) { case 'openLaunchSandboxPage': @@ -158,7 +159,7 @@ export default class ClusterViewLoader { }); stopProcess.on('close', (code) => { // eslint-disable-next-line no-console - console.log(`crc stop exited with code ${code}`); + console.log(`crc stop exited with code ${code}`);Adult Krav Maga 6pm ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel); }); } From 2ff8153eb5a886322fc8a7deebd1efcfbe8432e6 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 30 Jun 2021 13:55:01 -0700 Subject: [PATCH 3/5] Remove accidental change Signed-off-by: Denis Golovin dgolovin@redhat.com --- src/webview/cluster/clusterViewLoader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index 453600d8f..2f5290766 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -159,7 +159,7 @@ export default class ClusterViewLoader { }); stopProcess.on('close', (code) => { // eslint-disable-next-line no-console - console.log(`crc stop exited with code ${code}`);Adult Krav Maga 6pm + console.log(`crc stop exited with code ${code}`); ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel); }); } From b5de410267b53a1cfc0913b13d30c4b8f2c8fb0c Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 30 Jun 2021 13:57:34 -0700 Subject: [PATCH 4/5] Fix eslint error Signed-off-by: Denis Golovin dgolovin@redhat.com --- src/webview/cluster/clusterViewLoader.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index 2f5290766..ddc6c2783 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -15,11 +15,12 @@ let panel: vscode.WebviewPanel; const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs'); +/* interface ViewEvent { action: string; } -/* + interface OpenPageEvent extends ViewEvent { params: { url: string; From 5e1322e37ec1695793ea5523efd3bdc5bc8457ef Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 30 Jun 2021 14:13:19 -0700 Subject: [PATCH 5/5] Remove test code from clusterViewLoader.ts Signed-off-by: Denis Golovin dgolovin@redhat.com --- src/webview/cluster/clusterViewLoader.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index ddc6c2783..fd8924ae2 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -235,8 +235,8 @@ export default class ClusterViewLoader { const reactAppUri = p.webview.asWebviewUri(reactAppPathOnDisk); const htmlString:Buffer = fs.readFileSync(path.join(reactAppRootOnDisk, 'index.html')); const meta = ``;