From b52386a36a7334c07dafb7ed944ef33bb704afdb Mon Sep 17 00:00:00 2001 From: Lewis Sanchez <87730006+lewis-sanchez@users.noreply.github.com> Date: Fri, 3 Jun 2022 13:56:32 -0700 Subject: [PATCH] Execution Plan Telemetry for Plan Comparisons (#19610) * Adds telemetry when plan comparison is invoked * Small formatting change. * Adds telemetry to add execution plan button * Removes unused ExecutionPlanComparisonEditorView constructor parameters * Small formatting adjustment * Adds telemetry to ExecutionPlanComparisonEditorView properties * Code review changes --- .../telemetry/common/telemetryKeys.ts | 3 ++ .../executionPlanComparisonEditorView.ts | 28 +++++++++++++------ .../browser/executionPlanView.ts | 13 +++++++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/sql/platform/telemetry/common/telemetryKeys.ts b/src/sql/platform/telemetry/common/telemetryKeys.ts index 06203be35f..7033e02acb 100644 --- a/src/sql/platform/telemetry/common/telemetryKeys.ts +++ b/src/sql/platform/telemetry/common/telemetryKeys.ts @@ -55,6 +55,7 @@ export const enum TelemetryError { } export const enum TelemetryAction { + AddExecutionPlan = 'AddExecutionPlan', AddServerGroup = 'AddServerGroup', adsCommandExecuted = 'adsCommandExecuted', ConnectToServer = 'ConnectToServer', @@ -73,6 +74,7 @@ export const enum TelemetryAction { CancelQuery = 'CancelQuery', ChartCreated = 'ChartCreated', Click = 'Click', + CompareExecutionPlan = 'CompareExecutionPlan', FindNode = 'FindNode', FirewallRuleRequested = 'FirewallRuleCreated', GenerateScript = 'GenerateScript', @@ -97,6 +99,7 @@ export const enum TelemetryAction { RunQueryString = 'RunQueryString', ShowChart = 'ShowChart', StopAgentJob = 'StopAgentJob', + ViewExecutionPlanComparisonProperties = 'ViewExecutionPlanComparisonProperties', ViewTopOperations = 'ViewTopOperations', WizardPagesNavigation = 'WizardPagesNavigation', SearchStarted = 'SearchStarted', diff --git a/src/sql/workbench/contrib/executionPlan/browser/executionPlanComparisonEditorView.ts b/src/sql/workbench/contrib/executionPlan/browser/executionPlanComparisonEditorView.ts index 954f5c8548..cad9d911f1 100644 --- a/src/sql/workbench/contrib/executionPlan/browser/executionPlanComparisonEditorView.ts +++ b/src/sql/workbench/contrib/executionPlan/browser/executionPlanComparisonEditorView.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as azdata from 'azdata'; +import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys'; import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox'; import { ITaskbarContent, Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; import { AzdataGraphView } from 'sql/workbench/contrib/executionPlan/browser/azdataGraphView'; @@ -14,8 +15,6 @@ import { Action } from 'vs/base/common/actions'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IStorageService } from 'vs/platform/storage/common/storage'; -import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IColorTheme, ICssStyleCollector, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import * as DOM from 'vs/base/browser/dom'; import { ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar'; @@ -30,7 +29,7 @@ import { errorForeground, listHoverBackground, textLinkForeground } from 'vs/pla import { ExecutionPlanViewHeader } from 'sql/workbench/contrib/executionPlan/browser/executionPlanViewHeader'; import { attachSelectBoxStyler } from 'sql/platform/theme/common/styler'; import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress'; - +import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry'; export class ExecutionPlanComparisonEditorView { @@ -105,9 +104,7 @@ export class ExecutionPlanComparisonEditorView { constructor( parentContainer: HTMLElement, @IInstantiationService private _instantiationService: IInstantiationService, - @ITelemetryService telemetryService: ITelemetryService, @IThemeService private themeService: IThemeService, - @IStorageService storageService: IStorageService, @IExecutionPlanService private _executionPlanService: IExecutionPlanService, @IFileDialogService private _fileDialogService: IFileDialogService, @IContextViewService readonly contextViewService: IContextViewService, @@ -131,11 +128,11 @@ export class ExecutionPlanComparisonEditorView { }); this._taskbar.context = this; - this._addExecutionPlanAction = new AddExecutionPlanAction(); + this._addExecutionPlanAction = this._instantiationService.createInstance(AddExecutionPlanAction); this._zoomOutAction = new ZoomOutAction(); this._zoomInAction = new ZoomInAction(); this._zoomToFitAction = new ZoomToFitAction(); - this._propertiesAction = new PropertiesAction(); + this._propertiesAction = this._instantiationService.createInstance(PropertiesAction); this._toggleOrientationAction = new ToggleOrientation(); this._resetZoomAction = new ZoomReset(); const content: ITaskbarContent[] = [ @@ -529,11 +526,16 @@ export class ExecutionPlanComparisonEditorView { class AddExecutionPlanAction extends Action { public static ID = 'ep.AddExecutionPlan'; public static LABEL = localize('addExecutionPlanLabel', "Add execution plan"); - constructor() { + + constructor( + @IAdsTelemetryService private readonly telemetryService: IAdsTelemetryService + ) { super(AddExecutionPlanAction.ID, AddExecutionPlanAction.LABEL, addIconClassName); } public override async run(context: ExecutionPlanComparisonEditorView): Promise { + this.telemetryService.sendActionEvent(TelemetryKeys.TelemetryView.ExecutionPlan, TelemetryKeys.TelemetryAction.AddExecutionPlan); + await context.openAndAddExecutionPlanFile(); } @@ -608,11 +610,19 @@ class ToggleOrientation extends Action { class PropertiesAction extends Action { public static ID = 'epCompare.comparePropertiesAction'; public static LABEL = localize('epCompare.comparePropertiesAction', "Properties"); - constructor() { + + constructor( + @IAdsTelemetryService private readonly telemetryService: IAdsTelemetryService + ) { super(PropertiesAction.ID, PropertiesAction.LABEL, openPropertiesIconClassNames); this.enabled = false; } + public override async run(context: ExecutionPlanComparisonEditorView): Promise { + this.telemetryService + .createActionEvent(TelemetryKeys.TelemetryView.ExecutionPlan, TelemetryKeys.TelemetryAction.ViewExecutionPlanComparisonProperties) + .send(); + context.togglePropertiesView(); } } diff --git a/src/sql/workbench/contrib/executionPlan/browser/executionPlanView.ts b/src/sql/workbench/contrib/executionPlan/browser/executionPlanView.ts index 501d51b33e..d308fcb808 100644 --- a/src/sql/workbench/contrib/executionPlan/browser/executionPlanView.ts +++ b/src/sql/workbench/contrib/executionPlan/browser/executionPlanView.ts @@ -164,7 +164,7 @@ export class ExecutionPlanView implements ISashLayoutProvider { this._instantiationService.createInstance(ZoomToFitAction, 'ActionBar'), this._instantiationService.createInstance(CustomZoomAction, 'ActionBar'), this._instantiationService.createInstance(PropertiesAction, 'ActionBar'), - new CompareExecutionPlanAction(), + this._instantiationService.createInstance(CompareExecutionPlanAction, 'ActionBar'), this.actionBarToggleTopTip ]; this._actionBar.pushAction(actionBarActions, { icon: true, label: false }); @@ -181,7 +181,7 @@ export class ExecutionPlanView implements ISashLayoutProvider { this._instantiationService.createInstance(ZoomToFitAction, 'ContextMenu'), this._instantiationService.createInstance(CustomZoomAction, 'ContextMenu'), this._instantiationService.createInstance(PropertiesAction, 'ContextMenu'), - new CompareExecutionPlanAction(), + this._instantiationService.createInstance(CompareExecutionPlanAction, 'ContextMenu'), this.contextMenuToggleTooltipAction ]; const self = this; @@ -530,11 +530,18 @@ export class CompareExecutionPlanAction extends Action { public static ID = 'ep.tooltipToggleContextMenu'; public static COMPARE_PLAN = localize('executionPlanCompareExecutionPlanAction', "Compare execution plan"); - constructor() { + constructor(private source: ExecutionPlanActionSource, + @IAdsTelemetryService private readonly telemetryService: IAdsTelemetryService + ) { super(CompareExecutionPlanAction.COMPARE_PLAN, CompareExecutionPlanAction.COMPARE_PLAN, executionPlanCompareIconClassName); } public override async run(context: ExecutionPlanView): Promise { + this.telemetryService + .createActionEvent(TelemetryKeys.TelemetryView.ExecutionPlan, TelemetryKeys.TelemetryAction.CompareExecutionPlan) + .withAdditionalProperties({ source: this.source }) + .send(); + context.compareCurrentExecutionPlan(); } }