Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 61 additions & 2 deletions Darling/Darling.Tests/AzureSqlDatabaseMemoryScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void HealthScore_DoesNotDependOnTheEngineEdition(int engineEdition)
[Fact]
public void RightSizedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheDatabasesMemoryLimit()
{
var onAzure = ServerHardwareScope.RightSizedExplanation(40m, 62m, 71.0, azureSqlDatabase: true);
var onBox = ServerHardwareScope.RightSizedExplanation(40m, 62m, 71.0, azureSqlDatabase: false);
var onAzure = ServerHardwareScope.RightSizedExplanation(40m, 62m, 62, 0m, 71.0, azureSqlDatabase: true);
var onBox = ServerHardwareScope.RightSizedExplanation(40m, 62m, 62, 0m, 71.0, azureSqlDatabase: false);

Assert.Equal(
"CPU is moderately loaded (avg 40.0%, p95 62.0%) and memory is well-utilized (buffer pool uses 71% of the database's memory limit). No action needed.",
Expand All @@ -127,6 +127,65 @@ public void RightSizedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheD
onBox);
}

/// <summary>#6646: RIGHT_SIZED is also the verdict for an idle average with one sample at 40% or more. The sentence names the test that
/// decided, says "well-utilized" only for a buffer pool holding at least half of its basis, and names the target the way the
/// edition does ("database" on an Azure SQL Database, "server" elsewhere).</summary>
[Fact]
public void RightSizedSentence_ForAnIdleAverageWithOneBusySample_NamesThePeak_NotAModerateLoadOrWellUtilizedMemory()
{
Assert.Equal(
"CPU averaged 0.1% (p95 0.0%), but one sample reached 40%, so this server is not rated over-provisioned and the buffer pool uses 8% of physical RAM. No action needed.",
ServerHardwareScope.RightSizedExplanation(0.1m, 0m, 40, 10m, 8.0, azureSqlDatabase: false));
Assert.Equal(
"CPU averaged 0.1% (p95 0.0%), but one sample reached 40%, so this database is not rated over-provisioned and the buffer pool uses 8% of the database's memory limit. No action needed.",
ServerHardwareScope.RightSizedExplanation(0.1m, 0m, 40, 10m, 8.0, azureSqlDatabase: true));
}

/// <summary>#6646: with an idle average and no busy sample, only the measured grant utilization holds the verdict at RIGHT_SIZED, so
/// the sentence prints that measurement next to the bar, not the bar alone.</summary>
[Fact]
public void RightSizedSentence_ForAnIdleServerHeldByGrantUse_PrintsTheMeasuredGrantUtilization()
{
Assert.Equal(
"CPU is lightly loaded (avg 5.0%, p95 8.0%), but its memory grants peaked at 62% of their target (threshold: 50%), so this database is not rated over-provisioned and memory is well-utilized (buffer pool uses 60% of the database's memory limit). No action needed.",
ServerHardwareScope.RightSizedExplanation(5m, 8m, 12, 62m, 60.0, azureSqlDatabase: true));
Assert.Equal(
"CPU is lightly loaded (avg 5.0%, p95 8.0%), but its memory grants peaked at 97% of their target (threshold: 50%), so this server is not rated over-provisioned and the buffer pool uses 35% of physical RAM. No action needed.",
ServerHardwareScope.RightSizedExplanation(5m, 8m, 12, 97m, 35.0, azureSqlDatabase: false));
}

/// <summary>#6646: the sentence names the arm that ProvisioningVerdict.Evaluate used for the same inputs. Moving a cut point in
/// Evaluate without the sentence (or the reverse) leaves a RIGHT_SIZED server explained by a cause it does not have.</summary>
[Fact]
public void RightSizedSentence_NamesTheArmThatProvisioningVerdictEvaluateUsed()
{
const string Moderate = "moderately loaded";
const string Peak = "one sample reached";
const string Grants = "memory grants peaked at";

(decimal Avg, int Max, decimal P95, decimal Grant, string Arm)[] cases =
[
(40m, 62, 62m, 0m, Moderate),
(15m, 5, 8m, 0m, Moderate),
(14.9m, 40, 20m, 0m, Peak),
(0.1m, 84, 30m, 0m, Peak),
(5m, 12, 8m, 50m, Grants),
(14.9m, 39, 8m, 99m, Grants),
];

foreach (var (avg, max, p95, grant, arm) in cases)
{
var verdict = ProvisioningVerdict.Evaluate(avg, max, p95, 0, 0, 0, grant, 512, 100);
Assert.Equal(ProvisioningVerdict.RightSized, verdict);

var sentence = ServerHardwareScope.RightSizedExplanation(avg, p95, max, grant, 30.0, azureSqlDatabase: false);
foreach (var other in new[] { Moderate, Peak, Grants })
{
Assert.Equal(other == arm, sentence.Contains(other, StringComparison.Ordinal));
}
}
}

[Fact]
public void OverProvisionedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheDatabasesMemoryLimit()
{
Expand Down
58 changes: 38 additions & 20 deletions Darling/Darling.Tests/FinOpsUtilizationFiguresTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,47 @@ public void HealthBand_AgreesWithScoreColor_ForEveryScore()
}
}

/// <summary>The RIGHT_SIZED sentence for each reason a server is RIGHT_SIZED, written out as literals (not a copy of the switch). The
/// default Dto is a 12.5% average with a 40% peak and a buffer pool at exactly half of physical memory.</summary>
[Theory]
[InlineData("RIGHT_SIZED", 0)]
[InlineData("RIGHT_SIZED", 5)]
[InlineData("OVER_PROVISIONED", 0)]
[InlineData("OVER_PROVISIONED", 5)]
[InlineData("UNDER_PROVISIONED", 0)]
[InlineData("NOT_APPLICABLE", 0)]
[InlineData("", 0)]
public void Explanation_EqualsTheOldSwitch_InTheCurrentCulture(string status, int edition)
[InlineData(0, 40, 12.5, 4000, "CPU averaged 12.5% (p95 35.0%), but one sample reached 40%, so this server is not rated over-provisioned and memory is well-utilized (buffer pool uses 50% of physical RAM). No action needed.")]
[InlineData(5, 40, 12.5, 4000, "CPU averaged 12.5% (p95 35.0%), but one sample reached 40%, so this database is not rated over-provisioned and memory is well-utilized (buffer pool uses 50% of the database's memory limit). No action needed.")]
[InlineData(0, 40, 12.5, 3999, "CPU averaged 12.5% (p95 35.0%), but one sample reached 40%, so this server is not rated over-provisioned and the buffer pool uses 50% of physical RAM. No action needed.")]
[InlineData(0, 70, 30.0, 800, "CPU is moderately loaded (avg 30.0%, p95 35.0%) and the buffer pool uses 10% of physical RAM. No action needed.")]
[InlineData(0, 70, 30.0, 6000, "CPU is moderately loaded (avg 30.0%, p95 35.0%) and memory is well-utilized (buffer pool uses 75% of physical RAM). No action needed.")]
public void Explanation_ForRightSized_NamesTheCauseAndTheMemoryShare(int edition, int max, double avg, int bp, string expected)
{
var dto = Dto("RIGHT_SIZED", edition, avg: (decimal)avg, max: max, bp: bp);
Assert.Equal(expected, FinOpsUtilizationFigures.Explanation(dto, CultureInfo.InvariantCulture));
}

/// <summary>The idle-average, quiet-peak RIGHT_SIZED server is held there by its measured grant utilization, and the sentence prints it.</summary>
[Fact]
public void Explanation_ForRightSized_WithAnIdleQuietServer_PrintsTheMeasuredGrantUtilization()
{
var dto = Dto("RIGHT_SIZED", avg: 5m, max: 12, p95: 8m) with { GrantUtilizationPct = 77m };
Assert.Equal(
"CPU is lightly loaded (avg 5.0%, p95 8.0%), but its memory grants peaked at 77% of their target (threshold: 50%), so this server is not rated over-provisioned and memory is well-utilized (buffer pool uses 50% of physical RAM). No action needed.",
FinOpsUtilizationFigures.Explanation(dto, CultureInfo.InvariantCulture));
}

[Theory]
[InlineData("OVER_PROVISIONED", 0, "CPU is lightly loaded (avg 12.5%, max 40%) and buffer pool uses only 50% of physical RAM. This server may have more resources than it needs.")]
[InlineData("OVER_PROVISIONED", 5, "CPU is lightly loaded (avg 12.5%, max 40%) and buffer pool uses only 50% of the database's memory limit. This database may have more resources than it needs.")]
[InlineData("NOT_APPLICABLE", 0, null)]
[InlineData("", 0, "")]
public void Explanation_ForTheOtherStatuses_IsTheirSentence(string status, int edition, string? expected)
{
var dto = Dto(status, edition, p95: 90m, waiters: 2);
var bpPct = dto.PhysicalMemoryMb > 0 ? (double)dto.BufferPoolMb / dto.PhysicalMemoryMb * 100.0 : 0;
var azure = ServerHardwareScope.HardwareIsTheHosts(dto.EngineEdition);
var old = dto.ProvisioningStatus switch
{
"RIGHT_SIZED" => ServerHardwareScope.RightSizedExplanation(dto.AvgCpuPct, dto.P95CpuPct, bpPct, azure),
"OVER_PROVISIONED" => ServerHardwareScope.OverProvisionedExplanation(dto.AvgCpuPct, dto.MaxCpuPct, bpPct, azure),
"UNDER_PROVISIONED" => ProvisioningVerdict.UnderProvisionedReason(
dto.P95CpuPct, dto.MaxGrantWaiters, dto.GrantTimeouts, dto.ForcedGrants, dto.MaxWorkersCount, dto.CurrentWorkersCount),
ProvisioningVerdict.NotApplicable => ProvisioningVerdict.NotApplicableExplanation,
_ => ""
};
Assert.Equal(old, FinOpsUtilizationFigures.Explanation(dto, CultureInfo.CurrentCulture));
var actual = FinOpsUtilizationFigures.Explanation(dto, CultureInfo.InvariantCulture);
Assert.Equal(expected ?? ProvisioningVerdict.NotApplicableExplanation, actual);
}

[Fact]
public void Explanation_ForUnderProvisioned_SaysWhyItWasFlagged()
{
var dto = Dto("UNDER_PROVISIONED", p95: 90m);
Assert.Contains("90", FinOpsUtilizationFigures.Explanation(dto, CultureInfo.InvariantCulture));
}

/// <summary>#6139: six samples is no verdict, and the sentence says how many the window holds and how many it needs.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static string Explanation(UtilizationEfficiencyDto d, CultureInfo culture
var azureSqlDb = ServerHardwareScope.HardwareIsTheHosts(d.EngineEdition);
return d.ProvisioningStatus switch
{
"RIGHT_SIZED" => ServerHardwareScope.RightSizedExplanation(d.AvgCpuPct, d.P95CpuPct, bpPct, azureSqlDb),
"RIGHT_SIZED" => ServerHardwareScope.RightSizedExplanation(d.AvgCpuPct, d.P95CpuPct, d.MaxCpuPct, d.GrantUtilizationPct, bpPct, azureSqlDb),
"OVER_PROVISIONED" => ServerHardwareScope.OverProvisionedExplanation(d.AvgCpuPct, d.MaxCpuPct, bpPct, azureSqlDb),
/* The reason comes from the same place as the verdict, so a server flagged for grant pressure or
worker saturation is not explained as a memory ratio that no longer decides anything (#2246). */
Expand Down
63 changes: 61 additions & 2 deletions Lite.Tests/AzureSqlDatabaseMemoryScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ UtilizationEfficiencyRow Row(int edition, int physicalMb) => Scored(new Utilizat
[Fact]
public void RightSizedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheDatabasesMemoryLimit()
{
var onAzure = ServerHardwareScope.RightSizedExplanation(40m, 62m, 71.0, azureSqlDatabase: true);
var onBox = ServerHardwareScope.RightSizedExplanation(40m, 62m, 71.0, azureSqlDatabase: false);
var onAzure = ServerHardwareScope.RightSizedExplanation(40m, 62m, 62, 0m, 71.0, azureSqlDatabase: true);
var onBox = ServerHardwareScope.RightSizedExplanation(40m, 62m, 62, 0m, 71.0, azureSqlDatabase: false);

Assert.Equal(
"CPU is moderately loaded (avg 40.0%, p95 62.0%) and memory is well-utilized (buffer pool uses 71% of the database's memory limit). No action needed.",
Expand All @@ -153,6 +153,65 @@ public void RightSizedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheD
onBox);
}

/// <summary>#6646: RIGHT_SIZED is also the verdict for an idle average with one sample at 40% or more. The sentence names the test that
/// decided, says "well-utilized" only for a buffer pool holding at least half of its basis, and names the target the way the
/// edition does ("database" on an Azure SQL Database, "server" elsewhere).</summary>
[Fact]
public void RightSizedSentence_ForAnIdleAverageWithOneBusySample_NamesThePeak_NotAModerateLoadOrWellUtilizedMemory()
{
Assert.Equal(
"CPU averaged 0.1% (p95 0.0%), but one sample reached 40%, so this server is not rated over-provisioned and the buffer pool uses 8% of physical RAM. No action needed.",
ServerHardwareScope.RightSizedExplanation(0.1m, 0m, 40, 10m, 8.0, azureSqlDatabase: false));
Assert.Equal(
"CPU averaged 0.1% (p95 0.0%), but one sample reached 40%, so this database is not rated over-provisioned and the buffer pool uses 8% of the database's memory limit. No action needed.",
ServerHardwareScope.RightSizedExplanation(0.1m, 0m, 40, 10m, 8.0, azureSqlDatabase: true));
}

/// <summary>#6646: with an idle average and no busy sample, only the measured grant utilization holds the verdict at RIGHT_SIZED, so
/// the sentence prints that measurement next to the bar, not the bar alone.</summary>
[Fact]
public void RightSizedSentence_ForAnIdleServerHeldByGrantUse_PrintsTheMeasuredGrantUtilization()
{
Assert.Equal(
"CPU is lightly loaded (avg 5.0%, p95 8.0%), but its memory grants peaked at 62% of their target (threshold: 50%), so this database is not rated over-provisioned and memory is well-utilized (buffer pool uses 60% of the database's memory limit). No action needed.",
ServerHardwareScope.RightSizedExplanation(5m, 8m, 12, 62m, 60.0, azureSqlDatabase: true));
Assert.Equal(
"CPU is lightly loaded (avg 5.0%, p95 8.0%), but its memory grants peaked at 97% of their target (threshold: 50%), so this server is not rated over-provisioned and the buffer pool uses 35% of physical RAM. No action needed.",
ServerHardwareScope.RightSizedExplanation(5m, 8m, 12, 97m, 35.0, azureSqlDatabase: false));
}

/// <summary>#6646: the sentence names the arm that ProvisioningVerdict.Evaluate used for the same inputs. Moving a cut point in
/// Evaluate without the sentence (or the reverse) leaves a RIGHT_SIZED server explained by a cause it does not have.</summary>
[Fact]
public void RightSizedSentence_NamesTheArmThatProvisioningVerdictEvaluateUsed()
{
const string Moderate = "moderately loaded";
const string Peak = "one sample reached";
const string Grants = "memory grants peaked at";

(decimal Avg, int Max, decimal P95, decimal Grant, string Arm)[] cases =
[
(40m, 62, 62m, 0m, Moderate),
(15m, 5, 8m, 0m, Moderate),
(14.9m, 40, 20m, 0m, Peak),
(0.1m, 84, 30m, 0m, Peak),
(5m, 12, 8m, 50m, Grants),
(14.9m, 39, 8m, 99m, Grants),
];

foreach (var (avg, max, p95, grant, arm) in cases)
{
var verdict = ProvisioningVerdict.Evaluate(avg, max, p95, 0, 0, 0, grant, 512, 100);
Assert.Equal(ProvisioningVerdict.RightSized, verdict);

var sentence = ServerHardwareScope.RightSizedExplanation(avg, p95, max, grant, 30.0, azureSqlDatabase: false);
foreach (var other in new[] { Moderate, Peak, Grants })
{
Assert.Equal(other == arm, sentence.Contains(other, StringComparison.Ordinal));
}
}
}

[Fact]
public void OverProvisionedSentence_OnAzureSqlDatabase_CitesTheBufferPoolShare_OfTheDatabasesMemoryLimit()
{
Expand Down
2 changes: 1 addition & 1 deletion Lite/Controls/FinOpsTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ scheduler count it can see is never shown as the CPU it is given. */
/* Contextual explanation — one sentence describing WHY this classification */
ClassificationExplanation.Text = data.ProvisioningStatus switch
{
"RIGHT_SIZED" => ServerHardwareScope.RightSizedExplanation(data.AvgCpuPct, data.P95CpuPct, bpPct, azureSqlDb),
"RIGHT_SIZED" => ServerHardwareScope.RightSizedExplanation(data.AvgCpuPct, data.P95CpuPct, data.MaxCpuPct, data.GrantUtilizationPct, bpPct, azureSqlDb),
"OVER_PROVISIONED" => ServerHardwareScope.OverProvisionedExplanation(data.AvgCpuPct, data.MaxCpuPct, bpPct, azureSqlDb),
/* The reason comes from the same place as the verdict. This branch used to read
"P95CpuPct > 85 ? CPU : memory ratio is {x} (threshold: 0.95)", so a server flagged for grant
Expand Down
4 changes: 4 additions & 0 deletions PerformanceMonitor.Common/ProvisioningVerdict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public static class ProvisioningVerdict
/// The one place the number lives. It is also where the Stolen Mem % figure starts to read amber.</summary>
public const decimal HighStolenMemoryPercent = 60m;

/// <summary>A chosen value, not a measured one (#6646): the share of the memory basis the buffer pool must hold for a RIGHT_SIZED
/// sentence to call memory "well-utilized". It decides wording only, never the verdict.</summary>
public const double WellUtilizedBufferPoolPercent = 50.0;

/// <summary>Too few CPU samples in the window to say (<see cref="MinSamples"/>).</summary>
public const string NotEnoughData = "NOT_ENOUGH_DATA";

Expand Down
Loading
Loading