On SQL Server 2005 twenty rules stood as "not measurable" (Query Store, system_health, memory columns …) between the real gaps, and counted in the overview's "regler ikke målbare". They are not gaps: the version simply lacks what they look at. - New RuleOutcome.NotApplicable (last in the enum: outcomes are stored as numbers, so existing rows keep their meaning). - A rule or collector missing only capabilities inherent to the instance (version-gated, plan cache memory columns, or Azure-managed) is not applicable, with the version each needs: "Ikke relevant for SQL Server 2005: kræver QueryStore (fra SQL Server 2016)". Missing settings or rights (HADR not enabled …), collector failures and permission errors stay "not measurable". CollectedData.MarkNotApplicable carries this from collectors to the rules that use their data; community rules below their minimumVersion are not applicable too. - Counts are unchanged in shape: the overview, KPI, JSON API and Prometheus count outcomes 2 and 3 only. The instance page lists the rest in a collapsed "Ikke relevant for SQL Server 2005 (n)" (details/summary, no JS) after the real gaps. Report controls whose core rule does not apply count neither as met nor as not measured. Tests: engine (version vs. setting vs. collected data), inherent capabilities, the existing version tests now expect not applicable, report control status, and the web page and overview count. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
using SQLInsight.Core.Instances;
|
|
using SQLInsight.Rules.Engine;
|
|
using static SQLInsight.Rules.Tests.TestInstances;
|
|
|
|
namespace SQLInsight.Rules.Tests;
|
|
|
|
public class ManagedInstanceTests
|
|
{
|
|
private static RuleContext ManagedInstance()
|
|
{
|
|
var info = new InstanceInfo
|
|
{
|
|
ServerName = "mi-prod.abc123.database.windows.net",
|
|
Version = SqlServerVersion.Parse("12.0.2000.8"),
|
|
Edition = "SQL Azure",
|
|
EngineEdition = EngineEdition.AzureSqlManagedInstance,
|
|
};
|
|
var context = new RuleContext(info, InstanceCapabilities.From(info), Now);
|
|
context.Data.Set(Config(("max server memory (MB)", 2147483647), ("cost threshold for parallelism", 5), ("max degree of parallelism", 0), ("xp_cmdshell", 0)));
|
|
context.Data.Set(Server(cpus: 8));
|
|
context.Data.Set(DatabaseList(Database(change: d => d with { LastFullBackup = null, LastGoodCheckDb = new DateTime(1900, 1, 1) })));
|
|
return context;
|
|
}
|
|
|
|
[Fact]
|
|
public void Azure_managed_areas_are_reported_as_handled_by_azure_not_as_findings()
|
|
{
|
|
var results = new RuleEngine(BuiltInRules.Create()).Evaluate(ManagedInstance());
|
|
|
|
foreach (var id in new[] { "SQLI-VER-001", "SQLI-VER-002", "SQLI-CFG-001", "SQLI-DB-007", "SQLI-DB-009", "SQLI-DB-015" })
|
|
{
|
|
var result = results.Single(r => r.RuleId == id);
|
|
Assert.Equal(RuleOutcome.NotApplicable, result.Outcome);
|
|
Assert.Equal("Håndteres af Azure på Azure SQL Managed Instance.", result.Reason);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Workload_rules_still_apply()
|
|
{
|
|
var results = new RuleEngine(BuiltInRules.Create()).Evaluate(ManagedInstance());
|
|
|
|
Assert.Equal(RuleOutcome.Findings, results.Single(r => r.RuleId == "SQLI-CFG-003").Outcome); // cost threshold 5
|
|
}
|
|
}
|