Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling QueryStore options to the database properties #24255

Merged
merged 13 commits into from
Sep 8, 2023
2 changes: 1 addition & 1 deletion extensions/mssql/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "4.9.0.32",
"version": "4.9.0.34",
"downloadFileNames": {
"Windows_86": "win-x86-net7.0.zip",
"Windows_64": "win-x64-net7.0.zip",
Expand Down
10 changes: 10 additions & 0 deletions extensions/mssql/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,16 @@ export namespace GetAssociatedFilesRequest {
export const type = new RequestType<GetAssociatedFilesRequestParams, string[], void, void>('admin/getassociatedfiles');
}

export namespace PurgeQueryStoreDataRequest {
export const type = new RequestType<purgeQueryStoreDataRequestParams, void, void, void>('objectManagement/purgeQueryStoreData');
}

export interface purgeQueryStoreDataRequestParams {
connectionUri: string;
database: string;
objectUrn: string;
}

// ------------------------------- < Object Management > ------------------------------------

// ------------------------------- < Encryption IV/KEY updation Event > ------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions extensions/mssql/src/mssql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,13 @@ declare module 'mssql' {
* @returns An array of file path strings for each of the associated files.
*/
getAssociatedFiles(connectionUri: string, primaryFilePath: string): Thenable<string[]>;
/**
* Clears all query store data from the database
* @param connectionUri The URI of the server connection.
* @param database The target database.
* @param objectUrn SMO Urn of the database to be detached. More information: https://learn.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo
*/
purgeQueryStoreData(connectionUri: string, database: string, objectUrn: string): Thenable<void>;
}

export interface DatabaseFileData {
Expand Down
1 change: 1 addition & 0 deletions extensions/mssql/src/objectManagement/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const DatabaseGeneralPropertiesDocUrl = 'https://learn.microsoft.com/sql/
export const DatabaseOptionsPropertiesDocUrl = 'https://learn.microsoft.com/sql/relational-databases/databases/database-properties-options-page'
export const DropDatabaseDocUrl = 'https://learn.microsoft.com/sql/t-sql/statements/drop-database-transact-sql';
export const DatabaseScopedConfigurationPropertiesDocUrl = 'https://learn.microsoft.com/sql/t-sql/statements/alter-database-scoped-configuration-transact-sql'
export const QueryStorePropertiesDocUrl = 'https://learn.microsoft.com/sql/relational-databases/databases/database-properties-query-store-page'
export const DatabaseFilesPropertiesDocUrl = 'https://learn.microsoft.com/sql/relational-databases/databases/database-properties-files-page'
export const DatabaseFileGroupsPropertiesDocUrl = 'https://learn.microsoft.com/sql/relational-databases/databases/database-properties-filegroups-page'

Expand Down
27 changes: 27 additions & 0 deletions extensions/mssql/src/objectManagement/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ export interface Database extends ObjectManagement.SqlObject {
isFilesTabSupported?: boolean;
files?: DatabaseFile[];
filegroups?: FileGroup[];
queryStoreOptions?: QueryStoreOptions;
}

export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo<Database> {
Expand All @@ -481,6 +482,32 @@ export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo<Databa
rowDataFileGroupsOptions?: string[];
fileStreamFileGroupsOptions?: string[];
fileTypesOptions?: string[];
operationModeOptions?: string[];
statisticsCollectionIntervalOptions?: string[];
queryStoreCaptureModeOptions?: string[];
sizeBasedCleanupModeOptions?: string[];
staleThresholdOptions?: string[];
}

export interface QueryStoreOptions {
actualMode: string;
dataFlushIntervalInMinutes: number;
statisticsCollectionInterval: string;
maxPlansPerQuery: number;
maxSizeInMB: number;
queryStoreCaptureMode: string;
sizeBasedCleanupMode: string;
staleQueryThresholdInDays: number;
waitStatisticsCaptureMode?: boolean;
capturePolicyOptions?: QueryStoreCapturePolicyOptions;
currentStorageSizeInMB: number;
}

export interface QueryStoreCapturePolicyOptions {
executionCount: number;
staleThreshold: string;
totalCompileCPUTimeInMS: number;
totalExecutionCPUTimeInMS: number;
}

export interface DatabaseScopedConfigurationsInfo {
Expand Down
25 changes: 25 additions & 0 deletions extensions/mssql/src/objectManagement/localizedConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export const DatabaseStateText = localize('objectManagement.databaseProperties.d
export const EncryptionEnabledText = localize('objectManagement.databaseProperties.encryptionEnabledText', "Encryption Enabled");
export const RestrictAccessText = localize('objectManagement.databaseProperties.restrictAccessText', "Restrict Access");
export const DatabaseScopedConfigurationTabHeader = localize('objectManagement.databaseProperties.databaseProperties.databaseScopedConfigurationTabHeader', "Database Scoped Configuration");
export const QueryStoreTabHeader = localize('objectManagement.databaseProperties.databaseProperties.queryStoreTabHeader', "Query Store");
export const DatabaseScopedOptionsColumnHeader = localize('objectManagement.databaseProperties.databaseScopedOptionsColumnHeader', "Database Scoped Options");
export const ValueForPrimaryColumnHeader = localize('objectManagement.databaseProperties.valueForPrimaryColumnHeader', "Value for Primary");
export const ValueForSecondaryColumnHeader = localize('objectManagement.databaseProperties.valueForSecondaryColumnHeader', "Value for Secondary");
Expand Down Expand Up @@ -440,6 +441,30 @@ export const FilestreamFilesText = localize('objectManagement.databaseProperties
export const AddFilegroupText = localize('objectManagement.databaseProperties.addFilegroupButtonText', "Add Filegroup");
export const FilegroupExistsError = (name: string) => localize('objectManagement.databaseProperties.FilegroupExistsError', "File group '{0}' could not be added to the collection, because it already exists.", name);
export const EmptyFilegroupNameError = localize('objectManagement.databaseProperties.emptyFilegroupNameError', "Cannot use empty object names for filegroups.");
export const ActualOperationModeText = localize('objectManagement.databaseProperties.actualOperationModeText', "Operation Mode (Actual)");
export const RequestedOperationModeText = localize('objectManagement.databaseProperties.requestedOperationModeText', "Operation Mode (Requested)");
export const DataFlushIntervalInMinutesText = localize('objectManagement.databaseProperties.dataFlushIntervalInMinutesText', "Data Flush Interval (Minutes)");
export const StatisticsCollectionInterval = localize('objectManagement.databaseProperties.statisticsCollectionInterval', "Statistics Collection Interval");
export const MaxPlansPerQueryText = localize('objectManagement.databaseProperties.maxPlansPerQueryText', "Max Plans Per Query");
export const MaxSizeInMbText = localize('objectManagement.databaseProperties.maxSizeInMbText', "Max Size (MB)");
export const QueryStoreCaptureModeText = localize('objectManagement.databaseProperties.queryStoreCaptureModeText', "Query Store Capture Mode");
export const SizeBasedCleanupModeText = localize('objectManagement.databaseProperties.sizeBasedCleanupModeText', "Size Based Cleanup Mode");
export const StateQueryThresholdInDaysText = localize('objectManagement.databaseProperties.stateQueryThresholdInDaysText', "State Query Threshold (Days)");
export const WaitStatisticsCaptureModeText = localize('objectManagement.databaseProperties.waitStatisticsCaptureModeText', "Wait Statistics Capture Mode");
export const MonitoringSectionText = localize('objectManagement.databaseProperties.monitoringSectionText', "Monitoring");
export const QueryStoreRetentionSectionText = localize('objectManagement.databaseProperties.queryStoreRetentionSectionText', "Query Store Retention");
export const QueryStoreCapturePolicySectionText = localize('objectManagement.databaseProperties.queryStoreCapturePolicySectionText', "Query Store Capture Policy");
export const QueryStoreCurrentDiskUsageSectionText = localize('objectManagement.databaseProperties.queryStoreCurrentDiskUsageSectionText', "Current Disk Usage");
export const ExecutionCountText = localize('objectManagement.databaseProperties.executionCountText', "Execution Count");
export const StaleThresholdText = localize('objectManagement.databaseProperties.staleThresholdText', "Stale Threshold");
export const TotalCompileCPUTimeInMsText = localize('objectManagement.databaseProperties.totalCompileCPUTimeInMs', "Total Compile CPU Time (ms)");
export const TotalExecutionCPUTimeInMsText = localize('objectManagement.databaseProperties.totalExecutionCPUTimeInMsText', "Total Execution CPU Time (ms)");
export const QueryStoreCapturemodeCustomText = localize('objectManagement.databaseProperties.queryStoreCapturemodeCustomText', "Custom");
export const QueryStoreUsedText = localize('objectManagement.databaseProperties.queryStoreUsedText', "Query Store Used");
export const QueryStoreAvailableText = localize('objectManagement.databaseProperties.queryStoreAvailableText', "Query Store Available");
export const PurgeQueryDataButtonText = localize('objectManagement.databaseProperties.purgeQueryDataButtonText', "Purge Query Store Data");
export const YesText = localize('objectManagement.databaseProperties.yesText', "Yes");
export const PurgeQueryStoreDataMessage = (databaseName: string) => localize('objectManagement.databaseProperties.purgeQueryStoreDataMessage', "Are you sure you want to purge the Query Store data from '{0}'?", databaseName);

// Util functions
export function getNodeTypeDisplayName(type: string, inTitle: boolean = false): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export class ObjectManagementService extends BaseService implements IObjectManag
const params: contracts.GetAssociatedFilesRequestParams = { connectionUri, primaryFilePath };
return this.runWithErrorHandling(contracts.GetAssociatedFilesRequest.type, params);
}

async purgeQueryStoreData(connectionUri: string, database: string, objectUrn: string): Promise<void> {
const params: contracts.purgeQueryStoreDataRequestParams = { connectionUri, database, objectUrn };
return this.runWithErrorHandling(contracts.PurgeQueryStoreDataRequest.type, params);
}
}

const ServerLevelSecurableTypes: SecurableTypeMetadata[] = [
Expand Down Expand Up @@ -277,6 +282,10 @@ export class TestObjectManagementService implements IObjectManagementService {
return this.delayAndResolve([]);
}

async purgeQueryStoreData(connectionUri: string, database: string, objectUrn: string): Promise<void> {
return this.delayAndResolve([]);
}

private generateSearchResult(objectType: ObjectManagement.NodeType, schema: string | undefined, count: number): ObjectManagement.SearchResultItem[] {
let items: ObjectManagement.SearchResultItem[] = [];
for (let i = 0; i < count; i++) {
Expand Down
Loading