Skip to content

Commit

Permalink
Add metrics to commands being executed (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcampos authored Aug 17, 2018
1 parent 1a7252a commit e48aee0
Show file tree
Hide file tree
Showing 40 changed files with 127 additions and 35 deletions.
8 changes: 8 additions & 0 deletions packages/salesforcedx-utils-vscode/src/cli/commandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export class Command {
public readonly command: string;
public readonly description?: string;
public readonly args: string[];
public readonly logName?: string;

public constructor(builder: CommandBuilder) {
this.command = builder.command;
this.description = builder.description;
this.args = builder.args;
this.logName = builder.logName;
}

public toString(): string {
Expand All @@ -31,6 +33,7 @@ export class CommandBuilder {
public readonly command: string;
public description?: string;
public args: string[] = [];
public logName?: string;

public constructor(command: string) {
this.command = command;
Expand Down Expand Up @@ -61,6 +64,11 @@ export class CommandBuilder {
return this;
}

public withLogName(logName: string): CommandBuilder {
this.logName = logName;
return this;
}

public build(): Command {
return new Command(this);
}
Expand Down
1 change: 1 addition & 0 deletions packages/salesforcedx-utils-vscode/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Command {
readonly command: string;
readonly description?: string;
readonly args: string[];
readonly logName?: string;

toString(): string;
toCommand(): string;
Expand Down
6 changes: 6 additions & 0 deletions packages/salesforcedx-vscode-core/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { nls } from '../messages';
import { notificationService, ProgressNotification } from '../notifications';
import { isSfdxProjectOpened } from '../predicates';
import { taskViewService } from '../statuses';
import { telemetryService } from '../telemetry';

export class LightningFilePathExistsChecker
implements PostconditionChecker<DirFileNameSelection> {
Expand Down Expand Up @@ -338,6 +339,10 @@ export abstract class SfdxCommandletExecutor<T>
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}

public logMetric(logName?: string) {
telemetryService.sendCommandEvent(logName);
}

public execute(response: ContinueResponse<T>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;
Expand All @@ -346,6 +351,7 @@ export abstract class SfdxCommandletExecutor<T>
}).execute(cancellationToken);

this.attachExecution(execution, cancellationTokenSource, cancellationToken);
this.logMetric(execution.command.logName);
}

public abstract build(data: T): Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ForceAliasList extends SfdxCommandletExecutor<{}> {
return new SfdxCommandBuilder()
.withDescription(nls.localize('force_alias_list_text'))
.withArg('force:alias:list')
.withLogName('force_alias_list')
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { channelService } from '../channels';
import { nls } from '../messages';
import { notificationService, ProgressNotification } from '../notifications';
import { taskViewService } from '../statuses';
import { telemetryService } from '../telemetry';
import {
CompositeParametersGatherer,
FilePathExistsChecker,
Expand All @@ -43,6 +42,7 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
.withFlag('--classname', data.fileName)
.withFlag('--template', 'DefaultApexClass')
.withFlag('--outputdir', data.outputdir)
.withLogName('force_apex_class_create')
.build();
}

Expand Down Expand Up @@ -77,7 +77,7 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);

telemetryService.sendCommandEvent('force_apex_class_create');
this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ForceApexExecuteExecutor extends SfdxCommandletExecutor<{}> {
.withDescription(nls.localize('force_apex_execute_document_text'))
.withArg('force:apex:execute')
.withFlag('--apexcodefile', data.fileName)
.withLogName('force_apex_execute')
.build();
}

Expand All @@ -54,6 +55,7 @@ class ForceApexExecuteExecutor extends SfdxCommandletExecutor<{}> {
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);
this.logMetric(execution.command.logName);
channelService.showChannelOutput();
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ForceApexLogGetExecutor extends SfdxCommandletExecutor<
.withArg('force:apex:log:get')
.withFlag('--logid', data.id)
.withJson()
.withLogName('force_apex_log_get')
.build();
}

Expand All @@ -68,6 +69,7 @@ export class ForceApexLogGetExecutor extends SfdxCommandletExecutor<
cwd: vscode.workspace.rootPath
}).execute(cancellationToken);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);
this.logMetric(execution.command.logName);
const result = await new CommandOutput().getCmdResult(execution);
const resultJson = JSON.parse(result);
if (resultJson.status === 0) {
Expand Down Expand Up @@ -159,6 +161,7 @@ export class ForceApexLogList {
.withDescription(nls.localize('force_apex_log_list_text'))
.withArg('force:apex:log:list')
.withJson()
.withLogName('force_apex_log_list')
.build(),
{ cwd: vscode.workspace.workspaceFolders![0].uri.fsPath }
).execute();
Expand Down
22 changes: 13 additions & 9 deletions packages/salesforcedx-vscode-core/src/commands/forceApexTestRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class TestsSelector
implements ParametersGatherer<ApexTestQuickPickItem> {
public async gather(): Promise<
CancelResponse | ContinueResponse<ApexTestQuickPickItem>
> {
> {
const testSuites = await vscode.workspace.findFiles(
'**/*.testSuite-meta.xml'
);
Expand Down Expand Up @@ -96,12 +96,15 @@ export class ForceApexTestRunCommandFactory {
public constructExecutorCommand(): Command {
this.builder = this.builder
.withDescription(nls.localize('force_apex_test_run_text'))
.withArg('force:apex:test:run');
.withArg('force:apex:test:run')
.withLogName('force_apex_test_run');

switch (this.data.type) {
case TestType.Suite:
this.builder = this.builder
.withFlag('--suitenames', `${this.data.label}`);
this.builder = this.builder.withFlag(
'--suitenames',
`${this.data.label}`
);
break;
case TestType.Class:
this.builder = this.builder
Expand All @@ -113,8 +116,7 @@ export class ForceApexTestRunCommandFactory {
}

if (this.getCodeCoverage) {
this.builder = this.builder
.withArg('--codecoverage');
this.builder = this.builder.withArg('--codecoverage');
}

this.builder = this.builder
Expand All @@ -124,17 +126,19 @@ export class ForceApexTestRunCommandFactory {
this.testRunExecutorCommand = this.builder.build();
return this.testRunExecutorCommand;
}

}

export class ForceApexTestRunExecutor extends SfdxCommandletExecutor<
ApexTestQuickPickItem
> {
> {
public build(data: ApexTestQuickPickItem): Command {
const getCodeCoverage: boolean = sfdxCoreSettings
.getConfiguration()
.get('retrieve-test-code-coverage') as boolean;
const factory: ForceApexTestRunCommandFactory = new ForceApexTestRunCommandFactory(data, getCodeCoverage);
const factory: ForceApexTestRunCommandFactory = new ForceApexTestRunCommandFactory(
data,
getCodeCoverage
);
return factory.constructExecutorCommand();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export class ForceApexTestRunCodeActionExecutor extends SfdxCommandletExecutor<{
.withFlag('--tests', this.test)
.withFlag('--resultformat', 'human')
.withArg('--synchronous')
.withFlag('--loglevel', 'error');
.withFlag('--loglevel', 'error')
.withLogName('force_apex_test_run_code_action');

if (this.shouldGetCodeCoverage) {
this.builder = this.builder.withArg('--codecoverage');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ForceApexTriggerCreateExecutor extends SfdxCommandletExecutor<
.withArg('force:apex:trigger:create')
.withFlag('--triggername', data.fileName)
.withFlag('--outputdir', data.outputdir)
.withLogName('force_apex_trigger_create')
.build();
}

Expand Down Expand Up @@ -78,6 +79,7 @@ export class ForceApexTriggerCreateExecutor extends SfdxCommandletExecutor<
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
this.logMetric(execution.command.logName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ForceAuthDevHubExecutor extends SfdxCommandletExecutor<{}> {
)
.withArg('force:auth:web:login')
.withArg('--setdefaultdevhubusername')
.withLogName('force_auth_dev_hub')
.build();
}
}
Expand All @@ -43,6 +44,7 @@ export class ForceAuthDevHubDemoModeExecutor extends ForceAuthDemoModeExecutor<{
.withArg('--setdefaultdevhubusername')
.withArg('--noprompt')
.withJson()
.withLogName('force_auth_dev_hub_demo_mode')
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ForceAuthLogoutAll extends SfdxCommandletExecutor<{}> {
.withArg('force:auth:logout')
.withArg('--all')
.withArg('--noprompt')
.withLogName('force_auth_logout')
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class ForceAuthWebLoginExecutor extends SfdxCommandletExecutor<Alias> {
.withArg('force:auth:web:login')
.withFlag('--setalias', data.alias)
.withArg('--setdefaultusername')
.withLogName('force_auth_web_login')
.build();
}
}
Expand All @@ -64,7 +65,7 @@ export abstract class ForceAuthDemoModeExecutor<
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);

this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
Expand Down Expand Up @@ -96,6 +97,7 @@ export class ForceAuthWebLoginDemoModeExecutor extends ForceAuthDemoModeExecutor
.withArg('--setdefaultusername')
.withArg('--noprompt')
.withJson()
.withLogName('force_auth_web_login_demo_mode')
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ForceConfigList extends SfdxCommandletExecutor<{}> {
return new SfdxCommandBuilder()
.withDescription(nls.localize('force_config_list_text'))
.withArg('force:config:list')
.withLogName('force_config_list')
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ class ForceDataSoqlQueryExecutor extends SfdxCommandletExecutor<{}> {
let command = new SfdxCommandBuilder()
.withDescription(nls.localize('force_data_soql_query_input_text'))
.withArg('force:data:soql:query')
.withFlag('--query', `${data.query}`);
.withFlag('--query', `${data.query}`)
.withLogName('force_data_soql_query');
if (data.api === ApiType.Tooling) {
command = command.withArg('--usetoolingapi');
command = command
.withArg('--usetoolingapi')
.withLogName('force_data_soql_query_tooling');
}
return command.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class DebuggerSessionDetachExecutor extends SfdxCommandletExecutor<
.withFlag('--sobjectid', data ? data.id : '')
.withFlag('--values', 'Status="Detach"')
.withArg('--usetoolingapi')
.withLogName('force_debugger_stop')
.build();
}
}
Expand All @@ -81,6 +82,7 @@ export class StopActiveDebuggerSessionExecutor extends SfdxCommandletExecutor<{}
)
.withArg('--usetoolingapi')
.withJson()
.withLogName('force_debugger_query_session')
.build();
}

Expand All @@ -93,6 +95,7 @@ export class StopActiveDebuggerSessionExecutor extends SfdxCommandletExecutor<{}
}).execute(cancellationToken);

const resultPromise = new CommandOutput().getCmdResult(execution);
this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
channelService.showChannelOutput();
ProgressNotification.show(execution, cancellationTokenSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ForceGenerateFauxClassesExecutor extends SfdxCommandletExecutor<{}> {
return new SfdxCommandBuilder()
.withDescription(nls.localize('force_sobjects_refresh'))
.withArg('sobject definitions refresh')
.withLogName('force_generate_faux_classes_create')
.build();
}

Expand Down Expand Up @@ -59,6 +60,7 @@ class ForceGenerateFauxClassesExecutor extends SfdxCommandletExecutor<{}> {
console.log('Generate error ' + e);
}
ForceGenerateFauxClassesExecutor.isActive = false;
this.logMetric(execution.command.logName);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ForceLightningAppCreateExecutor extends SfdxCommandletExecutor<
.withArg('force:lightning:app:create')
.withFlag('--appname', data.fileName)
.withFlag('--outputdir', data.outputdir)
.withLogName('force_lightning_app_create')
.build();
}

Expand Down Expand Up @@ -77,6 +78,7 @@ class ForceLightningAppCreateExecutor extends SfdxCommandletExecutor<
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);
this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ForceLightningComponentCreateExecutor extends SfdxCommandletExecutor<
.withArg('force:lightning:component:create')
.withFlag('--componentname', data.fileName)
.withFlag('--outputdir', data.outputdir)
.withLogName('force_lightning_component_create')
.build();
}

Expand Down Expand Up @@ -77,6 +78,7 @@ class ForceLightningComponentCreateExecutor extends SfdxCommandletExecutor<
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);
this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ForceLightningEventCreateExecutor extends SfdxCommandletExecutor<
.withArg('force:lightning:event:create')
.withFlag('--eventname', data.fileName)
.withFlag('--outputdir', data.outputdir)
.withLogName('force_lightning_event_create')
.build();
}

Expand Down Expand Up @@ -77,6 +78,7 @@ class ForceLightningEventCreateExecutor extends SfdxCommandletExecutor<
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);
this.logMetric(execution.command.logName);
channelService.streamCommandOutput(execution);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
Expand Down
Loading

0 comments on commit e48aee0

Please sign in to comment.