Skip to content

Commit

Permalink
feat: Add basic telemetry support
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
  • Loading branch information
GordonSmith committed May 14, 2022
1 parent 21eb200 commit d451cd2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 30 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 24 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@typescript-eslint/parser": "5.23.0",
"@vscode/debugadapter": "1.55.1",
"@vscode/debugprotocol": "1.55.1",
"@vscode/extension-telemetry": "0.5.1",
"adm-zip": "0.5.9",
"antlr4": "~4.9.3",
"assert": "2.0.0",
Expand Down Expand Up @@ -863,7 +864,7 @@
"properties": {
"ecl.eclccArgs": {
"type": "array",
"scope": "resource",
"scope": "application",
"items": {
"type": "string"
},
Expand All @@ -872,7 +873,7 @@
},
"ecl.eclccSyntaxArgs": {
"type": "array",
"scope": "resource",
"scope": "application",
"items": {
"type": "string"
},
Expand All @@ -881,31 +882,31 @@
},
"ecl.syntaxCheckOnSave": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": true,
"description": "%Run 'eclcc -syntax' on save%"
},
"ecl.syntaxCheckOnLoad": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": true,
"description": "%Run 'eclcc -syntax' on load%"
},
"ecl.saveOnSyntaxCheck": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Save file prior to syntax check%"
},
"ecl.saveOnSubmit": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Save file prior to submission%"
},
"ecl.includeFolders": {
"type": "array",
"scope": "resource",
"scope": "application",
"items": {
"type": "string"
},
Expand All @@ -914,19 +915,19 @@
},
"ecl.eclccPath": {
"type": "string",
"scope": "resource",
"scope": "application",
"default": "",
"description": "%Override eclcc auto detection%"
},
"ecl.eclccLogFile": {
"type": "string",
"scope": "resource",
"scope": "application",
"default": "",
"description": "%Write eclcc log file to specified file%"
},
"ecl.legacyMode": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Add '-legacy' argument to eclcc%"
},
Expand All @@ -938,37 +939,37 @@
},
"ecl.launchConfiguration": {
"type": "string",
"scope": "resource",
"scope": "application",
"default": "",
"description": "%Default launch configuration%"
},
"ecl.targetCluster": {
"type": "object",
"scope": "resource",
"scope": "application",
"default": {},
"description": "%Target cluster (per launch configuration)%"
},
"ecl.pinnedLaunchConfigurations": {
"type": "object",
"scope": "resource",
"scope": "application",
"default": {},
"description": "%Pinned launch configurations%"
},
"ecl.WUAutoOpen": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Automatically open Workunits on creation%"
},
"ecl.forceProxySupport": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Force global 'proxySupport' to 'fallback'%"
},
"dashy.libraryLocation": {
"type": "string",
"scope": "resource",
"scope": "application",
"enum": [
"latest",
"localPath"
Expand All @@ -978,7 +979,7 @@
},
"dashy.localPath": {
"type": "string",
"scope": "resource",
"scope": "application",
"default": "",
"description": "%Dashy Library Path (libraryLocation === \"localPath\")%"
},
Expand All @@ -992,19 +993,19 @@
},
"kel.kelPath": {
"type": "string",
"scope": "resource",
"scope": "application",
"default": "",
"description": "%Override KEL auto detection%"
},
"kel.syntaxCheckOnSave": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": true,
"description": "%Check syntax on save%"
},
"kel.generateLocation": {
"type": "string",
"scope": "resource",
"scope": "application",
"enum": [
"Same Folder",
"Child Folder"
Expand All @@ -1014,19 +1015,19 @@
},
"kel.generateOnSave": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Generate ECL on save%"
},
"kel.syntaxCheckOnLoad": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": true,
"description": "%Check syntax on load%"
},
"kel.syntaxCheckFromGrammar": {
"type": "boolean",
"scope": "resource",
"scope": "application",
"default": false,
"description": "%Check syntax with KEL grammar (fast)%"
}
Expand Down
24 changes: 18 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { ExtensionContext } from "vscode";
import * as vscode from "vscode";
import { initialize } from "./util/localize";
import { activate as telemetryActivate, deactivate as telemetryDeactivate, reporter } from "./telemetry";

export function activate(context: vscode.ExtensionContext): void {
performance.mark("extension-start");
telemetryActivate(context);

export function activate(ctx: ExtensionContext): void {
initialize().then(() => {
import("./ecl/main").then(({ activate }) => activate(ctx));
import("./notebook/main").then(({ activate }) => activate(ctx));
import("./kel/main").then(({ activate }) => activate(ctx));
import("./dashy/main").then(({ activate }) => activate(ctx));
return Promise.all([
import("./ecl/main").then(({ activate }) => activate(context)),
import("./notebook/main").then(({ activate }) => activate(context)),
import("./kel/main").then(({ activate }) => activate(context)),
import("./dashy/main").then(({ activate }) => activate(context))
]);
}).then(() => {
reporter.sendTelemetryEvent("initialized");
});
}

export function deactivate(): void {
telemetryDeactivate();
}
17 changes: 17 additions & 0 deletions src/hpccplatform/launchConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LaunchConfigState, LaunchMode, LaunchProtocol, LaunchRequestArguments }
import { showEclStatus } from "../ecl/clientTools";
import localize from "../util/localize";
import { readFile } from "../util/fs";
import { reporter } from "../telemetry";

const fs = vscode.workspace.fs;

Expand Down Expand Up @@ -466,6 +467,7 @@ export class LaunchConfig implements LaunchRequestArguments {
}

checkSyntax(fileUri: vscode.Uri): Promise<CheckResponse> {
reporter.sendTelemetryEvent("launchConfig.checkSyntax.start");
return this.locateClientTools(fileUri).then(clientTools => {
if (!clientTools) {
throw new Error();
Expand All @@ -476,9 +478,11 @@ export class LaunchConfig implements LaunchRequestArguments {
logger.warning(`syntaxCheck-warning: ${fileUri.fsPath} ${errors.unknown().toString()}`);
}
logger.debug(`syntaxCheck-resolve: ${fileUri.fsPath} ${errors.errors().length} total.`);
reporter.sendTelemetryEvent("launchConfig.checkSyntax.success", {}, { "errorCount": errors.all().length });
return { errors: errors.all(), checked: errors.checked() };
}).catch(e => {
logger.debug(`syntaxCheck-reject: ${fileUri.fsPath} ${e.msg}`);
reporter.sendTelemetryErrorEvent("launchConfig.checkSyntax.fail", { "message": e?.msg });
vscode.window.showInformationMessage(`${localize("Syntax check exception")}: ${fileUri.fsPath} ${e.msg}`);
return Promise.resolve({ errors: [], checked: [] });
});
Expand Down Expand Up @@ -627,6 +631,7 @@ export class LaunchConfig implements LaunchRequestArguments {
async submit(fileUri: vscode.Uri, targetCluster: string, mode: LaunchMode) {
// const args = await this.localResolveDebugConfiguration(filePath);
// logger.debug("launchRequest: " + JSON.stringify(args));
reporter.sendTelemetryEvent("launchConfig.submit.start");
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: localize("Submit ECL"),
Expand All @@ -636,31 +641,38 @@ export class LaunchConfig implements LaunchRequestArguments {
logger.info(`Fetch build version.${os.EOL}`);
const pathParts = path.parse(filePath);
let failedWU: Workunit;
reporter.sendTelemetryEvent("launchConfig.submit.fetchBuild");
return this.fetchBuild().then(build => {
progress.report({ increment: 10, message: localize("Locating Client Tools") });
logger.info(`Locating Client Tools.${os.EOL}`);
reporter.sendTelemetryEvent("launchConfig.submit.locateClientTools");
return this.locateClientTools(fileUri, build);
}).then((clientTools) => {
progress.report({ increment: 10, message: localize("Creating Archive") });
logger.info(`Client Tools: ${clientTools.eclccPath}.${os.EOL}`);
logger.info(`Generating archive.${os.EOL}`);
if (pathParts.ext.toLowerCase() === ".xml") {
reporter.sendTelemetryEvent("launchConfig.submit.xmlFile");
return xmlFile(filePath);
} else {
reporter.sendTelemetryEvent("launchConfig.submit.createArchive");
return clientTools.createArchive(filePath);
}
}).then(archive => {
progress.report({ increment: 10, message: localize("Verifying Archive") });
if (this.abortSubmitOnError && archive.err.hasError()) {
reporter.sendTelemetryEvent("launchConfig.submit.abortSubmitOnError");
throw new Error(`${localize("ECL Syntax Error(s)")}:\n ${archive.err.errors().map(e => e.msg).join("\n ")}`);
} else if (archive.content.length === 0) {
reporter.sendTelemetryErrorEvent("launchConfig.submit.EmptyArchive");
throw new Error(`${localize("Empty Archive")}:\n ${archive.err.all().map(e => e.msg).join("\n ")}`);
}
logger.info(`Archive Size: ${archive.content.length}.${os.EOL}`);
return archive;
}).then(archive => {
progress.report({ increment: 10, message: localize("Creating Workunit") });
logger.info(`Creating workunit.${os.EOL}`);
reporter.sendTelemetryEvent("launchConfig.submit.createWorkunit");
return this.createWorkunit().then(wu => {
failedWU = wu;
return [wu, archive] as [Workunit, any];
Expand All @@ -675,6 +687,7 @@ export class LaunchConfig implements LaunchRequestArguments {
for (let retry = 1; retry <= attempts; ++retry) {
progress.report({ increment: 3, message: `${localize("Updating Workunit")} ${wu.Wuid} (${retry} of ${attempts})` });
logger.info(`Updating workunit (${retry} of ${attempts}).${os.EOL}`);
reporter.sendTelemetryEvent("launchConfig.submit.update", {}, { "attempt": retry });
await wu.update({
Jobname: pathParts.name,
QueryText: archive.content,
Expand All @@ -692,18 +705,22 @@ export class LaunchConfig implements LaunchRequestArguments {
lastError = e || lastError;
});
}
reporter.sendTelemetryErrorEvent("launchConfig.submit.update", { "message": lastError?.message });
reject(lastError);
});
}).then((wu) => {
progress.report({ increment: 10, message: `${localize("Submitting workunit")} ${wu.Wuid}` });
logger.info(`Submitting workunit: ${wu.Wuid}.${os.EOL}`);
reporter.sendTelemetryEvent("launchConfig.submit.submit");
return wu.submit(targetCluster, action(mode), this.resultLimit);
}).then((wu) => {
progress.report({ increment: 10, message: `${localize("Submitted workunit")} ${wu.Wuid}` });
logger.info(`Submitted: ${this.wuDetailsUrl(wu.Wuid)}.${os.EOL}`);
failedWU = undefined;
reporter.sendTelemetryEvent("launchConfig.submit.success");
return wu;
}).catch(e => {
reporter.sendTelemetryErrorEvent("launchConfig.submit.catch", { "message": e?.message });
logger.info(`Launch failed - ${e.message}.${os.EOL}`);
logger.debug("launchConfig.submit");
if (failedWU) {
Expand Down
27 changes: 27 additions & 0 deletions src/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as vscode from "vscode";
import TelemetryReporter from "@vscode/extension-telemetry";

class MyTelemetryReporter extends TelemetryReporter {

dispose(): Promise<any> {
reporter.sendTelemetryEvent("MyTelemetryReporter.dispose");
return super.dispose();
}
}

// telemetry reporter
export let reporter: TelemetryReporter;

export function activate(context: vscode.ExtensionContext) {
const extPackageJSON = context.extension.packageJSON;
reporter = new MyTelemetryReporter("hpcc-systems.ecl", extPackageJSON.version, "b785b2bb-e170-421b-8bd8-baaf895fe88b");
context.subscriptions.push(reporter);

reporter.sendTelemetryEvent("activate");
}

export function deactivate(): void {
reporter.sendTelemetryEvent("deactivate");

reporter.dispose();
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"outDir": "lib-es6",
"jsx": "react",
"allowJs": true,
"resolveJsonModule": true,
"sourceMap": true,
"noImplicitAny": false,
"noEmitOnError": false,
Expand Down
Loading

0 comments on commit d451cd2

Please sign in to comment.