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

Query Store Service #2171

Merged
merged 36 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3928949
Checkpoint
Benjin Jul 18, 2023
51d8d82
Checkpoint
Benjin Jul 18, 2023
d057cdf
Checkpoint
Benjin Jul 19, 2023
33419c3
checkpoint
Benjin Jul 19, 2023
99e65e1
Hooking in calls to QueryExecutionService
Benjin Jul 20, 2023
f0a26bc
adding cases
Benjin Jul 22, 2023
ee5599b
Fleshing out report handlers
Benjin Aug 2, 2023
3d2ccfc
Adding parameter converters
Benjin Aug 11, 2023
ef73305
Adding sqlparam declarations for Top Resource Consumers and Forced Plans
Benjin Aug 11, 2023
6995f11
swapping to object-object to centralize conversion for sqlparams
Benjin Aug 11, 2023
4f6d74f
Adding sqlparams for GetTrackedQueries
Benjin Aug 11, 2023
bf1626f
Added sqlparams for High Variation
Benjin Aug 11, 2023
f762d6c
Added Overall ResourceConumption
Benjin Aug 11, 2023
2c39510
Adding params for regressed queries
Benjin Aug 14, 2023
4196c82
Removing WithWaitStats calls, since they're automatically used within…
Benjin Aug 14, 2023
381c041
Adding PlanSummary handlers
Benjin Aug 14, 2023
d79de0a
cleaning up orderable queries
Benjin Aug 14, 2023
3f70aa8
initial test mockout
Benjin Aug 15, 2023
cb3778f
adding basic (incorrect) parameter translation
Benjin Aug 15, 2023
8891103
first test passing, datetimeoffset swapped to ISO format
Benjin Aug 16, 2023
31a15c9
Adding test baselines
Benjin Aug 16, 2023
3756a38
Updating nuget package
Benjin Aug 17, 2023
8a6cb0b
Adding get/set
Benjin Aug 17, 2023
fd051f9
Adding get/set for result object
Benjin Aug 18, 2023
bfc63d5
Switching to parameter-less constructor
Benjin Aug 18, 2023
8fce979
Swapping TimeInterval for string-based BasicTimeInterval
Benjin Aug 18, 2023
817d89d
Removing unnecessary usings
Benjin Aug 19, 2023
7cc471f
Adding back params comments
Benjin Aug 19, 2023
cd15264
Fixing up request docstrings
Benjin Aug 19, 2023
68e5bf1
comment tweak
Benjin Aug 19, 2023
5c1e925
fix tests failing in pipeline because of line endings not matching
kisantia Aug 29, 2023
4bacb80
removing unnecessary usings
Benjin Aug 31, 2023
0f0778d
Setting tests to generate queries in UTC for test stability
Benjin Aug 31, 2023
419b3db
Merge branch 'benjin/queryStore' of https://github.com/microsoft/sqlt…
Benjin Aug 31, 2023
e0290de
Merge branch 'main' into benjin/queryStore
Benjin Aug 31, 2023
f5dd105
Normalizing line endings
Benjin Aug 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.1.17]" />
<PackageReference Update="Microsoft.SqlServer.Migration.Assessment" Version="1.0.20230301.46" />
<PackageReference Update="Microsoft.SqlServer.Migration.Logins" Version="1.0.20230407.56" />
<PackageReference Update="Microsoft.SqlServer.Management.QueryStoreModel" Version="163.26.1" />
<PackageReference Update="Microsoft.SqlServer.Management.SqlParser" Version="170.9.0" />
<PackageReference Update="Microsoft.SqlServer.Migration.Tde" Version="1.0.0-preview.1.0.20230720.98" />
<PackageReference Update="Microsoft.Azure.OperationalInsights" Version="1.0.0" />
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using Microsoft.SqlTools.ServiceLayer.ObjectManagement;
using Microsoft.SqlTools.ServiceLayer.Profiler;
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
using Microsoft.SqlTools.ServiceLayer.QueryStore;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare;
using Microsoft.SqlTools.ServiceLayer.Scripting;
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
Expand Down Expand Up @@ -175,6 +176,9 @@ private static void InitializeRequestHandlersAndServices(ServiceHost serviceHost
SqlProjectsService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(SqlProjectsService.Instance);

QueryStoreService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(QueryStoreService.Instance);

serviceHost.InitializeRequestHandlers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" />
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" />
<PackageReference Include="Microsoft.SqlServer.Management.QueryStoreModel" />
<PackageReference Include="Microsoft.SqlServer.Management.SmoMetadataProvider" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" />
<PackageReference Include="Microsoft.SqlServer.Management.SqlParser" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

#nullable disable

using System;
using Microsoft.SqlServer.Management.QueryStoreModel.Common;

namespace Microsoft.SqlTools.ServiceLayer.QueryStore
{
/// <summary>
/// Represents a TimeInterval with strings for the start and end times instead of DateTimeOffsets for JRPC compatibility
/// </summary>
public class BasicTimeInterval
{
/// <summary>
/// Start time of this time interval, in ISO 8601 format (<code>ToString("O")</code>).
/// This property is ignored unless TimeIntervalOptions is set to Custom.
/// </summary>
public string StartDateTimeInUtc { get; set; } = null;

/// <summary>
/// End time of this time interval, in ISO 8601 format (<code>ToString("O")</code>).
/// This property is ignored unless TimeIntervalOptions is set to Custom.
/// </summary>
public string EndDateTimeInUtc { get; set; } = null;

/// <summary>
/// Time interval type. Unless set to Custom, then StartDateTimeInUtc and EndDateTimeInUtc are ignored.
/// </summary>
public TimeIntervalOptions TimeIntervalOptions { get; set; } = TimeIntervalOptions.Custom;

public TimeInterval Convert()
{
if (TimeIntervalOptions == TimeIntervalOptions.Custom
&& !String.IsNullOrWhiteSpace(StartDateTimeInUtc)
&& !String.IsNullOrWhiteSpace(EndDateTimeInUtc))
{
return new TimeInterval(DateTimeOffset.Parse(StartDateTimeInUtc), DateTimeOffset.Parse(EndDateTimeInUtc));
}
else if (TimeIntervalOptions != TimeIntervalOptions.Custom
&& String.IsNullOrWhiteSpace(StartDateTimeInUtc)
&& String.IsNullOrWhiteSpace(EndDateTimeInUtc))
{
return new TimeInterval(TimeIntervalOptions);
}
else
{
throw new InvalidOperationException($"{nameof(BasicTimeInterval)} was not populated correctly: '{TimeIntervalOptions}', '{StartDateTimeInUtc}' - '{EndDateTimeInUtc}'");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlServer.Management.QueryStoreModel.ForcedPlanQueries;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting a Forced Plan Queries report
/// </summary>
public class GetForcedPlanQueriesReportParams : OrderableQueryConfigurationParams<ForcedPlanQueriesConfiguration>
{
/// <summary>
/// Time interval for the report
/// </summary>
public BasicTimeInterval TimeInterval { get; set; }

public override ForcedPlanQueriesConfiguration Convert()
{
ForcedPlanQueriesConfiguration config = base.Convert();
config.TimeInterval = TimeInterval.Convert();

return config;
}
}

/// <summary>
/// Gets the query for a Forced Plan Queries report
/// </summary>
public class GetForcedPlanQueriesReportRequest
{
public static readonly RequestType<GetForcedPlanQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetForcedPlanQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getForcedPlanQueriesReport");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlServer.Management.QueryStoreModel.HighVariation;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting a High Variation Queries report
/// </summary>
public class GetHighVariationQueriesReportParams : OrderableQueryConfigurationParams<HighVariationConfiguration>
{
/// <summary>
/// Time interval for the report
/// </summary>
public BasicTimeInterval TimeInterval { get; set; }

public override HighVariationConfiguration Convert()
{
HighVariationConfiguration config = base.Convert();
config.TimeInterval = TimeInterval.Convert();

return config;
}
}

/// <summary>
/// Gets the query for a High Variation Queries report
/// </summary>
public class GetHighVariationQueriesSummaryRequest
{
public static readonly RequestType<GetHighVariationQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetHighVariationQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getHighVariationQueriesSummary");
}

/// <summary>
/// Gets the query for a detailed High Variation Queries report
/// </summary>
public class GetHighVariationQueriesDetailedSummaryRequest
{
public static readonly RequestType<GetHighVariationQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetHighVariationQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getHighVariationQueriesDetailedSummary");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlServer.Management.QueryStoreModel.Common;
using Microsoft.SqlServer.Management.QueryStoreModel.OverallResourceConsumption;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting an Overall Resource Consumption report
/// </summary>
public class GetOverallResourceConsumptionReportParams : QueryConfigurationParams<OverallResourceConsumptionConfiguration>
{
/// <summary>
/// Time interval for the report
/// </summary>
public BasicTimeInterval SpecifiedTimeInterval { get; set; }

/// <summary>
/// Bucket interval for the report
/// </summary>
public BucketInterval SpecifiedBucketInterval { get; set; }

public override OverallResourceConsumptionConfiguration Convert()
{
OverallResourceConsumptionConfiguration result = base.Convert();

result.SpecifiedTimeInterval = SpecifiedTimeInterval.Convert();
result.SelectedBucketInterval = SpecifiedBucketInterval;

return result;
}
}

/// <summary>
/// Gets the query for an Overall Resource Consumption report
/// </summary>
public class GetOverallResourceConsumptionReportRequest
{
public static readonly RequestType<GetOverallResourceConsumptionReportParams, QueryStoreQueryResult> Type
= RequestType<GetOverallResourceConsumptionReportParams, QueryStoreQueryResult>.Create("queryStore/getOverallResourceConsumptionReport");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlServer.Management.QueryStoreModel.RegressedQueries;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting a Regressed Queries report
/// </summary>
public class GetRegressedQueriesReportParams : QueryConfigurationParams<RegressedQueriesConfiguration>
{
/// <summary>
/// Time interval during which to look for performance regressions for the report
/// </summary>
public BasicTimeInterval TimeIntervalRecent { get; set; }

/// <summary>
/// Time interval during which to establish baseline performance for the report
/// </summary>
public BasicTimeInterval TimeIntervalHistory { get; set; }

/// <summary>
/// Minimum number of executions for a query to be included
/// </summary>
public long MinExecutionCount { get; set; }

public override RegressedQueriesConfiguration Convert()
{
RegressedQueriesConfiguration result = base.Convert();

result.TimeIntervalRecent = TimeIntervalRecent.Convert();
result.TimeIntervalHistory = TimeIntervalHistory.Convert();
result.MinExecutionCount = MinExecutionCount;

return result;
}
}

/// <summary>
/// Gets the query for a Regressed Queries report
/// </summary>
public class GetRegressedQueriesSummaryRequest
{
public static readonly RequestType<GetRegressedQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetRegressedQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getRegressedQueriesSummary");
}

/// <summary>
/// Gets the query for a detailed Regressed Queries report
/// </summary>
public class GetRegressedQueriesDetailedSummaryRequest
{
public static readonly RequestType<GetRegressedQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetRegressedQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getRegressedQueriesDetailedSummary");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlServer.Management.QueryStoreModel.TopResourceConsumers;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting a Top Resource Consumers report
/// </summary>
public class GetTopResourceConsumersReportParams : OrderableQueryConfigurationParams<TopResourceConsumersConfiguration>
{
/// <summary>
/// Time interval for the report
/// </summary>
public BasicTimeInterval TimeInterval { get; set; }

public override TopResourceConsumersConfiguration Convert()
{
TopResourceConsumersConfiguration result = base.Convert();
result.TimeInterval = TimeInterval.Convert();

return result;
}
}

/// <summary>
/// Gets the query for a Top Resource Consumers report
/// </summary>
public class GetTopResourceConsumersSummaryRequest
{
public static readonly RequestType<GetTopResourceConsumersReportParams, QueryStoreQueryResult> Type
= RequestType<GetTopResourceConsumersReportParams, QueryStoreQueryResult>.Create("queryStore/getTopResourceConsumersSummary");
}

/// <summary>
/// Gets the query for a detailed Top Resource Consumers report
/// </summary>
public class GetTopResourceConsumersDetailedSummaryRequest
{
public static readonly RequestType<GetTopResourceConsumersReportParams, QueryStoreQueryResult> Type
= RequestType<GetTopResourceConsumersReportParams, QueryStoreQueryResult>.Create("queryStore/getTopResourceConsumersDetailedSummary");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.SqlTools.Hosting.Protocol.Contracts;

#nullable disable

namespace Microsoft.SqlTools.ServiceLayer.QueryStore.Contracts
{
/// <summary>
/// Parameters for getting a Tracked Queries report
/// </summary>
public class GetTrackedQueriesReportParams
{
/// <summary>
/// Search text for a query
/// </summary>
public string QuerySearchText { get; set; }
}

/// <summary>
/// Gets the query for a Tracked Queries report
/// </summary>
public class GetTrackedQueriesReportRequest
{
public static readonly RequestType<GetTrackedQueriesReportParams, QueryStoreQueryResult> Type
= RequestType<GetTrackedQueriesReportParams, QueryStoreQueryResult>.Create("queryStore/getTrackedQueriesReport");
}
}
Loading
Loading