mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 01:25:36 -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
148 lines
4.3 KiB
TypeScript
148 lines
4.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
//TODO: This is the same file from mssql. Move this into a common place.
|
|
import * as azdata from 'azdata';
|
|
import * as vscode from 'vscode';
|
|
import * as path from 'path';
|
|
import * as os from 'os';
|
|
import * as findRemoveSync from 'find-remove';
|
|
import { promises as fs } from 'fs';
|
|
|
|
const configTracingLevel = 'tracingLevel';
|
|
const configLogRetentionMinutes = 'logRetentionMinutes';
|
|
const configLogFilesRemovalLimit = 'logFilesRemovalLimit';
|
|
const extensionConfigSectionName = 'azuremonitor';
|
|
|
|
export function removeOldLogFiles(logPath: string, _prefix: string): JSON {
|
|
return findRemoveSync(logPath, { age: { seconds: getConfigLogRetentionSeconds() }, limit: getConfigLogFilesRemovalLimit() });
|
|
}
|
|
|
|
export function getConfiguration(_config: string = extensionConfigSectionName): vscode.WorkspaceConfiguration {
|
|
return vscode.workspace.getConfiguration(extensionConfigSectionName);
|
|
}
|
|
|
|
export function getConfigLogFilesRemovalLimit(): number | undefined {
|
|
let config = getConfiguration();
|
|
if (config && config[configLogFilesRemovalLimit]) {
|
|
return Number((config[configLogFilesRemovalLimit]).toFixed(0));
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function getConfigLogRetentionSeconds(): number | undefined {
|
|
let config = getConfiguration();
|
|
if (config && config[configLogRetentionMinutes]) {
|
|
return Number((config[configLogRetentionMinutes] * 60).toFixed(0));
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function getConfigTracingLevel(): string | undefined {
|
|
let config = getConfiguration();
|
|
if (config) {
|
|
return config[configTracingLevel];
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function getLogFileName(prefix: string, pid: number): string {
|
|
return `${prefix}_${pid}.log`;
|
|
}
|
|
|
|
export function getCommonLaunchArgsAndCleanupOldLogFiles(logPath: string, fileName: string, executablePath: string): string[] {
|
|
let launchArgs: string[] = [];
|
|
launchArgs.push(`--locale`, vscode.env.language);
|
|
|
|
launchArgs.push('--log-file');
|
|
let logFile = path.join(logPath, fileName);
|
|
launchArgs.push(logFile);
|
|
|
|
console.log(`logFile for ${path.basename(executablePath)} is ${logFile}`);
|
|
console.log(`This process (ui Extenstion Host) is pid: ${process.pid}`);
|
|
// Delete old log files
|
|
let deletedLogFiles = removeOldLogFiles(logPath, fileName);
|
|
console.log(`Old log files deletion report: ${JSON.stringify(deletedLogFiles)}`);
|
|
let config = getConfigTracingLevel();
|
|
if (config) {
|
|
launchArgs.push('--tracing-level');
|
|
launchArgs.push(config);
|
|
}
|
|
|
|
launchArgs.push('--service-name');
|
|
launchArgs.push('AzureMonitor');
|
|
|
|
return launchArgs;
|
|
}
|
|
|
|
export function ensure(target: any, key: string): any {
|
|
if (target[key] === void 0) {
|
|
target[key] = {} as any;
|
|
}
|
|
return target[key];
|
|
}
|
|
|
|
export interface IPackageInfo {
|
|
name: string;
|
|
version: string;
|
|
aiKey: string;
|
|
}
|
|
|
|
export function getPackageInfo(packageJson: IPackageInfo): IPackageInfo | undefined {
|
|
if (packageJson) {
|
|
return {
|
|
name: packageJson.name,
|
|
version: packageJson.version,
|
|
aiKey: packageJson.aiKey
|
|
};
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function verifyPlatform(): Thenable<boolean> {
|
|
if (os.platform() === 'darwin' && parseFloat(os.release()) < 16) {
|
|
return Promise.resolve(false);
|
|
} else {
|
|
return Promise.resolve(true);
|
|
}
|
|
}
|
|
|
|
export function getErrorMessage(error: Error | any, removeHeader: boolean = false): string {
|
|
let errorMessage: string = (error instanceof Error) ? error.message : error.toString();
|
|
if (removeHeader) {
|
|
errorMessage = removeErrorHeader(errorMessage);
|
|
}
|
|
return errorMessage;
|
|
}
|
|
|
|
export function removeErrorHeader(errorMessage: string): string {
|
|
if (errorMessage && errorMessage !== '') {
|
|
let header: string = 'Error:';
|
|
if (errorMessage.startsWith(header)) {
|
|
errorMessage = errorMessage.substring(header.length);
|
|
}
|
|
}
|
|
return errorMessage;
|
|
}
|
|
|
|
export function isObjectExplorerContext(object: any): object is azdata.ObjectExplorerContext {
|
|
return 'connectionProfile' in object && 'isConnectionNode' in object;
|
|
}
|
|
|
|
export async function exists(path: string): Promise<boolean> {
|
|
try {
|
|
await fs.access(path);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|