From 210a2f59ef5f519ce17a8aad1a1e8b8b9c13abb6 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Sat, 24 Oct 2026 04:09:23 -0400 Subject: [PATCH 1/3] Alert texts: the word agrees with the count (#6703) Replace the count-then-word(s) forms in alert bodies, self-alert texts, MCP alert answers and the shared engine texts with the singular for 1 and the plural otherwise, with the verb agreeing. --- Darling/Darling.Tests/AlertEngineTests.cs | 59 +++++++--- .../DarlingPgOperationalAlertTests.cs | 23 +++- .../Darling.Tests/DarlingSelfAlertTests.cs | 103 +++++++++++++++++- .../IncidentDeliveryFilterTests.cs | 22 +++- Darling/Darling.Tests/McpPageContractTests.cs | 2 +- .../PolicyJobFailingRetryTests.cs | 4 +- .../RepeatDeliveryBudgetTests.cs | 35 +++++- .../RunnableQueueAlertDetailTests.cs | 2 +- .../Darling.Tests/RunnableQueueRound1Tests.cs | 13 ++- .../StoreToastAndCheckpointerTests.cs | 14 +-- .../DarlingSelfAlertEvaluator.cs | 46 ++++---- .../DarlingWorker.cs | 10 +- .../Mcp/DarlingMcpAlertTools.cs | 4 +- Lite.Tests/AlertContextBuildersTests.cs | 6 +- Lite.Tests/AlertValueParserTests.cs | 2 +- .../BlockingDeadlockContextBuilderTests.cs | 6 +- Lite.Tests/LiteAlertForwardingTests.cs | 43 ++++++-- Lite.Tests/McpPageContractTests.cs | 14 ++- Lite/Mcp/McpAlertTools.cs | 4 +- .../AlertContextBuilders.cs | 10 +- PerformanceMonitor.Alerting/AlertEngine.cs | 18 +-- .../IncidentDeliveryFilter.cs | 5 +- .../PerEventNotification.cs | 2 +- .../RepeatDeliveryBudget.cs | 4 +- 24 files changed, 341 insertions(+), 110 deletions(-) diff --git a/Darling/Darling.Tests/AlertEngineTests.cs b/Darling/Darling.Tests/AlertEngineTests.cs index 08185a2ab9..2bb23dd55f 100644 --- a/Darling/Darling.Tests/AlertEngineTests.cs +++ b/Darling/Darling.Tests/AlertEngineTests.cs @@ -1366,6 +1366,9 @@ public async Task AzureMaster_EventsForADatabaseNotInTheList_StillAlert() Assert.Contains(h.Deliverer.Outcomes, o => o.MetricName == "Blocking Detected"); Assert.Contains(h.Deliverer.Outcomes, o => o.MetricName == "Deadlocks Detected"); + /* #6703: a count of one reads in the singular. */ + Assert.Equal("1 blocking session", Assert.Single(h.Deliverer.Outcomes, o => o.MetricName == "Blocking Detected").ShortMessage); + Assert.Equal("1 deadlock in the last hour", Assert.Single(h.Deliverer.Outcomes, o => o.MetricName == "Deadlocks Detected").ShortMessage); } [Fact] @@ -1382,7 +1385,7 @@ public async Task AzureMaster_Blocking_CountAndWatermarkCoverOnlyTheUnlistedData var outcome = Assert.Single(h.Deliverer.Outcomes, o => o.MetricName == "Blocking Detected"); Assert.Equal("2", outcome.CurrentValue); - Assert.Equal("2 blocking session(s)", outcome.ShortMessage); + Assert.Equal("2 blocking sessions", outcome.ShortMessage); Assert.Equal(2, h.StateStore.EdgeWatermarks[(Key, AlertEngine.BlockingWatermarkMetric)]); } @@ -1400,7 +1403,7 @@ public async Task AzureMaster_Deadlocks_CountAndWatermarkCoverOnlyTheUnlistedDat var outcome = Assert.Single(h.Deliverer.Outcomes, o => o.MetricName == "Deadlocks Detected"); Assert.Equal("2", outcome.CurrentValue); - Assert.Equal("2 deadlock(s) in the last hour", outcome.ShortMessage); + Assert.Equal("2 deadlocks in the last hour", outcome.ShortMessage); Assert.Equal(2, h.StateStore.EdgeWatermarks[(Key, AlertEngine.DeadlockWatermarkMetric)]); } @@ -1498,7 +1501,7 @@ public async Task BlockingWait_FiresAtThresholdInclusive_WithRealNumericsAndCont await DriveBlockingWaitAsync(engine, h, 600_000, samples: AlertEngine.BlockingWaitBreachSamples, from: Harness.SampleBase); var fired = Assert.Single(h.Deliverer.Outcomes, o => o.MetricName == "Blocking Wait Time"); - Assert.Equal("600s across 3 blocked session(s)", fired.CurrentValue); + Assert.Equal("600s across 3 blocked sessions", fired.CurrentValue); Assert.Equal("600s", fired.ThresholdValue); /* #1830: the numerics must carry the real values — the display text is prose no parser recovers. */ Assert.Equal(600d, fired.NumericCurrentValue); @@ -1544,7 +1547,7 @@ public async Task BlockingWait_ASingleSnapshotAtThreeTimesTheBar_FiresAtOnce_And var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Blocking Wait Time", fired.MetricName); - Assert.Equal("180s across 145 blocked session(s)", fired.CurrentValue); + Assert.Equal("180s across 145 blocked sessions", fired.CurrentValue); Assert.Equal(AlertEngine.BlockingWaitFiredBySingleSnapshot, FiredBy(fired)); var gateItem = fired.Context!.Details[0]; Assert.Equal("180s", Assert.Single(gateItem.Fields, f => f.Label == "Total Blocked Wait").Value); @@ -2756,7 +2759,7 @@ public async Task LongRunningQuery_ForwardsEverySettingsKnobToTheAdapter_AndFire var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Long-Running Query", fired.MetricName); - Assert.Equal("1 query(s), longest 35m", fired.CurrentValue); /* :385 */ + Assert.Equal("1 query, longest 35m", fired.CurrentValue); /* :385 */ Assert.Equal("30m", fired.ThresholdValue); Assert.Equal(35d, fired.NumericCurrentValue); /* :389 */ @@ -2843,7 +2846,7 @@ service logins (multi-day CDC-shaped background), the application's admin login var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Long-Running Query", fired.MetricName); - Assert.Equal("2 query(s), longest 66m", fired.CurrentValue); + Assert.Equal("2 queries, longest 66m", fired.CurrentValue); Assert.StartsWith("Session #65 running 66m", fired.ShortMessage, StringComparison.Ordinal); /* The excluded sessions are not on the card as SESSIONS (the knob item lists the prefix itself, by design). */ Assert.DoesNotContain("Job 0x", fired.DetailText, StringComparison.Ordinal); @@ -2866,7 +2869,7 @@ public async Task LongRunningQuery_AnExcludedSessionIsNotEvaluated_AndTheCardCou { /* Measured on one production store class: 191 distinct sessions over the 30-minute bar in 7 days, the p90 seen in 6,192 snapshots — permanent background requests no gate can separate from a runaway query. With - the knob set, the permanent session is not read into the decision at all (not counted in "N query(s)", + the knob set, the permanent session is not read into the decision at all (not counted in "N queries", not the longest, not fingerprinted), and the card's knob item says how many the knob removed, by arm, so the operator can see it working. */ var h = new Harness(); @@ -2883,7 +2886,7 @@ the operator can see it working. */ var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Long-Running Query", fired.MetricName); /* One query, and the longest is the 35-minute one — the two permanent sessions never entered the count. */ - Assert.Equal("1 query(s), longest 35m", fired.CurrentValue); + Assert.Equal("1 query, longest 35m", fired.CurrentValue); Assert.Equal(35d, fired.NumericCurrentValue); Assert.StartsWith("Session #73 running 35m", fired.ShortMessage, StringComparison.Ordinal); @@ -2923,7 +2926,7 @@ matches nothing real — the entry is listed on the card so the misspelling is v await h.Build().EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); - Assert.Equal("2 query(s), longest 150m", fired.CurrentValue); + Assert.Equal("2 queries, longest 150m", fired.CurrentValue); var knobItem = fired.Context!.Details[^1]; Assert.Equal("0", Assert.Single(knobItem.Fields, f => f.Label == AlertContextBuilders.LongRunningQueryExcludedCountLabel).Value); Assert.Equal("SQLAgent - TSQL JobStep*", Assert.Single(knobItem.Fields, f => f.Label == "Excluded Program Prefixes").Value); @@ -3006,7 +3009,7 @@ public async Task LongRunningQuery_ExcludedDatabasesAreRemovedAheadOfTheCap_AndT runs long; on a server where that ETL holds the SIX longest sessions and the cap is five, the old post-read filter returned an EMPTY page — five excluded rows read, five dropped — and the alert was off for every other database without a word. With the list applied in the read, the human's query is on - the page, the fire says "1 query(s)", and the card's new item says six sessions were in excluded + the page, the fire says "1 query", and the card's new item says six sessions were in excluded databases — so a short page is a page an operator can read. */ var h = new Harness(); h.Settings.LongRunningQueryEnabled = true; @@ -3023,7 +3026,7 @@ public async Task LongRunningQuery_ExcludedDatabasesAreRemovedAheadOfTheCap_AndT var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Long-Running Query", fired.MetricName); - Assert.Equal("1 query(s), longest 35m", fired.CurrentValue); + Assert.Equal("1 query, longest 35m", fired.CurrentValue); Assert.StartsWith("Session #73 running 35m", fired.ShortMessage, StringComparison.Ordinal); /* None of the six ETL sessions is on the card as a session — not their text, not their ids. */ Assert.DoesNotContain("FactSales", fired.DetailText, StringComparison.Ordinal); @@ -3085,7 +3088,7 @@ public async Task LongRunningQuery_TheKnobAndTheDatabaseListCompose_ASessionBoth await h.Build().EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); - Assert.Equal("1 query(s), longest 35m", fired.CurrentValue); + Assert.Equal("1 query, longest 35m", fired.CurrentValue); /* Knob item first (61 and 65 by prefix; 62 by login), database item last (63 and 64) — 2 + 1 + 2 = 5, the five sessions the page does not show, each counted exactly once. */ @@ -3279,7 +3282,7 @@ public async Task Cpu_ConcurrentMaintenanceSessions_OneLineEach_CappedWithAState var detail = Assert.Single(h.Deliverer.Outcomes).DetailText!; Assert.Equal(AlertContextBuilders.ActiveMaintenanceMaxLines, detail.Split('\n').Count(line => line.Contains("Active maintenance: BACKUP DATABASE", StringComparison.Ordinal))); - Assert.EndsWith("Active maintenance: 2 more maintenance session(s) not shown", detail, StringComparison.Ordinal); + Assert.EndsWith("Active maintenance: 2 more maintenance sessions not shown", detail, StringComparison.Ordinal); Assert.Contains("10m 0s elapsed", detail, StringComparison.Ordinal); } @@ -4408,7 +4411,7 @@ NEW run of the same job alerts without waiting out the old run's cooldown. */ await engine.EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Long-Running Job", fired.MetricName); - Assert.Equal("1 job(s) exceeding 3x average", fired.CurrentValue); /* :606 */ + Assert.Equal("1 job exceeding 3x average", fired.CurrentValue); /* :606 */ Assert.Equal(400d, fired.NumericCurrentValue); /* :610 */ Assert.Equal(300d, fired.NumericThresholdValue); /* :611 multiplier*100 */ @@ -4460,6 +4463,29 @@ fresh evidence resumes real evaluation. */ Assert.Equal("Long-Running Jobs Cleared", Assert.Single(h.Resolutions).Title); } + [Fact] + public async Task AnomalousJob_TwoJobsReadInThePlural() + { + /* #6703: "2 jobs exceeding", where one job reads "1 job exceeding". */ + var h = new Harness(); + h.Settings.LongRunningJobEnabled = true; + var start = new DateTime(2026, 7, 1, 11, 0, 0); + h.Adapter.AnomalousJobs.Add(new AnomalousJobInfo + { + JobName = "Nightly ETL", JobId = "job-1", StartTime = start, + CurrentDurationSeconds = 3600, AvgDurationSeconds = 900, PercentOfAverage = 400 + }); + h.Adapter.AnomalousJobs.Add(new AnomalousJobInfo + { + JobName = "Index Rebuild", JobId = "job-2", StartTime = start, + CurrentDurationSeconds = 3600, AvgDurationSeconds = 900, PercentOfAverage = 400 + }); + + await h.Build().EvaluateServerAsync(Harness.Snapshot()); + + Assert.Equal("2 jobs exceeding 3x average", Assert.Single(h.Deliverer.Outcomes).CurrentValue); + } + /* ---------------- failed jobs ---------------- */ [Fact] @@ -4477,7 +4503,7 @@ public async Task FailedJobs_WatermarkDedups_AndPersistsTheServerLocalRunTime() await engine.EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Failed Agent Job", fired.MetricName); - Assert.Equal("1 job failure(s) in last 60m — Backup.Full", fired.CurrentValue); /* :701 */ + Assert.Equal("1 job failure in last 60m — Backup.Full", fired.CurrentValue); /* :701 */ Assert.Equal((Key, firstFailure), Assert.Single(h.StateStore.SavedFailedJob)); /* The same failure lingering in the lookback window never re-fires (:667). */ @@ -4491,6 +4517,9 @@ public async Task FailedJobs_WatermarkDedups_AndPersistsTheServerLocalRunTime() await engine.EvaluateServerAsync(Harness.Snapshot()); Assert.Equal(2, h.Deliverer.Outcomes.Count); Assert.Equal(firstFailure.AddMinutes(30), h.StateStore.FailedJobWatermarks[Key]); + /* #6703: two failures in the window read "2 job failures", the one-failure fire above "1 job failure". */ + Assert.StartsWith("2 job failures in last 60m", h.Deliverer.Outcomes[1].CurrentValue, StringComparison.Ordinal); + Assert.StartsWith("2 job failures", h.Deliverer.Outcomes[1].ShortMessage, StringComparison.Ordinal); } /// diff --git a/Darling/Darling.Tests/DarlingPgOperationalAlertTests.cs b/Darling/Darling.Tests/DarlingPgOperationalAlertTests.cs index e3eb3181fb..ae989321c4 100644 --- a/Darling/Darling.Tests/DarlingPgOperationalAlertTests.cs +++ b/Darling/Darling.Tests/DarlingPgOperationalAlertTests.cs @@ -92,7 +92,20 @@ public void BuildPgDeadlockIncident_FallsBackToPidAndParticipantCount_WhenVictim var incident = DarlingWorker.BuildPgDeadlockIncident( DeadlockRow("hash-2", victimStatement: null, victimPid: 555, participantCount: 3)); - Assert.Equal("victim pid 555, 3 participant(s)", incident.InvolvedObjects[0]); + Assert.Equal("victim pid 555, 3 participants", incident.InvolvedObjects[0]); + } + + [Fact] + public void BuildPgIncidents_WithACountOfOne_ReadInTheSingular() + { + /* #6703: "1 participant" and "blocking 1 session", where the counts above read in the plural. */ + var deadlock = DarlingWorker.BuildPgDeadlockIncident( + DeadlockRow("hash-2", victimStatement: null, victimPid: 555, participantCount: 1)); + Assert.Equal("victim pid 555, 1 participant", deadlock.InvolvedObjects[0]); + + var blocking = DarlingWorker.BuildPgBlockingIncident( + BlockingRow(rootBackendId: 1, rootPid: 42, totalVictims: 1, databases: Array.Empty(), rootQuery: null)); + Assert.Equal("root pid 42 blocking 1 session", blocking.InvolvedObjects[0]); } [Fact] @@ -229,7 +242,7 @@ public void BuildPgBlockingIncident_IncludesDatabaseRootPidVictimCountAndQuery() var incident = DarlingWorker.BuildPgBlockingIncident( BlockingRow(rootBackendId: 1, rootPid: 42, totalVictims: 5, databases: new[] { "sales" }, rootQuery: "SELECT * FROM x")); - Assert.Equal("root pid 42 blocking 5 session(s) in [sales]: SELECT * FROM x", incident.InvolvedObjects[0]); + Assert.Equal("root pid 42 blocking 5 sessions in [sales]: SELECT * FROM x", incident.InvolvedObjects[0]); Assert.Equal("sales", incident.Database); } @@ -239,7 +252,7 @@ public void BuildPgBlockingIncident_OmitsTrailingQueryClause_WhenRootQueryIsMiss var incident = DarlingWorker.BuildPgBlockingIncident( BlockingRow(rootBackendId: 1, rootPid: 42, totalVictims: 2, databases: new[] { "sales" }, rootQuery: null)); - Assert.Equal("root pid 42 blocking 2 session(s) in [sales]", incident.InvolvedObjects[0]); + Assert.Equal("root pid 42 blocking 2 sessions in [sales]", incident.InvolvedObjects[0]); } [Fact] @@ -272,7 +285,7 @@ public void BuildPgBlockingIncident_OmitsDatabaseClause_WhenNoDatabasesResolved( var incident = DarlingWorker.BuildPgBlockingIncident( BlockingRow(rootBackendId: 1, rootPid: 42, totalVictims: 2, databases: Array.Empty(), rootQuery: null)); - Assert.Equal("root pid 42 blocking 2 session(s)", incident.InvolvedObjects[0]); + Assert.Equal("root pid 42 blocking 2 sessions", incident.InvolvedObjects[0]); Assert.Null(incident.Database); } @@ -491,7 +504,7 @@ await deliverer.DeliverAsync( }, DetailText: null, NumericCurrentValue: 3, NumericThresholdValue: 1, Muted: false, Severity: AlertEngine.GradeDeadlockFire(3, settings.DeadlockRateThresholds), - ShortMessage: "3 deadlock(s) in the last hour"), + ShortMessage: "3 deadlocks in the last hour"), TestContext.Current.CancellationToken); /* The CPU arm's shape: no context at all, the grade on the outcome. */ diff --git a/Darling/Darling.Tests/DarlingSelfAlertTests.cs b/Darling/Darling.Tests/DarlingSelfAlertTests.cs index 814c3fa259..f1b7b68239 100644 --- a/Darling/Darling.Tests/DarlingSelfAlertTests.cs +++ b/Darling/Darling.Tests/DarlingSelfAlertTests.cs @@ -730,6 +730,7 @@ public async Task CaptureDown_FiresOnce_ThenRestoredHistoryRow() Assert.Equal("Capture Down", fired.MetricName); Assert.Equal("Blocking and Deadlock", fired.CurrentValue); Assert.Equal(AlertSeverityLevel.Critical, fired.Severity); + Assert.Contains("The Blocking and Deadlock Extended Events sessions are missing", fired.DetailText, StringComparison.Ordinal); /* Still down a minute later: a state alert (#5493) sends once per occurrence, no re-fire. */ h.Now = h.Now.AddMinutes(1); @@ -754,6 +755,18 @@ public async Task CaptureDown_BlockingAndDeadlockDisabled_DoesNotFire() Assert.Empty(h.Deliverer.Outcomes); } + [Fact] + public async Task CaptureDown_OneMissingSession_ReadsInTheSingular() + { + var h = new Harness(); + var e = h.Build(); + + await e.ApplyCaptureDownAsync(ServerId, Name, new[] { "Blocking" }, Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.Contains("The Blocking Extended Events session is missing", fired.DetailText, StringComparison.Ordinal); + } + /* ---------------- agent-not-running edge (#1433 Phase 2) ---------------- */ [Fact] @@ -1321,12 +1334,25 @@ public async Task CustomRuleHealth_ManyBroken_AggregatesToOneAlert_AndNeverEmits Assert.Equal("customalerts", fired.ServerKey); // fleet sentinel key, not a real server_id Assert.Equal(DarlingSelfAlertEvaluator.StoreServerLabel, fired.ServerName); Assert.Equal("3", fired.CurrentValue); // the count of unhealthy rules + Assert.StartsWith("3 custom alert rules need attention:", fired.ShortMessage, StringComparison.Ordinal); Assert.Contains("Rule 1", fired.DetailText); Assert.Contains("Rule 3", fired.DetailText); // The detail carries the rule id/name + reason, NEVER the compiled SQL. Assert.DoesNotContain("SELECT", fired.DetailText!, StringComparison.OrdinalIgnoreCase); } + [Fact] + public async Task CustomRuleHealth_OneRule_ReadsInTheSingular() + { + var h = new Harness(); + var e = h.Build(); + + await e.ApplyCustomRuleHealthAsync(HealthReport(broken: 1, neverFiring: 0), Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.StartsWith("1 custom alert rule needs attention:", fired.ShortMessage, StringComparison.Ordinal); + } + [Fact] public async Task CustomRuleHealth_ListsNeverFiringRules_UnderTheirOwnHeading() { @@ -1457,6 +1483,19 @@ public async Task StaleMute_UnboundedRulePastTheAge_FiresOnce_WithTheCountAndThe Assert.Equal(AlertSeverityLevel.Warning, fired.Severity); // scoped rule: one signal hidden Assert.Contains("Rule rule-a", fired.DetailText); Assert.Contains("never expires", fired.DetailText); + Assert.StartsWith("1 mute rule has been suppressing", fired.ShortMessage, StringComparison.Ordinal); + } + + [Fact] + public async Task StaleMute_TwoRules_ReadInThePlural() + { + var h = new Harness(); + var e = h.Build(); + + await e.ApplyStaleMuteRulesAsync(new[] { Mute(StaleDays + 1), Mute(StaleDays + 2, id: "rule-b") }, Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.StartsWith("2 mute rules have been suppressing", fired.ShortMessage, StringComparison.Ordinal); } /* ---------------- managed store settings needing attention (#4215) ---------------- */ @@ -4542,7 +4581,7 @@ that treated an absent baseline as 0 would page about the store's whole history. Assert.Equal("Store Job Failing", fired.MetricName); Assert.Equal("jobfailing:7001", fired.ServerKey); Assert.Null(fired.Severity); /* no override: the DECLARED INFO arm in AlertSeverity.ForMetric decides */ - Assert.Contains("2 new failure(s), 14 total", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("2 new failures, 14 total", fired.CurrentValue, StringComparison.Ordinal); Assert.Contains("refresh job 7001 on wait_stats_hourly", fired.ShortMessage, StringComparison.Ordinal); /* Pass 3 — the counter did NOT grow, and last_run_status is still 'Failed' (it says Failed until the @@ -6617,6 +6656,64 @@ await e.ApplyRawPurgeOverHorizonAsync( Assert.Equal(DarlingSelfAlertEvaluator.RawPurgeOverHorizonClearedMetric, resolved.MetricName); } + [Fact] + public async Task ComposeHoursStuck_TwoHours_ReadInThePlural() + { + var h = new Harness(); + var e = h.Build(); + + await e.ApplyComposeHoursStuckAsync(new[] + { + ComposeFailure(2, inBackoff: true), + ComposeFailure(3, inBackoff: true) with { Hour = new DateTime(2026, 10, 15, 9, 0, 0) }, + }, Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.Equal("2 hours", fired.CurrentValue); + Assert.Contains("2 hours of the Query Store compose rollup", fired.DetailText, StringComparison.Ordinal); + Assert.Contains("and are now retried once a day", fired.DetailText, StringComparison.Ordinal); + Assert.StartsWith("2 Query Store compose hours retried once a day", fired.ShortMessage, StringComparison.Ordinal); + } + + [Fact] + public async Task ComposeHoursStuck_OneHourWithOneFailure_ReadsInTheSingular() + { + var h = new Harness(); + var e = h.Build(); + + await e.ApplyComposeHoursStuckAsync(new[] { ComposeFailure(1, inBackoff: true) }, Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.Equal("1 hour", fired.CurrentValue); + Assert.Contains("and is now retried once a day", fired.DetailText, StringComparison.Ordinal); + Assert.Contains("2026-10-07 15:00 UTC: 1 failure, last reason", fired.DetailText, StringComparison.Ordinal); + Assert.StartsWith("1 Query Store compose hour retried once a day", fired.ShortMessage, StringComparison.Ordinal); + } + + [Fact] + public async Task PolicyJobFailing_OneNewFailure_ReadsInTheSingular() + { + var h = new Harness(); + var e = h.Build(); + var rearm = new RearmRecorder(); + + StorePolicyJobHealth Pass(long failures) => new( + Array.Empty(), + new[] + { + new PolicyJobRunReading( + 7001, TimescaleSupport.StorePolicyJobFamily.Refresh, "wait_stats_hourly", false, "Failed", failures), + }); + + await e.ApplyPolicyJobsStuckAsync(Pass(12), rearm.Delegate, Ct); + h.Now = h.Now.AddHours(1); + await e.ApplyPolicyJobsStuckAsync(Pass(13), rearm.Delegate, Ct); + + var fired = Assert.Single(h.Deliverer.Outcomes); + Assert.Contains("1 new failure, 13 total", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("failed 1 more time since the last sample", fired.ShortMessage, StringComparison.Ordinal); + } + private static QueryStoreComposeStamp.HourFailure ComposeFailure(int failures, bool inBackoff) => new(new DateTime(2026, 10, 7, 15, 0, 0), failures, "57014", "canceling statement due to statement timeout", 240, new DateTime(2026, 10, 15, 14, 5, 0), new DateTime(2026, 10, 15, 16, 5, 0), new DateTime(2026, 10, 16, 16, 5, 0), inBackoff); @@ -6635,8 +6732,8 @@ public async Task ComposeHoursStuck_FiresForAnHourInBackoff_NotForOneStillRetrie await e.ApplyComposeHoursStuckAsync(new[] { ComposeFailure(2, inBackoff: true), ComposeFailure(1, inBackoff: false) with { Hour = new DateTime(2026, 10, 15, 9, 0, 0) } }, Ct); var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal(DarlingSelfAlertEvaluator.ComposeHoursStuckMetric, fired.MetricName); - Assert.Contains("1 hour(s) of the Query Store compose rollup", fired.DetailText, StringComparison.Ordinal); - Assert.Contains("2026-10-07 15:00 UTC: 2 failure(s), last reason 57014: canceling statement due to statement timeout", fired.DetailText, StringComparison.Ordinal); + Assert.Contains("1 hour of the Query Store compose rollup", fired.DetailText, StringComparison.Ordinal); + Assert.Contains("2026-10-07 15:00 UTC: 2 failures, last reason 57014: canceling statement due to statement timeout", fired.DetailText, StringComparison.Ordinal); await e.ApplyComposeHoursStuckAsync(Array.Empty(), Ct); var resolved = Assert.Single(h.History.Records); diff --git a/Darling/Darling.Tests/IncidentDeliveryFilterTests.cs b/Darling/Darling.Tests/IncidentDeliveryFilterTests.cs index f8b9e35f49..a75feb11b8 100644 --- a/Darling/Darling.Tests/IncidentDeliveryFilterTests.cs +++ b/Darling/Darling.Tests/IncidentDeliveryFilterTests.cs @@ -42,7 +42,7 @@ public sealed class IncidentDeliveryFilterTests private const string Stale = "bf7e29b4cooldowninwindow"; private const string Fresh = "9d5ead0aoutsideitswindow"; - private const string Footer = "1 other incident(s) still open (already reported)"; + private const string Footer = "1 other incident still open (already reported)"; private static readonly AlertBranding Branding = new("Test Edition", null); @@ -107,6 +107,26 @@ public void ABatchWhoseEveryFingerprintIsFresh_IsReturnedUnfiltered() render.Context!.Details, d => d.Heading == IncidentDeliveryFilter.OtherIncidentsHeading); } + /// #6703: the footer's noun agrees with the held-back count; the one-incident form is Footer. + [Fact] + public void TwoHeldBackIncidents_AreFootnotedInThePlural() + { + var context = new AlertContext(); + AlertIncidentRenderer.Apply(context, new[] + { + new AlertIncident(Stale, new[] { "SalesDb.dbo.Orders" }, TotalOccurrences: 1), + new AlertIncident(Fresh, new[] { "SalesDb.dbo.Shipments" }, TotalOccurrences: 1), + new AlertIncident("c3d4e5f6thirdincidentinwindow", new[] { "SalesDb.dbo.Items" }, TotalOccurrences: 1), + }); + + var render = IncidentDeliveryFilter.ForDelivery(context, null, new[] { Fresh }); + + Assert.Equal(2, render.SuppressedIncidentCount); + var footer = Assert.Single( + render.Context!.Details, d => d.Heading == IncidentDeliveryFilter.OtherIncidentsHeading); + Assert.Contains(footer.Fields, f => f.Value == "2 other incidents still open (already reported)"); + } + /// /// #5641 review: a tier escalation's cooldown bypass is about the firing, so both delivery copies keep it (the /// filtered render and the roster press), and a context that is not an escalation stays unflagged. diff --git a/Darling/Darling.Tests/McpPageContractTests.cs b/Darling/Darling.Tests/McpPageContractTests.cs index 77b5c0de69..148956a5f7 100644 --- a/Darling/Darling.Tests/McpPageContractTests.cs +++ b/Darling/Darling.Tests/McpPageContractTests.cs @@ -1604,7 +1604,7 @@ await DarlingMcpTestData.ExecAsync(connection, ct, await DarlingMcpTestData.ExecAsync(connection, ct, $"UPDATE config_alert_log SET dismissed = TRUE WHERE server_id = {ServerId}"); var allDismissed = await DarlingMcpAlertTools.GetAlertHistory(postgres, ServerName, 24, 50); Assert.Equal("empty", DarlingMcpTestData.StatusOf(allDismissed)); - Assert.Contains("5 dismissed alert(s) were excluded", allDismissed, StringComparison.Ordinal); + Assert.Contains("5 dismissed alerts were excluded", allDismissed, StringComparison.Ordinal); bodySucceeded = true; } diff --git a/Darling/Darling.Tests/PolicyJobFailingRetryTests.cs b/Darling/Darling.Tests/PolicyJobFailingRetryTests.cs index a75d8b2cdf..87f5596313 100644 --- a/Darling/Darling.Tests/PolicyJobFailingRetryTests.cs +++ b/Darling/Darling.Tests/PolicyJobFailingRetryTests.cs @@ -109,7 +109,7 @@ public async Task APendingRetry_KeepsTheBaseline_SoASweepInsideTheDelayDoesNotEa /* The retry is due and still reports the three failures. */ await rig.PassAsync(TimeSpan.FromHours(1) + TimeSpan.FromSeconds(60), 3); Assert.Equal(2, rig.Deliverer.Outcomes.Count); - Assert.Equal("3 new failure(s), 3 total", rig.Deliverer.Outcomes[1].CurrentValue); + Assert.Equal("3 new failures, 3 total", rig.Deliverer.Outcomes[1].CurrentValue); } [Fact] @@ -129,6 +129,6 @@ public async Task ADeliveredAlert_AdvancesTheBaselineAsBefore() /* ... so when the cooldown is over, two more failures read as two, not five. */ await rig.PassAsync(TimeSpan.FromHours(4), 5); Assert.Equal(2, rig.Deliverer.Outcomes.Count); - Assert.Equal("2 new failure(s), 5 total", rig.Deliverer.Outcomes[1].CurrentValue); + Assert.Equal("2 new failures, 5 total", rig.Deliverer.Outcomes[1].CurrentValue); } } diff --git a/Darling/Darling.Tests/RepeatDeliveryBudgetTests.cs b/Darling/Darling.Tests/RepeatDeliveryBudgetTests.cs index 788de59aa7..a26db81d05 100644 --- a/Darling/Darling.Tests/RepeatDeliveryBudgetTests.cs +++ b/Darling/Darling.Tests/RepeatDeliveryBudgetTests.cs @@ -178,7 +178,30 @@ public void AFirstNotice_PostsEvenWithTheWindowSpent_AndCarriesTheRoster() aggregateRepeats: true, incidents: Incidents("SRV-C")); Assert.True(firstNotice.ShouldSend); - Assert.Equal(new[] { "SRV-B (srvb01234567, 4 occurrence(s))" }, RosterEntries(firstNotice)); + Assert.Equal(new[] { "SRV-B (srvb01234567, 4 occurrences)" }, RosterEntries(firstNotice)); + } + + /// #6703: a folded incident that carried one occurrence reads "1 occurrence", not "1 occurrences". + [Fact] + public void ARosterLine_ForAnIncidentSeenOnce_ReadsInTheSingular() + { + var budget = new RepeatDeliveryBudget(); + + var carrier = budget.Evaluate( + Metric, "SRV-A", Repeat(T0, Fingerprint("SRV-A")), Window, aggregateRepeats: true); + budget.Commit(carrier); + + var folded = budget.Evaluate( + Metric, "SRV-B", Repeat(T0 + TimeSpan.FromMinutes(1), Fingerprint("SRV-B")), Window, + aggregateRepeats: true, + incidents: new[] { new AlertIncident(Fingerprint("SRV-B"), new[] { "SalesDb.dbo.Orders" }, 1) }); + Assert.False(folded.ShouldSend); + + var firstNotice = budget.Evaluate( + Metric, "SRV-C", FirstNotice(T0 + TimeSpan.FromMinutes(2), Fingerprint("SRV-C")), Window, + aggregateRepeats: true, incidents: Incidents("SRV-C")); + + Assert.Equal(new[] { "SRV-B (srvb01234567, 1 occurrence)" }, RosterEntries(firstNotice)); } /// @@ -210,7 +233,7 @@ public void TheRosterNamesEachFoldedServerWithItsOwnFingerprint() Assert.Equal(14, lines.Count); foreach (var server in Fleet.Skip(1)) { - Assert.Contains($"{server} ({Fingerprint(server).Substring(0, 12)}, 4 occurrence(s))", lines); + Assert.Contains($"{server} ({Fingerprint(server).Substring(0, 12)}, 4 occurrences)", lines); } /* The permutation: every line is present, every fingerprint is present, and no line pairs a server @@ -219,7 +242,7 @@ with its neighbour's fingerprint. */ { var neighbour = Fleet[n == Fleet.Length - 1 ? 1 : n + 1]; Assert.DoesNotContain( - $"{Fleet[n]} ({Fingerprint(neighbour).Substring(0, 12)}, 4 occurrence(s))", lines); + $"{Fleet[n]} ({Fingerprint(neighbour).Substring(0, 12)}, 4 occurrences)", lines); } } @@ -292,7 +315,7 @@ public void ACommitClearsWhatThePostNamed_AndNothingFoldedAfterIt() var carrier = budget.Evaluate( Metric, "SRV-A", Repeat(T0 + Window, Fingerprint("SRV-A")), Window, true); - Assert.Equal(new[] { "SRV-B (srvb01234567, 4 occurrence(s))" }, RosterEntries(carrier)); + Assert.Equal(new[] { "SRV-B (srvb01234567, 4 occurrences)" }, RosterEntries(carrier)); /* Folded between the decision and the commit — the window the four channel posts occupy. */ budget.Evaluate( @@ -302,7 +325,7 @@ public void ACommitClearsWhatThePostNamed_AndNothingFoldedAfterIt() var next = budget.Evaluate( Metric, "SRV-A", Repeat(T0 + Window + Window, Fingerprint("SRV-A")), Window, true); - Assert.Equal(new[] { "SRV-C (srvc01234567, 4 occurrence(s))" }, RosterEntries(next)); + Assert.Equal(new[] { "SRV-C (srvc01234567, 4 occurrences)" }, RosterEntries(next)); } /// @@ -414,7 +437,7 @@ public void RepeatedFoldsOfOneFingerprint_AreOneRosterLine() var carrier = budget.Evaluate( Metric, "SRV-A", Repeat(T0 + Window, Fingerprint("SRV-A")), Window, true); - Assert.Equal(new[] { "SRV-B (srvb01234567, 7 occurrence(s))" }, RosterEntries(carrier)); + Assert.Equal(new[] { "SRV-B (srvb01234567, 7 occurrences)" }, RosterEntries(carrier)); Assert.Equal(1, carrier.RosterEntryCount); } diff --git a/Darling/Darling.Tests/RunnableQueueAlertDetailTests.cs b/Darling/Darling.Tests/RunnableQueueAlertDetailTests.cs index 3ea91ad1fb..6ff3804b84 100644 --- a/Darling/Darling.Tests/RunnableQueueAlertDetailTests.cs +++ b/Darling/Darling.Tests/RunnableQueueAlertDetailTests.cs @@ -95,7 +95,7 @@ public async Task TheCard_CarriesTheCpuForTheSameFiveMinutes_AndTheTopRequestsBy Assert.Equal("SOS_SCHEDULER_YIELD", Field(requests[0], "Wait Type")); var more = Item(fired, "More requests"); - Assert.Contains("1 more request(s)", Field(more, "Not shown"), StringComparison.Ordinal); + Assert.Contains("1 more request", Field(more, "Not shown"), StringComparison.Ordinal); Assert.False(Assert.Single(h.Deliverer.Outcomes).Muted); } diff --git a/Darling/Darling.Tests/RunnableQueueRound1Tests.cs b/Darling/Darling.Tests/RunnableQueueRound1Tests.cs index 68975a2f57..bb64d0c894 100644 --- a/Darling/Darling.Tests/RunnableQueueRound1Tests.cs +++ b/Darling/Darling.Tests/RunnableQueueRound1Tests.cs @@ -276,7 +276,7 @@ public async Task TheCardAsksTheReadForCpuOrder_SoBlockedLongRunnersCannotFillTh Assert.Contains("session #201", requests[1].Heading, StringComparison.Ordinal); Assert.Contains("session #202", requests[2].Heading, StringComparison.Ordinal); /* The read hit its 50-row cap, so the 47 left are a floor. */ - Assert.Equal("at least 47 more request(s) in the newest query snapshot", MoreText(fired)); + Assert.Equal("at least 47 more requests in the newest query snapshot", MoreText(fired)); } [Fact] @@ -291,7 +291,7 @@ public async Task UnderTheCap_TheTrailerIsAnExactCount() await h.Build().EvaluateServerAsync(AlertEngineTests.Harness.Snapshot()); - Assert.Equal("3 more request(s) in the newest query snapshot", MoreText(Assert.Single(h.Deliverer.Outcomes))); + Assert.Equal("3 more requests in the newest query snapshot", MoreText(Assert.Single(h.Deliverer.Outcomes))); } [Fact] @@ -302,8 +302,13 @@ public void TheBuilder_SaysAtLeast_OnlyWhenTheReadHitItsCap() var exact = AlertContextBuilders.BuildRunnableQueueRequestItems(sessions); var floor = AlertContextBuilders.BuildRunnableQueueRequestItems(sessions, readHitCap: true); - Assert.Equal("2 more request(s) in the newest query snapshot", exact[^1].Fields.Single().Value); - Assert.Equal("at least 2 more request(s) in the newest query snapshot", floor[^1].Fields.Single().Value); + Assert.Equal("2 more requests in the newest query snapshot", exact[^1].Fields.Single().Value); + Assert.Equal("at least 2 more requests in the newest query snapshot", floor[^1].Fields.Single().Value); + + /* #6703: one request past the display cap reads in the singular. */ + var one = AlertContextBuilders.BuildRunnableQueueRequestItems( + sessions.Take(AlertContextBuilders.RunnableQueueRequestDisplayCap + 1).ToList()); + Assert.Equal("1 more request in the newest query snapshot", one[^1].Fields.Single().Value); } [Fact] diff --git a/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs b/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs index 368a2408a4..90ea963007 100644 --- a/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs +++ b/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs @@ -912,7 +912,7 @@ public async Task CheckpointerPressure_FiresInfoOnEitherArm_AndNotUnderBothLines Assert.Equal("checkpointer", fired.ServerKey); Assert.Equal(25_200, fired.NumericCurrentValue); Assert.Equal(10_000, fired.NumericThresholdValue); - Assert.Equal("average sync 25.2s per checkpoint over 1 checkpoint(s) in 60.0 min", fired.CurrentValue); + Assert.Equal("average sync 25.2s per checkpoint over 1 checkpoint in 60.0 min", fired.CurrentValue); Assert.Equal("average sync > 10s per checkpoint, or any requested checkpoint", fired.ThresholdValue); Assert.Contains("25.2 s and 14.0 s sync phases", fired.DetailText!, StringComparison.Ordinal); @@ -923,7 +923,7 @@ say which (#4758), so the alert calls it "requested", names all three causes and var forced = new Harness(); await forced.Build().ApplyCheckpointerPressureAsync(Interval(syncMs: 800, requested: 1, timed: 1), Ct); var forcedFire = Assert.Single(forced.Deliverer.Outcomes); - Assert.Contains("1 requested checkpoint(s)", forcedFire.CurrentValue, StringComparison.Ordinal); + Assert.Contains("1 requested checkpoint", forcedFire.CurrentValue, StringComparison.Ordinal); Assert.DoesNotContain("WAL-forced", forcedFire.CurrentValue, StringComparison.Ordinal); Assert.DoesNotContain("WAL-forced", forcedFire.ShortMessage!, StringComparison.Ordinal); Assert.Contains("WAL volume reaching max_wal_size, a base backup, or a CHECKPOINT statement", forcedFire.DetailText!, StringComparison.Ordinal); @@ -1004,7 +1004,7 @@ public async Task CheckpointerPressure_RefiresOnTheSharedCooldown_AndRecoversOnA await e.ApplyCheckpointerPressureAsync(Interval(syncMs: 1_200, requested: 0), Ct); var recovered = Assert.Single(h.History.Records); Assert.Equal(DarlingSelfAlertEvaluator.CheckpointerPressureRecoveredMetric, recovered.MetricName); - Assert.Contains("average sync per checkpoint and 0 requested checkpoint(s)", recovered.DetailText!, StringComparison.Ordinal); + Assert.Contains("average sync per checkpoint and 0 requested checkpoints", recovered.DetailText!, StringComparison.Ordinal); Assert.StartsWith(DarlingSelfAlertEvaluator.StoreServerLabel + ": ", recovered.DetailText!, StringComparison.Ordinal); /* Quiet stays quiet. */ @@ -1043,7 +1043,7 @@ public async Task CheckpointerPressure_TheSameCountersWithoutARestart_StillFireA await h.Build().ApplyCheckpointerPressureAsync(Interval(syncMs: 800, requested: 2, restarted: false, timed: 1), Ct); var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal(DarlingSelfAlertEvaluator.CheckpointerPressureMetric, fired.MetricName); - Assert.Contains("2 requested checkpoint(s)", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("2 requested checkpoints", fired.CurrentValue, StringComparison.Ordinal); Assert.DoesNotContain("restart", fired.ShortMessage!, StringComparison.OrdinalIgnoreCase); Assert.DoesNotContain("RESTARTED", fired.DetailText!, StringComparison.Ordinal); } @@ -1070,7 +1070,7 @@ public async Task CheckpointerPressure_TheSameSlowSyncWithoutARestart_StillFires await h.Build().ApplyCheckpointerPressureAsync(Interval(syncMs: 25_200, requested: 1, restarted: false, timed: 1), Ct); var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Contains("average sync", fired.CurrentValue, StringComparison.Ordinal); - Assert.Contains("1 requested checkpoint(s)", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("1 requested checkpoint", fired.CurrentValue, StringComparison.Ordinal); Assert.DoesNotContain("restart", fired.ShortMessage!, StringComparison.OrdinalIgnoreCase); } @@ -1149,7 +1149,7 @@ public async Task CheckpointerPressure_OneLongSyncAmongFourCheckpoints_FiresAndN Assert.Contains("12:41 UTC", text, StringComparison.Ordinal); } - Assert.Contains("over 4 checkpoint(s) in 60.0 min", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("over 4 checkpoints in 60.0 min", fired.CurrentValue, StringComparison.Ordinal); Assert.DoesNotContain("requested", fired.CurrentValue, StringComparison.Ordinal); Assert.Contains("single checkpoint sync > 10s", fired.ThresholdValue, StringComparison.Ordinal); } @@ -1237,7 +1237,7 @@ await h.Build().ApplyCheckpointerPressureAsync( Assert.Contains("average sync 15.0s per checkpoint", fired.CurrentValue, StringComparison.Ordinal); Assert.Contains("23.5s", fired.CurrentValue, StringComparison.Ordinal); Assert.Contains("12:41 UTC", fired.CurrentValue, StringComparison.Ordinal); - Assert.Contains("1 requested checkpoint(s)", fired.CurrentValue, StringComparison.Ordinal); + Assert.Contains("1 requested checkpoint", fired.CurrentValue, StringComparison.Ordinal); Assert.Equal(23_542, fired.NumericCurrentValue); } diff --git a/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs b/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs index ddb13c3661..db1f9bdab0 100644 --- a/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs +++ b/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs @@ -1822,7 +1822,7 @@ internal async Task ApplyCaptureDownAsync( var list = string.Join(" and ", missing); var delivery = await FireAsync( key, serverName, CaptureDownMetric, list, "session running", - detail: StateRepeatNote(decision, refire) + $"The {list} Extended Events session(s) are missing and could not be created. " + + detail: StateRepeatNote(decision, refire) + $"The {list} Extended Events {(missing.Count == 1 ? "session is" : "sessions are")} missing and could not be created. " + "Blocking/deadlock data is NOT being captured, so those alerts can never fire. Check the " + "collection log for the SESSION_MISSING detail (usually a permissions problem: " + "ALTER ANY EVENT SESSION on-prem, CREATE ANY DATABASE EVENT SESSION on Azure SQL DB).", @@ -2461,7 +2461,7 @@ leaving the structured reader with only the movers. */ if (remaining > 0) { /* A heading-only item, the shape AlertContextBuilders already uses for a stated remainder - (BuildBlockingContext's "+N more distinct blocking incident(s)"): a surface that renders only + (BuildBlockingContext's "+N more distinct blocking incidents"): a surface that renders only rows must not be able to read this document as complete. */ context.Details.Add(new AlertDetailItem { @@ -3185,10 +3185,10 @@ private sealed record HistoryAuditAlertText(int Hours, string ValueText, string var hours = CollectionHistoryAudit.FlaggedHours(findings); return new HistoryAuditAlertText( hours, - string.Create(CultureInfo.InvariantCulture, $"{hours} hours"), + string.Create(CultureInfo.InvariantCulture, $"{hours} {(hours == 1 ? "hour" : "hours")}"), CollectionHistoryAudit.Render(held.Day, findings, unread, incomplete), string.Create(CultureInfo.InvariantCulture, - $"{hours} thin hour(s) in retained history on {held.Day:yyyy-MM-dd}")); + $"{hours} thin {(hours == 1 ? "hour" : "hours")} in retained history on {held.Day:yyyy-MM-dd}")); } /* ------------------------- #3712: the analysis singles digest ------------------------- */ @@ -5216,7 +5216,7 @@ await RecordResolutionAsync(new AlertResolution( private static (string ShortMessage, string Detail) RenderCustomRuleHealth(CustomAlertHealthReport report) { var shortMessage = string.Create(CultureInfo.InvariantCulture, - $"{report.TotalIssues} custom alert rule(s) need attention: {report.BrokenRules.Count} no longer compile, {report.NeverFiringRules.Count} armed but never fire"); + $"{report.TotalIssues} custom alert {(report.TotalIssues == 1 ? "rule needs" : "rules need")} attention: {report.BrokenRules.Count} no longer compile, {report.NeverFiringRules.Count} armed but never fire"); var sb = new StringBuilder(); sb.Append(shortMessage).Append('.'); @@ -5583,7 +5583,7 @@ private static (string ShortMessage, string Detail) RenderStaleMuteRules( { var oldestDays = (nowUtc - stale[0].CreatedAtUtc).TotalDays; var shortMessage = string.Create(CultureInfo.InvariantCulture, - $"{stale.Count} mute rule(s) have been suppressing alerts with no expiry for over {StaleMuteAge.TotalDays:F0} days (oldest {oldestDays:F0} days)"); + $"{stale.Count} {(stale.Count == 1 ? "mute rule has" : "mute rules have")} been suppressing alerts with no expiry for over {StaleMuteAge.TotalDays:F0} days (oldest {oldestDays:F0} days)"); var sb = new StringBuilder(); sb.Append(shortMessage).Append('.'); @@ -5795,7 +5795,7 @@ successful read — including one that comes back empty — always states exactl { var rejectedList = string.Join(", ", report.RejectedSettingNames); reasons.Add(string.Create(CultureInfo.InvariantCulture, - $"PostgreSQL rejected the managed value for {report.RejectedSettingNames.Count} owned setting(s): {rejectedList}")); + $"PostgreSQL rejected the managed value for {report.RejectedSettingNames.Count} owned {(report.RejectedSettingNames.Count == 1 ? "setting" : "settings")}: {rejectedList}")); } if (anyUnknown && reasons.Count == 0) @@ -5831,7 +5831,7 @@ these four facts moves faster than a restart. */ _lastStoreSettingsAlert[StoreSettingsKey] = now; var detail = string.Join(". ", reasons) + ". Run --check-settings for the full picture."; - var shortMessage = FormattableString.Invariant($"{reasons.Count} managed-store setting condition(s) need attention"); + var shortMessage = FormattableString.Invariant($"{reasons.Count} managed-store setting {(reasons.Count == 1 ? "condition needs" : "conditions need")} attention"); var delivery = await FireAsync( StoreKey(StoreSettingsKey), _storeLabel, StoreSettingsMetric, @@ -7038,7 +7038,7 @@ internal async Task ApplyRetentionHoldsAsync( StoreKey(RetentionHoldKeyPrefix + key), _storeLabel, RetentionHoldMetric, $"{ratio:F1}x its {policy.DropAfter} horizon", $"{warnRatio:F1}x", detail: StateRepeatNote(decision, refire) + $"Store {label} is HELD PAUSED by the rollup-coverage gate, and the tier now " + - $"holds {spanDays:F1} days across {policy.ChunkCount} chunk(s) against a configured " + + $"holds {spanDays:F1} days across {policy.ChunkCount} {(policy.ChunkCount == 1 ? "chunk" : "chunks")} against a configured " + $"{policy.DropAfter} horizon ({ratio:F1}x). " + (critical ? "The tier is now several times its intended depth and still growing, so this " + @@ -7285,15 +7285,15 @@ internal async Task ApplyComposeHoursStuckAsync( var reason = string.IsNullOrEmpty(oldest.LastSqlState) ? oldest.LastReason : $"{oldest.LastSqlState}: {oldest.LastReason}"; var delivery = await FireAsync( StoreKey(ComposeHoursStuckKeyPrefix + key), _storeLabel, ComposeHoursStuckMetric, - $"{stuck.Count} hour(s)", "0 hours", + $"{stuck.Count} {(stuck.Count == 1 ? "hour" : "hours")}", "0 hours", detail: StateRepeatNote(decision, refire) + - $"{stuck.Count} hour(s) of the Query Store compose rollup failed to build {QueryStoreComposeStamp.FailuresBeforeBackoff} times in a row " + - "(or timed out under the longer timeout) and are now retried once a day. " + - $"The oldest is {oldest.Hour:yyyy-MM-dd HH}:00 UTC: {oldest.Failures} failure(s), last reason {reason}, next attempt {oldest.NextAttemptAt:yyyy-MM-dd HH:mm} UTC. " + + $"{stuck.Count} {(stuck.Count == 1 ? "hour" : "hours")} of the Query Store compose rollup failed to build {QueryStoreComposeStamp.FailuresBeforeBackoff} times in a row " + + $"(or timed out under the longer timeout) and {(stuck.Count == 1 ? "is" : "are")} now retried once a day. " + + $"The oldest is {oldest.Hour:yyyy-MM-dd HH}:00 UTC: {oldest.Failures} {(oldest.Failures == 1 ? "failure" : "failures")}, last reason {reason}, next attempt {oldest.NextAttemptAt:yyyy-MM-dd HH:mm} UTC. " + "get_store_metrics lists every such hour under query_store_compose; the service log's 'Query Store compose rollup: building hour' " + "lines carry each failure.", severity: AlertSeverityLevel.Warning, - shortMessage: $"{stuck.Count} Query Store compose hour(s) retried once a day - {reason}", + shortMessage: $"{stuck.Count} Query Store compose {(stuck.Count == 1 ? "hour" : "hours")} retried once a day - {reason}", numericCurrentValue: stuck.Count, numericThresholdValue: 0, cancellationToken); @@ -7707,7 +7707,7 @@ internal async Task ApplyCheckpointerPressureAsync( if (requested > 0 || armParts.Count == 0) { - armParts.Add($"{requested} requested checkpoint(s)"); + armParts.Add($"{requested} requested {(requested == 1 ? "checkpoint" : "checkpoints")}"); } var arms = armParts.Count == 1 @@ -7735,9 +7735,9 @@ longest single sync when that did (the larger when both did). */ var delivery = await FireAsync( StoreKey(CheckpointerKey), _storeLabel, CheckpointerPressureMetric, - $"{arms} over {checkpointCount} checkpoint(s) in {intervalMinutes} min", + $"{arms} over {checkpointCount} {(checkpointCount == 1 ? "checkpoint" : "checkpoints")} in {intervalMinutes} min", thresholdText, - detail: $"The store's own checkpointer ran {checkpointCount} checkpoint(s) over the {intervalMinutes} minutes " + + detail: $"The store's own checkpointer ran {checkpointCount} {(checkpointCount == 1 ? "checkpoint" : "checkpoints")} over the {intervalMinutes} minutes " + $"between the last two self-metrics sweeps, spending {(syncMs / 1000.0).ToString("0.0", CultureInfo.InvariantCulture)}s " + $"total in its sync (fsync) phase and {writeSeconds}s in its write phase — an average of {averageSecondsText}s of sync " + $"per checkpoint — and {requested} of those checkpoints were REQUESTED — started by something other than " + @@ -7762,7 +7762,7 @@ longest single sync when that did (the larger when both did). */ "new interval breaches and recovers when one reads clean.", /* No override: the per-metric map's declared INFO arm decides (the digest reasoning). */ severity: null, - shortMessage: $"store checkpointer: {arms} over {checkpointCount} checkpoint(s) in the last {intervalMinutes} min", + shortMessage: $"store checkpointer: {arms} over {checkpointCount} {(checkpointCount == 1 ? "checkpoint" : "checkpoints")} in the last {intervalMinutes} min", numericCurrentValue: currentValue, numericThresholdValue: CheckpointSyncBarMs, cancellationToken); @@ -7778,8 +7778,8 @@ await RecordResolutionAsync(new AlertResolution( StoreKey(CheckpointerKey), _storeLabel, CheckpointerPressureMetric, CheckpointerPressureRecoveredMetric, /* Label rather than the constant for the #3500 reason the cadence recovery gives. */ - $"{_storeLabel}: checkpointer {recoveredAverageText} and {requested} requested checkpoint(s) over {checkpointCount} " + - $"checkpoint(s) in the last {intervalMinutes} min" + + $"{_storeLabel}: checkpointer {recoveredAverageText} and {requested} requested {(requested == 1 ? "checkpoint" : "checkpoints")} over {checkpointCount} " + + $"{(checkpointCount == 1 ? "checkpoint" : "checkpoints")} in the last {intervalMinutes} min" + (longestSync is CheckpointSyncMax recoveredLongest ? $", longest single sync {FormatSyncSeconds(recoveredLongest.SyncMs)}s" : "") + " — under the line again"), cancellationToken); } @@ -8208,8 +8208,8 @@ delivered alert (no pending retry) advances it exactly as before. */ var delivery = await FireAsync( StoreKey(PolicyJobFailingKeyPrefix + key), _storeLabel, PolicyJobFailingMetric, - $"{grew} new failure(s), {job.TotalFailures} total", "at least one new failure", - detail: $"TimescaleDB {label} recorded {grew} more failed run(s) since the previous hourly sample " + + $"{grew} new {(grew == 1 ? "failure" : "failures")}, {job.TotalFailures} total", "at least one new failure", + detail: $"TimescaleDB {label} recorded {grew} more failed {(grew == 1 ? "run" : "runs")} since the previous hourly sample " + $"({job.TotalFailures} failures total since the policy was created) and its last run reports Failed. " + $"{band.Consequence} The job is still SCHEDULED — the scheduler is running it and it is failing — " + "which is why neither the dead-job arm (next_start = -infinity) nor the #2136 cadence check (which " + @@ -8221,7 +8221,7 @@ delivered alert (no pending retry) advances it exactly as before. */ #3443/#3783 idiom. The value IS a measurement — how many more failures — so unlike the stuck family this metric is deliberately not state-only. */ severity: null, - shortMessage: $"{label} failed {grew} more time(s) since the last sample", + shortMessage: $"{label} failed {grew} more {(grew == 1 ? "time" : "times")} since the last sample", numericCurrentValue: grew, numericThresholdValue: 1, cancellationToken); diff --git a/Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs b/Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs index 4c7bd53be7..81d3e6c60c 100644 --- a/Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs +++ b/Darling/PerformanceMonitor.Darling.Service/DarlingWorker.cs @@ -8863,7 +8863,7 @@ this host serves one. */ NumericThresholdValue: threshold, Muted: muted, Severity: AlertEngine.GradeDeadlockFire(count, rateTiers), - ShortMessage: $"{count} deadlock(s) in the last hour"), + ShortMessage: $"{count} {(count == 1 ? "deadlock" : "deadlocks")} in the last hour"), cancellationToken); readClock.Restart(); @@ -9042,7 +9042,7 @@ qualifies as a Critical tier tonight. */ NumericThresholdValue: threshold, Muted: muted, Severity: PgBlockingFireSeverity, - ShortMessage: $"{count} blocking session(s)"), + ShortMessage: $"{count} blocking {(count == 1 ? "session" : "sessions")}"), cancellationToken); readClock.Restart(); @@ -9255,7 +9255,7 @@ render as three FALSE arms and the read's rows are exactly the pre-#3743 rows. * key, snapshot.ServerName, metricName, - $"{rows.Count} query(s), longest {elapsedMinutes}m", + $"{rows.Count} {(rows.Count == 1 ? "query" : "queries")}, longest {elapsedMinutes}m", $"{thresholdMinutes}m", Context: AlertSampleAge.Stamp( new AlertContext @@ -9674,7 +9674,7 @@ statements are commonly multi-line formatted DML with no SQL-Server-style length without this, a multi-line statement breaks the one-line-per-incident rendering and an unbounded one can bloat the stored context past what Slack/Teams will accept. */ string.IsNullOrWhiteSpace(row.VictimStatement) - ? $"victim pid {row.VictimPid}, {row.ParticipantCount} participant(s)" + ? $"victim pid {row.VictimPid}, {row.ParticipantCount} {(row.ParticipantCount == 1 ? "participant" : "participants")}" : AlertContextBuilders.TruncateText(row.VictimStatement!), }); @@ -9767,7 +9767,7 @@ the same way a real backend id already is on its own. */ : row.RootBackendId.ToString(CultureInfo.InvariantCulture), new[] { - $"root pid {row.RootPid} blocking {row.TotalVictims} session(s)" + $"root pid {row.RootPid} blocking {row.TotalVictims} {(row.TotalVictims == 1 ? "session" : "sessions")}" + (row.Databases.Length > 0 ? $" in [{string.Join(", ", row.Databases)}]" : string.Empty) /* AlertContextBuilders.TruncateText — same reasoning as BuildPgDeadlockIncident's VictimStatement: root queries are commonly multi-line and otherwise unbounded. */ diff --git a/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpAlertTools.cs b/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpAlertTools.cs index add663cc85..f8d2673a40 100644 --- a/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpAlertTools.cs +++ b/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpAlertTools.cs @@ -146,7 +146,7 @@ the caller off widening a window whose contents they were never shown. */ return dismissedExcludedCount > 0 ? McpHelpers.Status( "empty", - $"No undismissed alerts found in the specified time range{filterSentence}, but {dismissedExcludedCount} dismissed alert(s) were excluded by the default filter. Re-run with include_dismissed = true to see them — a dismissed alert still fired.") + $"No undismissed alerts found in the specified time range{filterSentence}, but {dismissedExcludedCount} dismissed {(dismissedExcludedCount == 1 ? "alert was" : "alerts were")} excluded by the default filter. Re-run with include_dismissed = true to see them — a dismissed alert still fired.") : McpHelpers.Status("empty", $"No alerts found in the specified time range{filterSentence}."); } @@ -1127,7 +1127,7 @@ and the second one is a mute somebody INTENDED that is no longer in force. "empty", configured == 0 ? "No mute rules are configured for this store, so no alert is being suppressed anywhere — a quiet alert history is genuine rather than muted." - : $"No mute rules are in force right now: {configured} rule(s) exist but every one of them is disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", + : $"No mute rules are in force right now: {configured} {(configured == 1 ? "rule exists but it is" : "rules exist but every one of them is")} disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", new { enabled_only, configured_count = configured, excluded_by_filter = configured - list.Count }); } diff --git a/Lite.Tests/AlertContextBuildersTests.cs b/Lite.Tests/AlertContextBuildersTests.cs index e2317ac977..da8f6d8792 100644 --- a/Lite.Tests/AlertContextBuildersTests.cs +++ b/Lite.Tests/AlertContextBuildersTests.cs @@ -424,7 +424,11 @@ concurrent maintenance sessions render three lines (the input's own order — th Assert.Equal(AlertContextBuilders.ActiveMaintenanceMaxLines + 2, detail.Split('\n').Length); Assert.Equal(AlertContextBuilders.ActiveMaintenanceMaxLines, System.Text.RegularExpressions.Regex.Matches(detail, "Active maintenance: BACKUP DATABASE").Count); - Assert.EndsWith("Active maintenance: 2 more maintenance session(s) not shown", detail, StringComparison.Ordinal); + Assert.EndsWith("Active maintenance: 2 more maintenance sessions not shown", detail, StringComparison.Ordinal); + /* #6703: one session past the cap reads in the singular. */ + var oneOver = AlertContextBuilders.BuildActiveMaintenanceDetail( + sessions.GetRange(0, AlertContextBuilders.ActiveMaintenanceMaxLines + 1)); + Assert.EndsWith("Active maintenance: 1 more maintenance session not shown", oneOver, StringComparison.Ordinal); /* The leader (longest elapsed) is named first — the likeliest pin leads the reader's eye. */ Assert.Contains("10m 0s elapsed", detail.Split('\n')[1], StringComparison.Ordinal); } diff --git a/Lite.Tests/AlertValueParserTests.cs b/Lite.Tests/AlertValueParserTests.cs index 2762c92b17..c8bddfd8d0 100644 --- a/Lite.Tests/AlertValueParserTests.cs +++ b/Lite.Tests/AlertValueParserTests.cs @@ -25,7 +25,7 @@ public sealed class AlertValueParserTests [Theory] [InlineData("87% (Total CPU)", 87)] /* High CPU — the #1830 field case, stored 0 before */ [InlineData("92% (SQL CPU)", 92)] /* High CPU, SQL-only mode */ - [InlineData("+3 more incident(s) this cycle", 3)] /* per-event overflow trailer */ + [InlineData("+3 more incidents this cycle", 3)] /* per-event overflow trailer */ [InlineData("92.5%", 92.5)] /* plain percent — the old fallback's happy path */ [InlineData("80%", 80)] [InlineData("1074", 1074)] /* bare count (blocking/deadlocks) */ diff --git a/Lite.Tests/BlockingDeadlockContextBuilderTests.cs b/Lite.Tests/BlockingDeadlockContextBuilderTests.cs index aa71e71206..6f9554e0f7 100644 --- a/Lite.Tests/BlockingDeadlockContextBuilderTests.cs +++ b/Lite.Tests/BlockingDeadlockContextBuilderTests.cs @@ -125,7 +125,11 @@ public void BuildBlockingContext_CapsAtTenGroups_WithTrueTotalTrailer() Assert.NotNull(context); /* 10 chain items + 1 trailer + 10 appended incident items. */ Assert.Equal(21, context!.Details.Count); - Assert.Equal("+2 more distinct blocking incident(s)", context.Details[10].Heading); + Assert.Equal("+2 more distinct blocking incidents", context.Details[10].Heading); + + /* #6703: one chain past the cap reads in the singular. */ + var oneOver = AlertContextBuilders.BuildBlockingContext(Server, rows.Take(11).ToList(), NoExclusions); + Assert.Contains(oneOver!.Details, d => d.Heading == "+1 more distinct blocking incident"); Assert.Empty(context.Details[10].Fields); Assert.Equal(10, context.Incidents!.Count); } diff --git a/Lite.Tests/LiteAlertForwardingTests.cs b/Lite.Tests/LiteAlertForwardingTests.cs index a28a5d9af4..1b2d41d224 100644 --- a/Lite.Tests/LiteAlertForwardingTests.cs +++ b/Lite.Tests/LiteAlertForwardingTests.cs @@ -642,7 +642,7 @@ public async Task Blocking_FiresOnce_PersistsWatermark_AndEdgeTriggerHoldsWithin Assert.Equal("Blocking Detected", fired.MetricName); Assert.Equal("2", fired.CurrentValue); /* :180 */ Assert.Equal("1", fired.ThresholdValue); /* :181 */ - Assert.Equal("2 blocking session(s)", fired.ShortMessage); /* :167 toast body */ + Assert.Equal("2 blocking sessions", fired.ShortMessage); /* :167 toast body */ Assert.NotNull(fired.Context); /* :174 context built from the same rows */ /* :149-151 — the #1145 watermark persisted on change, keyed by the shared metric row key. */ Assert.Equal(2, h.StateStore.EdgeWatermarks[(Key, "Blocking Detected")]); @@ -801,8 +801,8 @@ public async Task FailedJob_Fires_PersistsWatermark_DedupsSameFailure_AndSurvive var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Failed Agent Job", fired.MetricName); - Assert.Equal("1 job failure(s) in last 60m — NightlyETL", fired.CurrentValue); /* :703 */ - Assert.Equal("1 job failure(s) — NightlyETL", fired.ShortMessage); /* :690 toast body */ + Assert.Equal("1 job failure in last 60m — NightlyETL", fired.CurrentValue); /* :703 */ + Assert.Equal("1 job failure — NightlyETL", fired.ShortMessage); /* :690 toast body */ /* :684 — the server-local watermark persisted the moment the alert fired. */ Assert.Equal(runTime, h.FailedJobWatermark()); @@ -917,7 +917,7 @@ public async Task Deadlock_ToastBody_AndValues_MatchTheOldLoop() var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Equal("Deadlocks Detected", fired.MetricName); Assert.Equal("1", fired.CurrentValue); /* :257 */ - Assert.Equal("1 deadlock(s) in the last hour", fired.ShortMessage); /* :244 toast body */ + Assert.Equal("1 deadlock in the last hour", fired.ShortMessage); /* :244 toast body */ } /// @@ -968,7 +968,7 @@ public async Task LongRunningQuery_ToastBody_CarriesSessionAndEightyCharPreview( await h.Build().EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); - Assert.Equal("1 query(s), longest 45m", fired.CurrentValue); /* :387 */ + Assert.Equal("1 query, longest 45m", fired.CurrentValue); /* :387 */ Assert.Equal("30m", fired.ThresholdValue); /* :388 */ var expectedPreview = PerformanceMonitor.Alerting.AlertContextBuilders.TruncateText(longText, 80); Assert.EndsWith("...", expectedPreview); @@ -1054,7 +1054,7 @@ public async Task LongRunningJob_ToastBody_CarriesJobNamePercentAndMinutes() await h.Build().EvaluateServerAsync(Harness.Snapshot()); var fired = Assert.Single(h.Deliverer.Outcomes); - Assert.Equal("1 job(s) exceeding 3x average", fired.CurrentValue); /* :608 */ + Assert.Equal("1 job exceeding 3x average", fired.CurrentValue); /* :608 */ Assert.Equal("3x historical avg", fired.ThresholdValue); /* :609 */ Assert.Equal("NightlyETL at 450% of avg (90m)", fired.ShortMessage); /* :595 toast body */ } @@ -1102,14 +1102,14 @@ public async Task Deliverer_Toast_TitleIsMetric_MessagePrefixedWithServer_IconTa Warning for CPU (:85), blocking (:168), LRQ (:375), tempdb (:436), volume (:511), long-running job (:596), failed job (:691). Title == metric name in every branch. */ await deliverer.DeliverAsync(Outcome("High CPU", shortMessage: "Total CPU at 92% (threshold: 80%)")); - await deliverer.DeliverAsync(Outcome("Deadlocks Detected", shortMessage: "1 deadlock(s) in the last hour")); + await deliverer.DeliverAsync(Outcome("Deadlocks Detected", shortMessage: "1 deadlock in the last hour")); await deliverer.DeliverAsync(Outcome("Poison Wait", shortMessage: "[THREADPOOL] 900s of wait accumulated in the last 10 minutes across 30,000 waits — on average 1.5 task(s) continuously stuck")); await deliverer.DeliverAsync(Outcome("Volume Free Space", shortMessage: "D:\\ 8% free (64.0 GB)")); Assert.Equal(4, toasts.Count); Assert.Equal(new ToastCall("High CPU", "SRV-A: Total CPU at 92% (threshold: 80%)", BalloonIcon.Warning, Name, "High CPU"), toasts[0]); Assert.Equal(BalloonIcon.Error, toasts[1].Icon); - Assert.Equal("SRV-A: 1 deadlock(s) in the last hour", toasts[1].Message); /* :244 full toast */ + Assert.Equal("SRV-A: 1 deadlock in the last hour", toasts[1].Message); /* :244 full toast */ Assert.Equal(BalloonIcon.Error, toasts[2].Icon); Assert.Equal(BalloonIcon.Warning, toasts[3].Icon); } @@ -1141,7 +1141,7 @@ when its context has incidents and the mode is PerEvent. */ }; var (deliverer, _, sends) = BuildDeliverer(); - await deliverer.DeliverAsync(Outcome("Long-Running Query", current: "1 query(s), longest 45m", threshold: "30m", context: context, numCur: 45, numThr: 30)); + await deliverer.DeliverAsync(Outcome("Long-Running Query", current: "1 query, longest 45m", threshold: "30m", context: context, numCur: 45, numThr: 30)); var send = Assert.Single(sends); Assert.Equal(45, send.NumericCurrentValue); @@ -1171,6 +1171,29 @@ forward them — the old path dropped them to null on this route. */ Assert.Equal(101, send.ServerId); } + [Fact] + public async Task Deliverer_Blocking_PerEventMode_TwoOverflowIncidents_ReadInThePlural() + { + /* #6703: the trailer for one held-back incident reads "+1 more incident" (above); two read "+2 more incidents". */ + App.AlertDeliveryMode = AlertNotificationMode.PerEvent; + App.AlertPerEventMaxPerCycle = 1; + var context = new AlertContext + { + Incidents = new List + { + new("a", new[] { "dbo.Users" }, OccurrenceCount: 3), + new("b", new[] { "dbo.Posts" }, OccurrenceCount: 1), + new("c", new[] { "dbo.Badges" }, OccurrenceCount: 2) + } + }; + var (deliverer, _, sends) = BuildDeliverer(); + + await deliverer.DeliverAsync(Outcome("Blocking Detected", current: "6", threshold: "1", context: context, numCur: 6, numThr: 1)); + + Assert.Equal(2, sends.Count); /* 1 per-incident + 1 overflow */ + Assert.Equal("+2 more incidents this cycle", sends[1].CurrentValue); + } + [Fact] public async Task Deliverer_Blocking_PerEventMode_SplitsPerIncident_WithCapOverflow() { @@ -1197,7 +1220,7 @@ AlertPerEventMaxPerCycle with a "+N more" trailer that keeps the remaining Assert.Equal(3, sends.Count); /* 2 per-incident + 1 overflow */ Assert.Equal("3", sends[0].CurrentValue); /* DescribeIncident = occurrence count */ Assert.Equal("1", sends[1].CurrentValue); - Assert.Equal("+1 more incident(s) this cycle", sends[2].CurrentValue); + Assert.Equal("+1 more incident this cycle", sends[2].CurrentValue); /* #1830: per-event sends carry per-incident numerics — occurrence counts, then the overflow COUNT for the "+N more" trailer whose text is unparseable (it stored 0 before). The threshold stays the outcome's on every send. */ diff --git a/Lite.Tests/McpPageContractTests.cs b/Lite.Tests/McpPageContractTests.cs index f4febf8f02..a764c3fe79 100644 --- a/Lite.Tests/McpPageContractTests.cs +++ b/Lite.Tests/McpPageContractTests.cs @@ -418,7 +418,7 @@ public async Task GetAlertHistory_AllDismissed_EmptyAnswerNamesTheFilter() var root = Parse(await McpAlertTools.GetAlertHistory(_dataService, 24, 50)); Assert.Equal("empty", root.GetProperty("status").GetString()); var message = root.GetProperty("message").GetString()!; - Assert.Contains("2 dismissed alert(s) were excluded", message, StringComparison.Ordinal); + Assert.Contains("2 dismissed alerts were excluded", message, StringComparison.Ordinal); Assert.Contains("include_dismissed", message, StringComparison.Ordinal); /* And with nothing dismissed either, the plain sentence — the count is a measurement, not a hedge. */ @@ -428,6 +428,18 @@ public async Task GetAlertHistory_AllDismissed_EmptyAnswerNamesTheFilter() Assert.DoesNotContain("dismissed", quiet.GetProperty("message").GetString()!, StringComparison.Ordinal); } + /// #6703: one dismissed alert reads "1 dismissed alert was excluded", not "1 dismissed alert(s) were". + [Fact] + public async Task GetAlertHistory_OneDismissed_EmptyAnswerReadsInTheSingular() + { + await SeedAlertAsync(WholeSecondsNow(), dismissed: true); + + var root = Parse(await McpAlertTools.GetAlertHistory(_dataService, 24, 50)); + + Assert.Equal("empty", root.GetProperty("status").GetString()); + Assert.Contains("1 dismissed alert was excluded", root.GetProperty("message").GetString()!, StringComparison.Ordinal); + } + /// /// #4766: the desktop grid's Time column converts an alert in the selected display mode, on its server's clock /// (AlertHistoryRow.TimeLocal, AlertHistoryRow.Clock). The tool serializes a projection of the row diff --git a/Lite/Mcp/McpAlertTools.cs b/Lite/Mcp/McpAlertTools.cs index 0bbff11907..b254b0a890 100644 --- a/Lite/Mcp/McpAlertTools.cs +++ b/Lite/Mcp/McpAlertTools.cs @@ -96,7 +96,7 @@ the caller off widening a window whose contents they were never shown. */ return dismissedExcludedCount > 0 ? McpHelpers.Status( "empty", - $"No undismissed alerts found in the specified time range{filterSentence}, but {dismissedExcludedCount} dismissed alert(s) were excluded by the default filter. Re-run with include_dismissed = true to see them — a dismissed alert still fired.") + $"No undismissed alerts found in the specified time range{filterSentence}, but {dismissedExcludedCount} dismissed {(dismissedExcludedCount == 1 ? "alert was" : "alerts were")} excluded by the default filter. Re-run with include_dismissed = true to see them — a dismissed alert still fired.") : McpHelpers.Status("empty", $"No alerts found in the specified time range{filterSentence}."); } @@ -795,7 +795,7 @@ is no longer in force. "empty", configured == 0 ? "No mute rules are configured for this store, so no alert is being suppressed anywhere — a quiet alert history is genuine rather than muted." - : $"No mute rules are in force right now: {configured} rule(s) exist but every one of them is disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", + : $"No mute rules are in force right now: {configured} {(configured == 1 ? "rule exists but it is" : "rules exist but every one of them is")} disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", new { enabled_only, configured_count = configured, excluded_by_filter = configured - rules.Count })); } diff --git a/PerformanceMonitor.Alerting/AlertContextBuilders.cs b/PerformanceMonitor.Alerting/AlertContextBuilders.cs index 4d531102d6..e86d7c5edf 100644 --- a/PerformanceMonitor.Alerting/AlertContextBuilders.cs +++ b/PerformanceMonitor.Alerting/AlertContextBuilders.cs @@ -92,7 +92,7 @@ public static class AlertContextBuilders { context.Details.Add(new AlertDetailItem { - Heading = $"+{groups.Count - maxGroups} more distinct blocking incident(s)", + Heading = $"+{groups.Count - maxGroups} more distinct blocking {(groups.Count - maxGroups == 1 ? "incident" : "incidents")}", Fields = new() }); } @@ -872,7 +872,7 @@ private static void AddTopList(List items, string heading, stri /// states the omission as a final item rather than cutting silently. Fields are the Long-Running Query /// card's session fields, so a reader sees the same facts under both alerts. Returns an empty list when the /// snapshot holds no request. says the read returned a full page, so the count of - /// omitted requests is a floor and the trailer reads "at least N more request(s)". + /// omitted requests is a floor and the trailer reads "at least N more requests" ("1 more request" for one). /// public static IReadOnlyList BuildRunnableQueueRequestItems(IReadOnlyList sessions, bool readHitCap = false) { @@ -917,7 +917,7 @@ public static IReadOnlyList BuildRunnableQueueRequestItems(IRea Fields = new() { ("Not shown", string.Create(CultureInfo.InvariantCulture, - $"{(readHitCap ? "at least " : "")}{ranked.Count - RunnableQueueRequestDisplayCap} more request(s) in the newest query snapshot")) + $"{(readHitCap ? "at least " : "")}{ranked.Count - RunnableQueueRequestDisplayCap} more {(ranked.Count - RunnableQueueRequestDisplayCap == 1 ? "request" : "requests")} in the newest query snapshot")) } }); } @@ -1212,7 +1212,7 @@ public static string BuildActiveMaintenanceDetail(IReadOnlyList 0) - sb.Append("\n Active maintenance: ").Append(omitted).Append(" more maintenance session(s) not shown"); + sb.Append("\n Active maintenance: ").Append(omitted).Append(omitted == 1 ? " more maintenance session not shown" : " more maintenance sessions not shown"); return sb.ToString(); } @@ -1393,7 +1393,7 @@ public static AlertDetailItem BuildBlockingWaitGateItem(CurrentBlockingWaitResul return new AlertDetailItem { - Heading = $"Blocking Wait Time — {current.TotalWaitSeconds:F0}s across {current.BlockedSessionCount} blocked session(s)", + Heading = $"Blocking Wait Time — {current.TotalWaitSeconds:F0}s across {current.BlockedSessionCount} blocked {(current.BlockedSessionCount == 1 ? "session" : "sessions")}", Fields = new() { (BlockingWaitFiredByLabel, firedBy), diff --git a/PerformanceMonitor.Alerting/AlertEngine.cs b/PerformanceMonitor.Alerting/AlertEngine.cs index 6b5315fd15..c0aaedb146 100644 --- a/PerformanceMonitor.Alerting/AlertEngine.cs +++ b/PerformanceMonitor.Alerting/AlertEngine.cs @@ -1500,7 +1500,7 @@ but the stored value must not depend on parse luck. */ blockingContext, detailText, NumericCurrentValue: effectiveBlockingCount, NumericThresholdValue: blockingThreshold, Muted: isMuted, Severity: blockingContext?.SeverityOverride, - ShortMessage: $"{effectiveBlockingCount} blocking session(s)"), ct); + ShortMessage: $"{effectiveBlockingCount} blocking {(effectiveBlockingCount == 1 ? "session" : "sessions")}"), ct); AfterFire("Blocking Detected", _lastBlockingAlert, key, now, alertCooldown, delivery); /* #4752: the gate advanced the watermark to this count, and it was saved, BEFORE delivery. A fire @@ -1843,18 +1843,18 @@ item is PREPENDED so the first thing a reader of the card or of get_alert_histor AlertSampleAge.Stamp(blockingContext, "blocking wait", current.SnapshotTime, now); var detailText = AlertContextBuilders.ContextToDetailText(blockingContext); - /* REAL numerics (#1830): the display text is prose ("745s across 3 blocked session(s)"), + /* REAL numerics (#1830): the display text is prose ("745s across 3 blocked sessions"), which no history-store parser could turn back into a number — the value has to travel as a number or every history row lands at 0, which is the defect #1830 just fixed. */ double totalWaitSeconds = current.TotalWaitSeconds; var delivery = await FireAsync(new AlertOutcome( key, serverName, "Blocking Wait Time", - $"{totalWaitSeconds:F0}s across {current.BlockedSessionCount} blocked session(s)", + $"{totalWaitSeconds:F0}s across {current.BlockedSessionCount} blocked {(current.BlockedSessionCount == 1 ? "session" : "sessions")}", $"{thresholdSeconds}s", blockingContext, detailText, NumericCurrentValue: totalWaitSeconds, NumericThresholdValue: thresholdSeconds, Muted: isMuted, Severity: blockingContext.SeverityOverride, - ShortMessage: $"{totalWaitSeconds:F0}s total blocked wait across {current.BlockedSessionCount} session(s) (threshold: {thresholdSeconds}s)"), ct); + ShortMessage: $"{totalWaitSeconds:F0}s total blocked wait across {current.BlockedSessionCount} {(current.BlockedSessionCount == 1 ? "session" : "sessions")} (threshold: {thresholdSeconds}s)"), ct); AfterFire("Blocking Wait Time", _lastBlockingWaitAlert, key, now, alertCooldown, delivery); } } @@ -2014,7 +2014,7 @@ with a count threshold of 1 keeps every fire and a run of 25 in an hour finally deadlockContext, detailText, NumericCurrentValue: effectiveDeadlockCount, NumericThresholdValue: deadlockThreshold, Muted: isMuted, Severity: deadlockContext.SeverityOverride, - ShortMessage: $"{effectiveDeadlockCount} deadlock(s) in the last hour"), ct); + ShortMessage: $"{effectiveDeadlockCount} {(effectiveDeadlockCount == 1 ? "deadlock" : "deadlocks")} in the last hour"), ct); AfterFire("Deadlocks Detected", _lastDeadlockAlert, key, now, alertCooldown, delivery); /* #4752: the blocking twin above explains it — the watermark moved to this count, and was saved, @@ -2847,7 +2847,7 @@ setting whose only effect is an absence needs a line that says the absence was n /* :382-392. ShortMessage = the toast body of :374. */ var delivery = await FireAsync(new AlertOutcome( key, serverName, "Long-Running Query", - $"{longRunning.Count} query(s), longest {elapsedMinutes}m", + $"{longRunning.Count} {(longRunning.Count == 1 ? "query" : "queries")}, longest {elapsedMinutes}m", $"{lrqThresholdMinutes}m", lrqContext, detailText, NumericCurrentValue: elapsedMinutes, @@ -3508,7 +3508,7 @@ displayed top N keeps its total instead of restarting. */ /* :603-613. ShortMessage = the toast body of :595. */ var delivery = await FireAsync(new AlertOutcome( key, serverName, "Long-Running Job", - $"{anomalousJobs.Count} job(s) exceeding {jobMultiplier}x average", + $"{anomalousJobs.Count} {(anomalousJobs.Count == 1 ? "job" : "jobs")} exceeding {jobMultiplier}x average", $"{jobMultiplier}x historical avg", jobContext, detailText, NumericCurrentValue: (double)(worst.PercentOfAverage ?? 0), @@ -3619,13 +3619,13 @@ displayed top N keeps its total instead of restarting. */ /* :698-708. ShortMessage = the toast body of :690. */ var delivery = await FireAsync(new AlertOutcome( key, serverName, "Failed Agent Job", - $"{failedJobs.Count} job failure(s) in last {failedJobLookbackMinutes}m — {jobNames}", + $"{failedJobs.Count} job {(failedJobs.Count == 1 ? "failure" : "failures")} in last {failedJobLookbackMinutes}m — {jobNames}", $"last {failedJobLookbackMinutes}m", failedJobContext, detailText, NumericCurrentValue: failedJobs.Count, NumericThresholdValue: 0, Muted: isMuted, Severity: failedJobContext?.SeverityOverride, - ShortMessage: $"{failedJobs.Count} job failure(s) — {jobNames}"), ct); + ShortMessage: $"{failedJobs.Count} job {(failedJobs.Count == 1 ? "failure" : "failures")} — {jobNames}"), ct); AfterFire("Failed Agent Job", _lastFailedJobAlert, key, now, alertCooldown, delivery); /* #4752: the in-memory watermark moved to the newest failure BEFORE the fire; the saved one diff --git a/PerformanceMonitor.Notifications/IncidentDeliveryFilter.cs b/PerformanceMonitor.Notifications/IncidentDeliveryFilter.cs index 5354871890..e0f8fa90cf 100644 --- a/PerformanceMonitor.Notifications/IncidentDeliveryFilter.cs +++ b/PerformanceMonitor.Notifications/IncidentDeliveryFilter.cs @@ -204,8 +204,9 @@ there rather than a copy of the string. Every other item (advice prose, remediat (OtherIncidentsLabel, string.Format( CultureInfo.InvariantCulture, - "{0} other incident(s) still open (already reported)", - suppressedCount)) + "{0} other {1} still open (already reported)", + suppressedCount, + suppressedCount == 1 ? "incident" : "incidents")) } }); diff --git a/PerformanceMonitor.Notifications/PerEventNotification.cs b/PerformanceMonitor.Notifications/PerEventNotification.cs index 19ac26c500..2e50acd7c8 100644 --- a/PerformanceMonitor.Notifications/PerEventNotification.cs +++ b/PerformanceMonitor.Notifications/PerEventNotification.cs @@ -85,7 +85,7 @@ public static List Split(AlertContext source, int maxPerCycle) ctx.Incidents = new List(overflow); for (int n = 0; n < overflow.Count; n++) ctx.Details.Add(AlertIncidentRenderer.BuildItem(overflow[n], $"Incident {n + 1} of {overflow.Count}", includeDetailFields: true)); - messages.Add(new Message(ctx, $"+{overflow.Count} more incident(s) this cycle", IsOverflow: true, NumericValue: overflow.Count)); + messages.Add(new Message(ctx, $"+{overflow.Count} more {(overflow.Count == 1 ? "incident" : "incidents")} this cycle", IsOverflow: true, NumericValue: overflow.Count)); } return messages; diff --git a/PerformanceMonitor.Notifications/RepeatDeliveryBudget.cs b/PerformanceMonitor.Notifications/RepeatDeliveryBudget.cs index 7d6f4b00ed..b00a32b8d2 100644 --- a/PerformanceMonitor.Notifications/RepeatDeliveryBudget.cs +++ b/PerformanceMonitor.Notifications/RepeatDeliveryBudget.cs @@ -567,7 +567,7 @@ private sealed class Entry public DateTime LastUtc { get; set; } /// - /// One roster line: SRV-A (1a2b3c4d5e6f, 4 occurrence(s)). The server first because that is + /// One roster line: SRV-A (1a2b3c4d5e6f, 4 occurrences) ("1 occurrence" for one). The server first because that is /// what an operator acts on; the fingerprint truncated because it is a correlator here and not the /// record (see ); the occurrence gauge only when the incident /// carried one, so a zero never reads as "measured none". @@ -585,7 +585,7 @@ public string Describe() if (Occurrences > 0) { - parts.Add(string.Format(CultureInfo.InvariantCulture, "{0} occurrence(s)", Occurrences)); + parts.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1}", Occurrences, Occurrences == 1 ? "occurrence" : "occurrences")); } return parts.Count > 0 From dc43c03b8c1f3404a5527f586c494920ffa8f460 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Sat, 24 Oct 2026 04:44:29 -0400 Subject: [PATCH 2/3] Alert count words: the deadlock text's reader accepts the new spelling, and the round-1 sibling sites agree with their counts (#6703) --- .../Darling.Tests/DarlingSelfAlertTests.cs | 21 +++++++++++- .../Darling.Tests/PgDeadlockRemaskTests.cs | 32 +++++++++++++++++++ .../StoreToastAndCheckpointerTests.cs | 13 ++++++-- .../DarlingSelfAlertEvaluator.cs | 4 +-- .../Mcp/DarlingMcpStoreMetricsTools.cs | 4 +-- .../PgDeadlockRemask.cs | 6 ++-- .../CurrentBlockingWaitResult.cs | 2 +- .../IAlertDeliverer.cs | 2 +- .../PerEventNotification.cs | 2 +- 9 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Darling/Darling.Tests/DarlingSelfAlertTests.cs b/Darling/Darling.Tests/DarlingSelfAlertTests.cs index f1b7b68239..2f68faad95 100644 --- a/Darling/Darling.Tests/DarlingSelfAlertTests.cs +++ b/Darling/Darling.Tests/DarlingSelfAlertTests.cs @@ -765,6 +765,14 @@ public async Task CaptureDown_OneMissingSession_ReadsInTheSingular() var fired = Assert.Single(h.Deliverer.Outcomes); Assert.Contains("The Blocking Extended Events session is missing", fired.DetailText, StringComparison.Ordinal); + Assert.Equal("Blocking capture is not running \u2014 XE session missing", fired.ShortMessage); + + /* Two sessions: the short message agrees the way the detail does (#6703's round-1 review). */ + var h2 = new Harness(); + await h2.Build().ApplyCaptureDownAsync(ServerId, Name, new[] { "Blocking", "Deadlock" }, Ct); + var both = Assert.Single(h2.Deliverer.Outcomes); + Assert.Contains("Extended Events sessions are missing", both.DetailText, StringComparison.Ordinal); + Assert.EndsWith("capture is not running \u2014 XE sessions missing", both.ShortMessage, StringComparison.Ordinal); } /* ---------------- agent-not-running edge (#1433 Phase 2) ---------------- */ @@ -1350,7 +1358,18 @@ public async Task CustomRuleHealth_OneRule_ReadsInTheSingular() await e.ApplyCustomRuleHealthAsync(HealthReport(broken: 1, neverFiring: 0), Ct); var fired = Assert.Single(h.Deliverer.Outcomes); - Assert.StartsWith("1 custom alert rule needs attention:", fired.ShortMessage, StringComparison.Ordinal); + Assert.Equal("1 custom alert rule needs attention: 1 no longer compiles, 0 armed but never fire", fired.ShortMessage); + + /* Every clause agrees with its own count, not only the head (#6703's round-1 review). */ + var h2 = new Harness(); + await h2.Build().ApplyCustomRuleHealthAsync(HealthReport(broken: 1, neverFiring: 1), Ct); + Assert.Equal("2 custom alert rules need attention: 1 no longer compiles, 1 armed but never fires", + Assert.Single(h2.Deliverer.Outcomes).ShortMessage); + + var h3 = new Harness(); + await h3.Build().ApplyCustomRuleHealthAsync(HealthReport(broken: 0, neverFiring: 2), Ct); + Assert.Equal("2 custom alert rules need attention: 0 no longer compile, 2 armed but never fire", + Assert.Single(h3.Deliverer.Outcomes).ShortMessage); } [Fact] diff --git a/Darling/Darling.Tests/PgDeadlockRemaskTests.cs b/Darling/Darling.Tests/PgDeadlockRemaskTests.cs index cac3a21163..087efee441 100644 --- a/Darling/Darling.Tests/PgDeadlockRemaskTests.cs +++ b/Darling/Darling.Tests/PgDeadlockRemaskTests.cs @@ -271,6 +271,38 @@ public void TheVictimStatement_IsWhatTheRemaskedGraphCarries_OrWithheldWithIt() Assert.Equal("UPDATE accounts SET pin = '?' WHERE card = ?", whole.VictimStatement); } + /// + /// The no-SQL line the live alert writes today ("victim pid 555, 1 participant" / "3 participants", #6703) is kept + /// as written when its report cannot be found, and does not count as text that still carries literals. The line + /// is built by itself, not typed here, so a change to the + /// builder's wording that the pass's whitelist does not follow fails this test. + /// + [Theory] + [InlineData(1)] + [InlineData(3)] + public void TheBuildersNoStatementLine_IsKeptAsWritten_AndNotJudgedToCarryLiterals(int participants) + { + var hash = PgDeadlockLogParser.HashOf("a report retention dropped, " + participants); + var built = DarlingWorker.BuildPgDeadlockIncident(new DarlingPgDeadlockReader.PgDeadlockRow( + new DateTime(2026, 8, 31, 0, 0, 0, DateTimeKind.Utc), 555, participants, hash, null, null, null, 1)); + var line = Assert.Single(built.InvolvedObjects); + Assert.Equal($"victim pid 555, {participants} {(participants == 1 ? "participant" : "participants")}", line); + + var context = AlertContextSerializer.Serialize(new AlertContext { Incidents = [built] }); + static PgDeadlockRemask.ResolvedReport Gone(string key) => new(PgDeadlockRemask.ReportState.Missing, null); + + /* Before every report is rewritten, a row holding only this line has nothing to rewrite and nothing that + would key it: a line judged to carry literals would be withheld and its key replaced here. */ + Assert.Null(PgDeadlockRemask.RemaskAlert(context, null, Gone, s_key, reportsMayBeRaw: true)); + + /* With the key passed (the alert-key stage), the key is replaced and the line stays as written. */ + var keyed = PgDeadlockRemask.RemaskAlert(context, null, Gone, s_key); + Assert.NotNull(keyed); + Assert.True(AlertContextSerializer.TryDeserialize(keyed.Value.ContextJson, out var after)); + Assert.Equal(s_key.DeadlockAlertKey(hash), after.Incidents![0].DedupKey); + Assert.Equal(line, Assert.Single(after.Incidents[0].InvolvedObjects)); + } + /// /// An alert whose report cannot be found (retention dropped it, or the report stage already rewrote it) has its /// statement normalized as it stands, and its key, which may be a raw graph's hash, keyed under the store's secret diff --git a/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs b/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs index 90ea963007..71f65eab6d 100644 --- a/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs +++ b/Darling/Darling.Tests/StoreToastAndCheckpointerTests.cs @@ -543,7 +543,8 @@ public void TheCheckpointerNote_AcrossARestart_StatesNoDelta_AndSaysWhy() Assert.Contains("judges neither arm: a standing alert neither fires nor recovers on it", note, StringComparison.Ordinal); Assert.Contains("That costs one skipped hourly interval; the next sweep differences cleanly against the post-restart row and is judged normally.", note, StringComparison.Ordinal); /* Never a figure, never the pressure prose, whatever the sync did. */ - Assert.DoesNotContain("checkpoint(s) were REQUESTED", note, StringComparison.Ordinal); + Assert.DoesNotContain("were REQUESTED rather than timed", note, StringComparison.Ordinal); + Assert.DoesNotContain("was REQUESTED rather than timed", note, StringComparison.Ordinal); Assert.DoesNotContain("in its sync (fsync) phase", note, StringComparison.Ordinal); Assert.DoesNotContain("CHECKPOINTER PRESSURE", note, StringComparison.Ordinal); } @@ -584,9 +585,15 @@ public void TheCheckpointerNote_SaysOneThingPerStatus_AndNamesTheLeversOnPressur /* Healthy per-checkpoint: 12 checkpoints, 84s summed sync -> 7s average, under the 10s bar; the old sum rule would have judged 84s against the same bar and misfired (#4037). */ var quiet = DarlingMcpStoreMetricsTools.CheckpointerNote(DarlingStoreMetricsReader.CheckpointerReading.From(new(t1, 2_000, 85_000, 5, Timed: 12), new(t0, 1_000, 1_000, 5, Timed: 0))); - Assert.Contains("12 checkpoint(s), spending", quiet, StringComparison.Ordinal); + Assert.Contains("12 checkpoints, spending", quiet, StringComparison.Ordinal); Assert.Contains("an average of 7.0s of sync per checkpoint", quiet, StringComparison.Ordinal); - Assert.Contains("0 checkpoint(s) were REQUESTED", quiet, StringComparison.Ordinal); + Assert.Contains("0 checkpoints were REQUESTED", quiet, StringComparison.Ordinal); + + /* One checkpoint and one requested checkpoint read in the singular (#6703's round-1 review). */ + var one = DarlingMcpStoreMetricsTools.CheckpointerNote(DarlingStoreMetricsReader.CheckpointerReading.From(new(t1, 2_000, 5_000, 6, Timed: 0), new(t0, 1_000, 1_000, 5, Timed: 0))); + Assert.Contains("1 checkpoint, spending", one, StringComparison.Ordinal); + Assert.Contains("1 checkpoint was REQUESTED rather than timed", one, StringComparison.Ordinal); + Assert.DoesNotContain("checkpoint(s)", one, StringComparison.Ordinal); Assert.Contains("Both under the lines the self-alert judges (average sync over 10s PER CHECKPOINT, or any requested checkpoint).", quiet, StringComparison.Ordinal); Assert.DoesNotContain("#3802", quiet, StringComparison.Ordinal); diff --git a/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs b/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs index db1f9bdab0..35f940b965 100644 --- a/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs +++ b/Darling/PerformanceMonitor.Darling.Service/DarlingSelfAlertEvaluator.cs @@ -1827,7 +1827,7 @@ internal async Task ApplyCaptureDownAsync( "collection log for the SESSION_MISSING detail (usually a permissions problem: " + "ALTER ANY EVENT SESSION on-prem, CREATE ANY DATABASE EVENT SESSION on Azure SQL DB).", severity: AlertSeverityLevel.Critical, - shortMessage: $"{list} capture is not running — XE session missing", + shortMessage: $"{list} capture is not running — XE {(missing.Count == 1 ? "session" : "sessions")} missing", /* Which capture is missing ("Blocking and Deadlock") against "session running". */ numericCurrentValue: StateOnlyValue, numericThresholdValue: StateOnlyValue, cancellationToken); @@ -5216,7 +5216,7 @@ await RecordResolutionAsync(new AlertResolution( private static (string ShortMessage, string Detail) RenderCustomRuleHealth(CustomAlertHealthReport report) { var shortMessage = string.Create(CultureInfo.InvariantCulture, - $"{report.TotalIssues} custom alert {(report.TotalIssues == 1 ? "rule needs" : "rules need")} attention: {report.BrokenRules.Count} no longer compile, {report.NeverFiringRules.Count} armed but never fire"); + $"{report.TotalIssues} custom alert {(report.TotalIssues == 1 ? "rule needs" : "rules need")} attention: {report.BrokenRules.Count} no longer {(report.BrokenRules.Count == 1 ? "compiles" : "compile")}, {report.NeverFiringRules.Count} armed but never {(report.NeverFiringRules.Count == 1 ? "fires" : "fire")}"); var sb = new StringBuilder(); sb.Append(shortMessage).Append('.'); diff --git a/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpStoreMetricsTools.cs b/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpStoreMetricsTools.cs index ba50483e88..a039812cfc 100644 --- a/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpStoreMetricsTools.cs +++ b/Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingMcpStoreMetricsTools.cs @@ -859,11 +859,11 @@ when it is measured and under the bar it is stated as a fact of the interval. */ + $"{DarlingSelfAlertEvaluator.FormatSyncSeconds(seen.SyncMs)}s, in the minute ending {DarlingSelfAlertEvaluator.FormatSyncMinute(seen.SampledUtc)}." : string.Empty; var measured = $" Over the {minutes} minutes ending {Stamp(reading.ObservedAt)} the checkpointer ran " - + (checkpointCount is long count ? $"{count} checkpoint(s), spending " : "an unmeasured number of checkpoints (a row before V140 has no timed count), spending ") + + (checkpointCount is long count ? $"{count} {(count == 1 ? "checkpoint" : "checkpoints")}, spending " : "an unmeasured number of checkpoints (a row before V140 has no timed count), spending ") + $"{(syncMs / 1000.0).ToString("0.0", CultureInfo.InvariantCulture)}s total in its sync (fsync) phase and " + $"{((reading.WriteMs ?? 0) / 1000.0).ToString("0.0", CultureInfo.InvariantCulture)}s in its write phase — " + (averageSyncMs is double average ? $"an average of {(average / 1000.0).ToString("0.0", CultureInfo.InvariantCulture)}s of sync per checkpoint — " : string.Empty) - + $"and {requested} checkpoint(s) were REQUESTED rather than timed (started by WAL volume reaching max_wal_size, " + + $"and {requested} {(requested == 1 ? "checkpoint was" : "checkpoints were")} REQUESTED rather than timed (started by WAL volume reaching max_wal_size, " + "a base backup, or a CHECKPOINT statement, not by checkpoint_timeout)."; if (!reading.IsPressure) diff --git a/Darling/PerformanceMonitor.Darling.Service/PgDeadlockRemask.cs b/Darling/PerformanceMonitor.Darling.Service/PgDeadlockRemask.cs index eec1f2288f..a1f5dec8b0 100644 --- a/Darling/PerformanceMonitor.Darling.Service/PgDeadlockRemask.cs +++ b/Darling/PerformanceMonitor.Darling.Service/PgDeadlockRemask.cs @@ -782,9 +782,11 @@ public enum ReportState public readonly record struct ResolvedReport(ReportState State, AlertIncident? Incident); /// The live alert's text for a report with no victim statement - /// (), which carries no SQL. + /// (), which carries no SQL. The builder writes "1 participant" or + /// "3 participants" (#6703); rows stored before that keep "2 participant(s)" for their retention, so all three + /// spellings are the same line. private static readonly Regex s_noStatementObject = new( - @"^victim pid -?[0-9]+, -?[0-9]+ participant\(s\)$", RegexOptions.Compiled | RegexOptions.CultureInvariant); + @"^victim pid -?[0-9]+, -?[0-9]+ participant(?:s|\(s\))?$", RegexOptions.Compiled | RegexOptions.CultureInvariant); /// A report's key as a PostgreSQL deadlock alert carries it: 's /// shape, 32 upper-case hex characters, which the SQL Server alert's fingerprint (64, lower case) never diff --git a/PerformanceMonitor.Alerting/CurrentBlockingWaitResult.cs b/PerformanceMonitor.Alerting/CurrentBlockingWaitResult.cs index 9fd164cbc7..096a75b474 100644 --- a/PerformanceMonitor.Alerting/CurrentBlockingWaitResult.cs +++ b/PerformanceMonitor.Alerting/CurrentBlockingWaitResult.cs @@ -49,7 +49,7 @@ namespace PerformanceMonitor.Alerting; /// /// The latest snapshot's collection time (naive UTC, as stored). /// Sum of wait_time_ms over that snapshot's rows. -/// Distinct blocked SPIDs in that snapshot — the alert text's "across N blocked session(s)". +/// Distinct blocked SPIDs in that snapshot — the alert text's "across N blocked sessions" ("across 1 blocked session" for one). /// False when the snapshot is older than ; see remarks. /// The server's effective dmv_blocking_snapshot cadence the freshness verdict was /// taken at, or null for a host that has none; see remarks (#3653 A5). diff --git a/PerformanceMonitor.Alerting/IAlertDeliverer.cs b/PerformanceMonitor.Alerting/IAlertDeliverer.cs index f779684cc1..d2a322b445 100644 --- a/PerformanceMonitor.Alerting/IAlertDeliverer.cs +++ b/PerformanceMonitor.Alerting/IAlertDeliverer.cs @@ -21,7 +21,7 @@ namespace PerformanceMonitor.Alerting; /// The engine's stable identity for the server (see ). /// Display name rendered in notifications. /// The alert metric name (e.g. "High CPU", "Deadlocks Detected") — the key mute rules, severity, and history filtering match on. -/// Human-readable current value (e.g. "3 deadlock(s) in the last hour"). +/// Human-readable current value (e.g. "3 deadlocks in the last hour", or "1 deadlock in the last hour"). /// Human-readable threshold it breached (e.g. "1", "80%"). /// Structured detail context (built by ), or null when no detail was resolvable. /// diff --git a/PerformanceMonitor.Notifications/PerEventNotification.cs b/PerformanceMonitor.Notifications/PerEventNotification.cs index 2e50acd7c8..fbdd69d158 100644 --- a/PerformanceMonitor.Notifications/PerEventNotification.cs +++ b/PerformanceMonitor.Notifications/PerEventNotification.cs @@ -49,7 +49,7 @@ public static class PerEventNotification /// One per-event notification to send: the single-incident (or overflow) context plus the /// "current value" string the caller passes to its alert sender. carries /// the same value as a number for the history stores (#1830): the overflow message's text - /// ("+N more incident(s) this cycle") is not parseable, and a store falling back to text-parsing + /// ("+N more incidents this cycle", "+1 more incident this cycle" for one) is not parseable, and a store falling back to text-parsing /// it silently recorded 0. public sealed record Message(AlertContext Context, string CurrentValue, bool IsOverflow, double? NumericValue = null); From af21dd48418bc5379e7d8abaa457534cb170986d Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:20:39 -0400 Subject: [PATCH 3/3] Mute parity pin starts after the word the count now picks (#6703) --- Lite.Tests/McpMissMessageParityPinTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lite.Tests/McpMissMessageParityPinTests.cs b/Lite.Tests/McpMissMessageParityPinTests.cs index e1eb157025..b0e54352a9 100644 --- a/Lite.Tests/McpMissMessageParityPinTests.cs +++ b/Lite.Tests/McpMissMessageParityPinTests.cs @@ -117,7 +117,7 @@ constants in Common (McpHelpers.CutWindowNothingMessage and CutWindowNothingRead /* get_mute_rules */ "No mute rules are configured for this store, so no alert is being suppressed anywhere — a quiet alert history is genuine rather than muted.", - "is disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", + "disabled or expired, so nothing is being suppressed. Pass enabled_only=false to list them — this is a lapsed mute, not an absent one.", /* compare_analysis */ "in EITHER window, so there is nothing to compare — this is NOT a report that nothing changed.",