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
927 changes: 927 additions & 0 deletions Darling/Darling.Tests/PgTargetAnomalyTests.cs

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions Darling/Darling.Tests/PgTargetSessionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ public void SessionsAmplifiers_TheParkedShareReadsTheFactItself_TheCpuArmAsksWhe
Assert.False(cpu.Predicate(Lookup(Saturation(90), quietCpu)));
Assert.False(cpu.Predicate(Lookup(Saturation(90))));

/* Through the real scorer: the parked share is the fact's own and fires; the CPU family is a stub (base 0)
so its arm is wired and inert until lane 9 lands its bar. 1.0 × (1 + 0.25) = 1.25. */
/* Through the real scorer: the parked share is the fact's own and fires; a CPU fact whose 95 is the RAW
percent-of-allocated reading (no capacity_measured flag — lane 9's scorer grades only the capacity
percent, #3281) scores 0 and its arm is wired and inert. 1.0 × (1 + 0.25) = 1.25. */
var facts = new List<Fact>
{
Saturation(90, idleInTransaction: 30),
Expand All @@ -229,6 +230,22 @@ public void SessionsAmplifiers_TheParkedShareReadsTheFactItself_TheCpuArmAsksWhe
Assert.True(facts[0].AmplifierResults[0].Matched);
Assert.False(facts[0].AmplifierResults[1].Matched);

/* And with the capacity reading measured at 95% of the configured ceiling the CPU fact fires (1.0) and the
arm lifts saturation to 1.0 × (1 + 0.25 + 0.25) = 1.5 — the D7 "queueing at the cliff" shape. */
var atCapacity = new List<Fact>
{
Saturation(90, idleInTransaction: 30),
new()
{
Source = PgTargetSources.CpuSource, Key = PgTargetFactKeys.CpuPercent, Value = 95,
Metadata = { [PgTargetScorer.CpuCapacityMeasuredKey] = 1 },
},
};
new FactScorer().ScoreAll(atCapacity);
Assert.Equal(1.0, atCapacity[1].BaseSeverity, precision: 9);
Assert.Equal(1.5, atCapacity[0].Severity, precision: 9);
Assert.True(atCapacity[0].AmplifierResults[1].Matched);

/* And below the warning band nothing fires at all — the fact is context, and no sibling can lift it. */
var calm = new List<Fact> { Saturation(70, idleInTransaction: 60), firedCpu };
new FactScorer().ScoreAll(calm);
Expand Down
20 changes: 14 additions & 6 deletions Darling/Darling.Tests/PgTargetSharedSwitchRoutingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,15 @@ public void ThePgRatioAnomaly_TakesThePgRatioRamp_NotTheSqlServerDeadlockSpikeAr
Assert.True(PgTargetScorer.IsPgRatioAnomalyKey(PgTargetFactKeys.AnomalyDeadlockRate));
Assert.False(PgTargetScorer.IsDeviationScoredAnomalyKey(PgTargetFactKeys.AnomalyDeadlockRate));

/* A ratio the SQL Server ANOMALY_DEADLOCK_SPIKE arm would grade at 1.0. The PostgreSQL ramp is lane 9's
and is stubbed at 0 — so 0 here is the ROUTING: had the key reached the SQL Server arm it would read 1.0. */
var fact = Anomaly(PgTargetFactKeys.AnomalyDeadlockRate, ("ratio", 10.0));
/* A ratio the two ramps grade DIFFERENTLY: the SQL Server ANOMALY_DEADLOCK_SPIKE arm (3× → 0.5, 10× → 1.0)
reads 6× as 0.5 + 0.5 × 3/7 = 0.714; the PostgreSQL ramp (lane 9: 3× → 0.5, 9× → 1.0) reads it as 0.75 —
so 0.75 here is the ROUTING, not a coincidence of two ramps agreeing. */
var fact = Anomaly(PgTargetFactKeys.AnomalyDeadlockRate, ("ratio", 6.0));
new FactScorer().ScoreAll([fact]);
Assert.Equal(PgTargetScorer.ScoreRatioAnomaly(fact), fact.BaseSeverity);
Assert.Equal(0.0, fact.BaseSeverity);
Assert.Equal(0.75, fact.BaseSeverity, precision: 9);
Assert.True(PgTargetScorer.IsPgRatioAnomalyKey(PgTargetFactKeys.AnomalyWaitProfile));
Assert.False(PgTargetScorer.IsDeviationScoredAnomalyKey(PgTargetFactKeys.AnomalyWaitProfile));
}

[Fact]
Expand Down Expand Up @@ -327,8 +330,13 @@ family moves its own line here and says so. Lane 5 (the wait profile) moved the
Assert.NotNull(PgTargetAdvice.Static(PgTargetFactKeys.BadActorKey(7)));

/* ANOMALY_PG_WAIT_PROFILE must not fall into the SQL Server ANOMALY_WAIT_ composer, which would render
"Anomalous spike in PG_WAIT_PROFILE" for it. */
Assert.Null(FactAdvice.GetForFactKey(PgTargetFactKeys.AnomalyWaitProfile));
"Anomalous spike in PG_WAIT_PROFILE" for it. Lane 9 filled the anomaly family, so the line moved from
"null" to "the PostgreSQL block, and not the SQL Server one". */
var pgWaitProfile = FactAdvice.GetForFactKey(PgTargetFactKeys.AnomalyWaitProfile);
Assert.NotNull(pgWaitProfile);
Assert.Equal(PgTargetAdvice.Static(PgTargetFactKeys.AnomalyWaitProfile), pgWaitProfile);
Assert.DoesNotContain("Anomalous spike", pgWaitProfile!.Headline, StringComparison.Ordinal);
Assert.NotEqual(FactAdvice.GetForFactKey("ANOMALY_WAIT_PROFILE"), pgWaitProfile);

/* The SQL Server side is untouched. */
Assert.NotNull(FactAdvice.GetForFactKey("CXPACKET"));
Expand Down
Loading
Loading