Query history telemetry fixes (#20812)

This commit is contained in:
Charles Gagnon
2022-10-11 15:46:05 -07:00
committed by GitHub
parent e05afc3cf9
commit 22a2bce55e
2 changed files with 39 additions and 13 deletions

View File

@@ -9,7 +9,12 @@ import { DOUBLE_CLICK_ACTION_CONFIG_SECTION, ITEM_SELECTED_COMMAND_ID, QUERY_HIS
import { QueryHistoryItem } from './queryHistoryItem';
import { QueryHistoryProvider, setLoadingContext } from './queryHistoryProvider';
import { promises as fs } from 'fs';
import { TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry';
import { sendSettingChangedEvent, TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry';
type DoubleClickAction = 'open' | 'run';
const DEFAULT_DOUBLECLICK_ACTION: DoubleClickAction = 'open';
let doubleClickAction: string = DEFAULT_DOUBLECLICK_ACTION;
let lastSelectedItem: { item: QueryHistoryItem | undefined, time: number | undefined } = {
item: undefined,
@@ -39,13 +44,21 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
canSelectMany: false
});
context.subscriptions.push(treeView);
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(`${QUERY_HISTORY_CONFIG_SECTION}.${DOUBLE_CLICK_ACTION_CONFIG_SECTION}`)) {
const newDoubleClickAction = getDoubleClickAction();
if (newDoubleClickAction !== doubleClickAction) {
sendSettingChangedEvent('DoubleClickAction', doubleClickAction, newDoubleClickAction);
}
doubleClickAction = newDoubleClickAction;
}
}));
// This is an internal-only command so not adding to package.json
context.subscriptions.push(vscode.commands.registerCommand(ITEM_SELECTED_COMMAND_ID, async (selectedItem: QueryHistoryItem) => {
// VS Code doesn't provide a native way to detect a double-click so we track it ourselves by keeping track of the last item clicked and
// when it was clicked to compare, then if a click happens on the same element quickly enough we trigger the configured action
const clickTime = new Date().getTime();
if (lastSelectedItem.item === selectedItem && lastSelectedItem.time && (clickTime - lastSelectedItem.time) < DOUBLE_CLICK_TIMEOUT_MS) {
const doubleClickAction = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION).get<string>(DOUBLE_CLICK_ACTION_CONFIG_SECTION);
TelemetryReporter.sendActionEvent(TelemetryViews.QueryHistory, TelemetryActions.DoubleClick, doubleClickAction);
switch (doubleClickAction) {
case 'run':
@@ -126,5 +139,8 @@ async function runQuery(item: QueryHistoryItem): Promise<void> {
.withAdditionalProperties({ step })
.send();
}
}
export function getDoubleClickAction(): string {
return vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION).get<string>(DOUBLE_CLICK_ACTION_CONFIG_SECTION, DEFAULT_DOUBLECLICK_ACTION);
}

View File

@@ -13,6 +13,7 @@ import * as path from 'path';
import * as crypto from 'crypto';
import * as loc from './localizedConstants';
import { sendSettingChangedEvent, TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry';
import { getDoubleClickAction } from './main';
const STORAGE_IV_KEY = 'queryHistory.storage-iv';
const STORAGE_KEY_KEY = 'queryHistory.storage-key';
@@ -55,10 +56,17 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
this._historyStorageFile = path.join(storageUri.fsPath, HISTORY_STORAGE_FILE_NAME);
// Kick off initialization but then continue on since that may take a while and we don't want to block extension activation
const initializeAction = TelemetryReporter.createTimedAction(TelemetryViews.QueryHistoryProvider, TelemetryActions.Initialize);
this._initPromise = this.initialize().then(() => initializeAction.send());
this._initPromise = this.initialize().then(() => {
initializeAction.withAdditionalProperties({
'setting.persistHistory': String(this._persistHistory),
'setting.maxEntries': String(this._maxEntries),
'setting.captureEnabled': String(this._captureEnabled),
'setting.doubleClickAction': getDoubleClickAction()
}).send();
});
this._disposables.push(vscode.workspace.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION) || e.affectsConfiguration(MAX_ENTRIES_CONFIG_SECTION)) {
await this.updateConfigurationValues();
if (e.affectsConfiguration(QUERY_HISTORY_CONFIG_SECTION)) {
await this.updateConfigurationValues(true);
}
}));
this._disposables.push(azdata.queryeditor.registerQueryEventListener({
@@ -249,23 +257,25 @@ export class QueryHistoryProvider implements vscode.TreeDataProvider<QueryHistor
this.writeHistoryFileWorker?.();
}
private async updateConfigurationValues(): Promise<void> {
private async updateConfigurationValues(sendChangedEvents: boolean = false): Promise<void> {
const configSection = vscode.workspace.getConfiguration(QUERY_HISTORY_CONFIG_SECTION);
const newCaptureEnabled = configSection.get(CAPTURE_ENABLED_CONFIG_SECTION, DEFAULT_CAPTURE_ENABLED);
if (this._captureEnabled !== newCaptureEnabled) {
if (sendChangedEvents && this._captureEnabled !== newCaptureEnabled) {
sendSettingChangedEvent('CaptureEnabled', String(this._captureEnabled), String(newCaptureEnabled));
this._captureEnabled = newCaptureEnabled;
}
this._captureEnabled = newCaptureEnabled;
const newPersistHistory = configSection.get(PERSIST_HISTORY_CONFIG_SECTION, DEFAULT_PERSIST_HISTORY);
if (this._persistHistory !== newPersistHistory) {
if (sendChangedEvents && this._persistHistory !== newPersistHistory) {
sendSettingChangedEvent('PersistHistory', String(this._persistHistory), String(newPersistHistory));
this._persistHistory = newPersistHistory;
}
this._persistHistory = newPersistHistory;
const newMaxEntries = configSection.get(MAX_ENTRIES_CONFIG_SECTION, DEFAULT_MAX_ENTRIES);
if (this._maxEntries !== newMaxEntries) {
if (sendChangedEvents && this._maxEntries !== newMaxEntries) {
sendSettingChangedEvent('MaxEntries', String(this._maxEntries), String(newMaxEntries));
this._maxEntries = newMaxEntries;
}
this._maxEntries = newMaxEntries;
this.trimExtraEntries();
if (!this._persistHistory) {
// We're not persisting history so we can immediately set loading to false to immediately