mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Add AQL Assessment service (#946)
[SQL Assessment API](https://docs.microsoft.com/en-us/sql/sql-assessment-api/sql-assessment-api-overview) provides a mechanism to evaluate the configuration of SQL Server for best practices. SQL Assessment API gives a list of recommended actions to improve SQL Server performance or security. The SQL Assessment service is used by the expected SQL Assessment feature of Azure Data Studio. SqlAssessmentService forwards JSONRPC calls to SQL Assessment engine and wraps results as a response. `assessment/getAssessmentItems` returns a set of checks applicable to a given target. `assessment/invoke` returns a set of recommendations for improving SQL Server instance or database configurations. `assessment/generateScript` returns a T-SQL script for storing an assessment result set to a SQL data table.
This commit is contained in:
@@ -652,6 +652,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
public string OsVersion;
|
||||
|
||||
public string MachineName;
|
||||
public string ServerName;
|
||||
|
||||
public Dictionary<string, object> Options { get; set; }
|
||||
}
|
||||
@@ -666,6 +667,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
public int Port;
|
||||
}
|
||||
|
||||
public class ServerHostInfo
|
||||
{
|
||||
public string Platform;
|
||||
public string Distribution;
|
||||
public string Release;
|
||||
public string ServicePackLevel;
|
||||
}
|
||||
|
||||
public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken)
|
||||
{
|
||||
serverInfo = null;
|
||||
@@ -697,6 +706,37 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
azureAccountToken: azureAccountToken);
|
||||
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the server host information from sys.dm_os_host_info view
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection</param>
|
||||
public static ServerHostInfo GetServerHostInfo(IDbConnection connection)
|
||||
{
|
||||
// SQL Server 2016 and below does not provide sys.dm_os_host_info
|
||||
if (!Version.TryParse(ReadServerVersion(connection), out var hostVersion) || hostVersion.Major <= 13)
|
||||
{
|
||||
return new ServerHostInfo
|
||||
{
|
||||
Platform = "Windows"
|
||||
};
|
||||
}
|
||||
|
||||
var hostInfo = new ServerHostInfo();
|
||||
ExecuteReader(
|
||||
connection,
|
||||
SqlConnectionHelperScripts.GetHostInfo,
|
||||
reader =>
|
||||
{
|
||||
reader.Read();
|
||||
hostInfo.Platform = reader[0].ToString();
|
||||
hostInfo.Distribution = reader[1].ToString();
|
||||
hostInfo.Release = reader[2].ToString();
|
||||
hostInfo.ServicePackLevel = reader[3].ToString();
|
||||
});
|
||||
|
||||
return hostInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -729,11 +769,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
serverInfo.ServerLevel = reader[2].ToString();
|
||||
serverInfo.ServerEdition = reader[3].ToString();
|
||||
serverInfo.MachineName = reader[4].ToString();
|
||||
serverInfo.ServerName = reader[5].ToString();
|
||||
|
||||
if (reader.FieldCount > 5)
|
||||
if (reader.FieldCount > 6)
|
||||
{
|
||||
// Detect the presence of SXI
|
||||
serverInfo.IsSelectiveXmlIndexMetadataPresent = reader.GetInt32(5) == 1;
|
||||
serverInfo.IsSelectiveXmlIndexMetadataPresent = reader.GetInt32(6) == 1;
|
||||
}
|
||||
|
||||
// The 'ProductVersion' server property is of the form ##.#[#].####.#,
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
{
|
||||
static class SqlConnectionHelperScripts
|
||||
{
|
||||
public const string EngineEdition = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WITH (NOLOCK) WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)";
|
||||
public const string EngineEditionWithLock = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)";
|
||||
public const string EngineEdition = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), SERVERPROPERTY ('ServerName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WITH (NOLOCK) WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)";
|
||||
public const string EngineEditionWithLock = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), SERVERPROPERTY ('ServerName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)";
|
||||
|
||||
public const string CheckDatabaseReadonly = @"EXEC sp_dboption '{0}', 'read only'";
|
||||
|
||||
@@ -48,5 +48,6 @@ SELECT @filepath AS FilePath
|
||||
|
||||
public const string GetOsVersion = @"SELECT OSVersion = RIGHT(@@version, LEN(@@version)- 3 -charindex (' on ', LOWER(@@version)))";
|
||||
public const string GetClusterEndpoints = @"SELECT [name], [description], [endpoint], [protocol_desc] FROM .[sys].[dm_cluster_endpoints];";
|
||||
public const string GetHostInfo = @"SELECT [host_platform], [host_distribution], [host_release], [host_service_pack_level], [host_sku], [os_language_version] FROM sys.dm_os_host_info";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user