mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 09:35:38 -05:00
* Added Azure Log Analytics resource for generating AAD Token. * Fixed AzureResource * Removed debug code from connectionManagementService * Moved AzureLogAnalytics from AzureResource enum in azdata.d.ts to azdata.proposed.d.ts. Added azureLogAnalyticsResource to all azureSettings in providerSettings.ts * Updated endpoint for generating AAD Token for LogAnalytics for UsGov, UsNat, and China * Initial Commit of Azure Monitor Extension * Added extension name to azuremonitor package strings * Removed azureMonitor resource from germanyCloud in providerSettings * Added logic to exclude menuItems in object explorer for LogAnalytics * Changed exe from AzureMonitor to Kusto * Added if clause for queryName for new queries * Changed queryWindow name from KustoQuery to KQLQuery for Kusto and LogAnalytics. * Added LogAnalytics for setTaskBarContent * Added serialization and telemetry feature classes to AzureMonitor. Added references for azdata and vscode. * Added azure monitor light and dark icons * Added config for Dashboard in package.json * Added workspace information to dashboard * Added language support for LogAnalytics * Added Notebook support * Added Hide flag to package.json for databaseName * Changed providerId from LogAnalytics to LOGANALYTICS * Changed Workspace to Workspace ID in package.nls.json * Added support for Azure Widget browser * Changed fullName to use workspaceId when connecting * Changed providerId from alertsManagement to azureMonitor * Added .gitignore and *.vsix to vscodeignore. * Removed unused devDependencies * Code Review Feedback * Changed tsconfig.json to match Kusto and Sql * Changed package.json to match kusto package. * Changed tsconfig to validate unused params and implictAny. Changed existing code to satisfy build. * Fixed tsconfig to use the correct base class. * Added objectExplorerNodeProvider and all related classes. * Removed unused tmLanguage file * Added logic to to download extension from toolservice * Fixed launchArgs. Removed commented code from extension.ts. Changed config.json to use net5.0 * Added displayName to package.nls.json. Removed hide flag from databaseName. Other code review feedback. * Added readme info to AzureMonitor * Removed unused client-error-handler and ui-references files. Combined outputChannel in azuremonitorServer. Removed TODO from contextProvider. Renamed function in extension.ts. Removed unneeded 'use strict' from cancelableStream.ts. Removed second outputChannel from objectExplorerNodeProvider. * Removed unused files
168 lines
6.5 KiB
TypeScript
168 lines
6.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { ServerProvider, IConfig, Events } from 'service-downloader';
|
|
import { ServerOptions, TransportKind } from 'vscode-languageclient';
|
|
import * as Constants from './constants';
|
|
import * as vscode from 'vscode';
|
|
import * as nls from 'vscode-nls';
|
|
import * as path from 'path';
|
|
import { getCommonLaunchArgsAndCleanupOldLogFiles } from './utils';
|
|
import { Telemetry, LanguageClientErrorHandler } from './telemetry';
|
|
import { SqlOpsDataClient, ClientOptions } from 'dataprotocol-client';
|
|
import { SerializationFeature } from './features/serializationFeature';
|
|
import { TelemetryFeature } from './features/telemetryFeature';
|
|
import { AccountFeature } from './features/accountFeature';
|
|
import { AppContext } from './appContext';
|
|
import { CompletionExtensionParams, CompletionExtLoadRequest } from './features/contracts';
|
|
import { promises as fs } from 'fs';
|
|
|
|
const localize = nls.loadMessageBundle();
|
|
|
|
export const outputChannel = vscode.window.createOutputChannel(Constants.serviceName);
|
|
const statusView = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
|
|
|
export class AzureMonitorServer {
|
|
|
|
private client!: SqlOpsDataClient;
|
|
private config!: IConfig;
|
|
private disposables: vscode.Disposable[] = [];
|
|
|
|
public async start(context: AppContext): Promise<SqlOpsDataClient> {
|
|
try {
|
|
const installationStart = Date.now();
|
|
const path = await this.download(context);
|
|
const installationComplete = Date.now();
|
|
let serverOptions = generateServerOptions(context.extensionContext.logPath, path);
|
|
let clientOptions = getClientOptions(context);
|
|
this.client = new SqlOpsDataClient(Constants.serviceName, serverOptions, clientOptions);
|
|
const processStart = Date.now();
|
|
const clientReadyPromise = this.client.onReady().then(() => {
|
|
const processEnd = Date.now();
|
|
statusView.text = localize('serviceStartedStatusMsg', "{0} Started", Constants.serviceName);
|
|
setTimeout(() => {
|
|
statusView.hide();
|
|
}, 1500);
|
|
vscode.commands.registerCommand('azuremonitor.loadCompletionExtension', (params: CompletionExtensionParams) => {
|
|
this.client.sendRequest(CompletionExtLoadRequest.type, params);
|
|
});
|
|
Telemetry.sendTelemetryEvent('startup/LanguageClientStarted', {
|
|
installationTime: String(installationComplete - installationStart),
|
|
processStartupTime: String(processEnd - processStart),
|
|
totalTime: String(processEnd - installationStart),
|
|
beginningTimestamp: String(installationStart)
|
|
});
|
|
});
|
|
statusView.show();
|
|
statusView.text = localize('startingServiceStatusMsg', "Starting {0}", Constants.serviceName);
|
|
this.client.start();
|
|
await Promise.all([clientReadyPromise]);
|
|
return this.client;
|
|
} catch (e) {
|
|
Telemetry.sendTelemetryEvent('ServiceInitializingFailed');
|
|
vscode.window.showErrorMessage(localize('failedToStartServiceErrorMsg', "Failed to start {0}", Constants.serviceName));
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
private async download(context: AppContext): Promise<string> {
|
|
const rawConfig = await fs.readFile(path.join(context.extensionContext.extensionPath, 'config.json'));
|
|
this.config = JSON.parse(rawConfig.toString())!;
|
|
this.config.installDirectory = path.join(__dirname, this.config.installDirectory);
|
|
this.config.proxy = vscode.workspace.getConfiguration('http').get<string>('proxy')!;
|
|
this.config.strictSSL = vscode.workspace.getConfiguration('http').get('proxyStrictSSL') || true;
|
|
|
|
const serverdownloader = new ServerProvider(this.config);
|
|
serverdownloader.eventEmitter.onAny(() => generateHandleServerProviderEvent());
|
|
return serverdownloader.getOrDownloadServer();
|
|
}
|
|
|
|
dispose() {
|
|
this.disposables.forEach(d => d.dispose());
|
|
if (this.client) {
|
|
this.client.stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateServerOptions(logPath: string, executablePath: string): ServerOptions {
|
|
const launchArgs = getCommonLaunchArgsAndCleanupOldLogFiles(logPath, 'azuremonitorService.log', executablePath);
|
|
return { command: executablePath, args: launchArgs, transport: TransportKind.stdio };
|
|
}
|
|
|
|
function generateHandleServerProviderEvent() {
|
|
let dots = 0;
|
|
return (e: string, ...args: any[]) => {
|
|
switch (e) {
|
|
case Events.INSTALL_START:
|
|
outputChannel.show(true);
|
|
statusView.show();
|
|
outputChannel.appendLine(localize('installingServiceChannelMsg', "Installing {0} to {1}", Constants.serviceName, args[0]));
|
|
statusView.text = localize('installingServiceStatusMsg', "Installing {0}", Constants.serviceName);
|
|
break;
|
|
case Events.INSTALL_END:
|
|
outputChannel.appendLine(localize('installedServiceChannelMsg', "Installed {0}", Constants.serviceName));
|
|
break;
|
|
case Events.DOWNLOAD_START:
|
|
outputChannel.appendLine(localize('downloadingServiceChannelMsg', "Downloading {0}", args[0]));
|
|
outputChannel.append(localize('downloadingServiceSizeChannelMsg', "({0} KB)", Math.ceil(args[1] / 1024).toLocaleString(vscode.env.language)));
|
|
statusView.text = localize('downloadingServiceStatusMsg', "Downloading {0}", Constants.serviceName);
|
|
break;
|
|
case Events.DOWNLOAD_PROGRESS:
|
|
let newDots = Math.ceil(args[0] / 5);
|
|
if (newDots > dots) {
|
|
outputChannel.append('.'.repeat(newDots - dots));
|
|
dots = newDots;
|
|
}
|
|
break;
|
|
case Events.DOWNLOAD_END:
|
|
outputChannel.appendLine(localize('downloadServiceDoneChannelMsg', "Done installing {0}", Constants.serviceName));
|
|
break;
|
|
default:
|
|
console.error(`Unknown event from Server Provider ${e}`);
|
|
break;
|
|
}
|
|
};
|
|
}
|
|
|
|
function getClientOptions(_context: AppContext): ClientOptions {
|
|
return {
|
|
documentSelector: ['loganalytics'],
|
|
synchronize: {
|
|
configurationSection: Constants.extensionConfigSectionName
|
|
},
|
|
providerId: Constants.providerId,
|
|
errorHandler: new LanguageClientErrorHandler(),
|
|
features: [
|
|
// we only want to add new features
|
|
...SqlOpsDataClient.defaultFeatures,
|
|
TelemetryFeature,
|
|
AccountFeature,
|
|
SerializationFeature
|
|
],
|
|
outputChannel: new CustomOutputChannel()
|
|
};
|
|
}
|
|
|
|
class CustomOutputChannel implements vscode.OutputChannel {
|
|
name!: string;
|
|
append(value: string): void {
|
|
console.log(value);
|
|
}
|
|
appendLine(value: string): void {
|
|
console.log(value);
|
|
}
|
|
clear(): void {
|
|
}
|
|
show(preserveFocus?: boolean): void;
|
|
show(column?: vscode.ViewColumn, preserveFocus?: boolean): void;
|
|
show(_column?: any, _preserveFocus?: any) {
|
|
}
|
|
hide(): void {
|
|
}
|
|
dispose(): void {
|
|
}
|
|
}
|