Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Darling/Darling.Tests/CollectionHistoryAuditTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ public void TheAuditedSources_AreTheLiveHourlyAggregatesForServers_AndThePerfmon
Assert.Contains("collection_time", TimescaleSupport.CreatePerfmonIntervalBaselineSql, StringComparison.Ordinal);
}

[Fact]
public void TheSourceCount_AgreesWithTheWord_ForOneSourceAndForMore()
{
/* #6700: "in 1 source," not "in 1 source(s),". */
var shared = new[] { new CollectionHistoryAudit.FlaggedRange(18, 21, 0, 40, 0, 0) };
var a = new Rollup("collect.query_store_stats_hourly", false);
var b = new Rollup("collect.query_store_stats_corrected_hourly", false);

var one = CollectionHistoryAudit.Render(AuditDay, new (Rollup, IReadOnlyList<CollectionHistoryAudit.FlaggedRange>)[] { (a, shared) });
Assert.Contains("for that hour in 1 source, where usual", one, StringComparison.Ordinal);

var two = CollectionHistoryAudit.Render(AuditDay, new (Rollup, IReadOnlyList<CollectionHistoryAudit.FlaggedRange>)[] { (a, shared), (b, shared) });
Assert.Contains("for that hour in 2 sources, where usual", two, StringComparison.Ordinal);
Assert.DoesNotContain("(s)", two, StringComparison.Ordinal);
}

[Fact]
public void SourcesWithIdenticalFlaggedRanges_ShareOneLine_AndUnreadSourcesAreNamed()
{
Expand Down
21 changes: 20 additions & 1 deletion Darling/Darling.Tests/ExternalAlertDeliverySelfAlertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public async Task Undelivered_FiresOnceWithTheCountsPerSource_AndNeverRepeatsASu
Assert.Equal("externalalerts", fired.ServerKey);
Assert.Equal(DarlingSelfAlertEvaluator.StoreServerLabel, fired.ServerName);
Assert.Equal("7", fired.CurrentValue);
Assert.Contains("7 external alerts were not delivered in the last hour", fired.ShortMessage);
Assert.Contains("2 expired, 4 interrupted, 1 failed", fired.ShortMessage);
Assert.Contains("- Source backup_svc: 2 expired, 1 failed", fired.DetailText);
Assert.Contains("- Source etl: 4 interrupted", fired.DetailText);
Expand Down Expand Up @@ -118,7 +119,25 @@ public async Task Undelivered_ListsAtMostTwentySources_AndTheCountReflectsAll()
Assert.Equal("25", fired.CurrentValue);
Assert.Contains("- Source src19:", fired.DetailText);
Assert.DoesNotContain("- Source src20:", fired.DetailText);
Assert.Contains("+ 5 more source(s).", fired.DetailText);
Assert.Contains("+ 5 more sources.", fired.DetailText);
}

[Fact]
public async Task Undelivered_TheWordsAgreeWithTheCounts_ForOneAlertAndForOneUnlistedSource()
{
/* #6700: "1 external alert was not delivered", not "1 external alert(s) were"; the 21st source is "1 more source.". */
var one = new DarlingSelfAlertTests.Harness();
await one.Build().ApplyExternalAlertsAsync(Report(("etl", "failed", 1)), Ct);
var single = Assert.Single(one.Deliverer.Outcomes);
Assert.StartsWith("1 external alert was not delivered in the last hour", single.ShortMessage);
Assert.DoesNotContain("(s)", single.DetailText);

var h = new DarlingSelfAlertTests.Harness();
var rows = Enumerable.Range(0, 21).Select(i => ("src" + i.ToString("D2", CultureInfo.InvariantCulture), "expired", 1)).ToArray();
await h.Build().ApplyExternalAlertsAsync(Report(rows), Ct);
var fired = Assert.Single(h.Deliverer.Outcomes);
Assert.Contains("+ 1 more source.", fired.DetailText);
Assert.DoesNotContain("(s)", fired.DetailText);
}

[Fact]
Expand Down
5 changes: 4 additions & 1 deletion Darling/Darling.Tests/WebPartialWindowBehaviourTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ public void TheCollectionHistoryAuditAlert_AgreesItsSourceCount_AndKeepsEveryOth
{
(sources[0], new[] { new CollectionHistoryAudit.FlaggedRange(18, 21, 0, 40, 0, 0) }),
},
sources.Skip(1).ToList());
sources.Skip(1).ToList())
// #6700: Render now says "in 1 source". An alert row stored before that fix still holds "in 1 source(s)", and
// that row is what the web rewrite is for, so the body here is the old row's text.
.Replace("in 1 source, where usual", "in 1 source(s), where usual", StringComparison.Ordinal);
Assert.DoesNotContain('\n', rendered);
Assert.Contains("in 1 source(s), where usual", rendered);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ internal static string Render(
{
var text = new StringBuilder();
text.Append(CultureInfo.InvariantCulture,
$"Retained history for {auditDayUtc:yyyy-MM-dd} (UTC) fell below half of the usual pace for that hour in {findings.Count} source(s), ")
$"Retained history for {auditDayUtc:yyyy-MM-dd} (UTC) fell below half of the usual pace for that hour in {findings.Count} {(findings.Count == 1 ? "source" : "sources")}, ")
.Append("where usual is the median of the 7 days before and only servers enabled now are counted. ");

var groups = new List<(bool JudgesPasses, bool Incomplete, List<Rollup> Sources, IReadOnlyList<FlaggedRange> Ranges)>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5343,7 +5343,7 @@ await RecordResolutionAsync(new AlertResolution(
private static (string ShortMessage, string Detail) RenderExternalAlerts(ExternalAlertsReport report)
{
var shortMessage = string.Create(CultureInfo.InvariantCulture,
$"{report.Total} external alert(s) were not delivered in the last hour: {report.Of("expired")} expired, {report.Of("interrupted")} interrupted, {report.Of("failed")} failed to send");
$"{report.Total} external {(report.Total == 1 ? "alert was" : "alerts were")} not delivered in the last hour: {report.Of("expired")} expired, {report.Of("interrupted")} interrupted, {report.Of("failed")} failed to send");

var sb = new StringBuilder();
sb.Append(shortMessage).Append('.');
Expand All @@ -5359,7 +5359,9 @@ private static (string ShortMessage, string Detail) RenderExternalAlerts(Externa

if (perSource.Count > MaxListedExternalSources)
{
sb.Append("\n+ ").Append((perSource.Count - MaxListedExternalSources).ToString(CultureInfo.InvariantCulture)).Append(" more source(s).");
/* #6700: "1 more source." / "N more sources." */
var unlisted = perSource.Count - MaxListedExternalSources;
sb.Append("\n+ ").Append(unlisted.ToString(CultureInfo.InvariantCulture)).Append(unlisted == 1 ? " more source." : " more sources.");
}

sb.Append("\nExpired: still queued when its deadline passed. Interrupted: a stopped service had claimed it and it is not sent again. Failed: every channel refused it and the retries ran out.");
Expand Down
Loading