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
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,36 @@ await DarlingMcpTestData.ExecAsync(c, TestContext.Current.CancellationToken,
Assert.DoesNotContain("quiet", message, StringComparison.Ordinal);
});

/* #6650: events of the tool's type WERE read in the window and its gate dropped them. The truncation answer must say
how many were read, not "No ... events were found" over a count of one or more. */
[Fact]
public async Task ATruncatedRingBufferRun_WithEventsReadButGatedOut_SaysHowManyWereRead_AgainstDevPostgres() =>
await RunHealthAsync("rbtrunc-read", async (c, ds, end) =>
{
await SeedHealthServerAsync(c, "rbtrunc-read", end.AddDays(-30), end.AddDays(-8), end.AddMinutes(-30));
var name = HealthName("rbtrunc-read");
var (eventType, fixture, _) = SourceOf(HealthTool.MemoryBroker);
var xml = System.IO.File.ReadAllText(System.IO.Path.Combine(AppContext.BaseDirectory, "Fixtures", "SystemHealth", fixture));
await DarlingMcpTestData.ExecAsync(c, TestContext.Current.CancellationToken,
@"INSERT INTO system_health_events (system_health_event_id, collection_time, server_id, server_name, event_time, event_type, event_xml)
VALUES ($1,$2,$3,$4,$5,$6,$7)",
CollectionIdGenerator.Next(), DarlingMcpTestData.Naive(end.AddDays(-1)), ServerIdHelper.GetDeterministicHashCode(name), name,
DarlingMcpTestData.Naive(end.AddDays(-1)), eventType, xml);
await DarlingMcpTestData.ExecAsync(c, TestContext.Current.CancellationToken,
@"INSERT INTO collection_log (log_id, server_id, server_name, collector_name, collection_time, duration_ms, status, rows_collected, error_message)
VALUES ($1, $2, $3, $4, $5, 12, 'SUCCESS', 0, 'ring_buffer_truncated=1 ring_buffer_events_hidden=773 newest_visible_event_age_s=19380')",
CollectionIdGenerator.Next(), ServerIdHelper.GetDeterministicHashCode(name), name, Collector, DarlingMcpTestData.Naive(end));

var root = WindowFloorLiveHarness.Parse(await CallHealthAsync(HealthTool.MemoryBroker, ds, "rbtrunc-read", 168, end));

Assert.Equal("unavailable", root.GetProperty("status").GetString());
var message = root.GetProperty("message").GetString()!;
Assert.StartsWith($"1 {eventType} event(s) were read for {name}", message, StringComparison.Ordinal);
Assert.DoesNotContain("events were found", message, StringComparison.Ordinal);
Assert.Contains("NOT an all-clear", message, StringComparison.Ordinal);
Assert.Contains("773 event(s) are hidden", message, StringComparison.Ordinal);
});

/* #6453: nothing of any type ever stored. The newest run read the live session through its event_file target and found
nothing: a true negative, `empty`. A fallback to the ring buffer, a ring buffer read with no note and a newest run that
was an ERROR keep `unavailable`, because the ring buffer path also records SUCCESS for a dead session. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ private static async Task<string> EmptyAsync<T>(
{
return WitnessStatus(
"unavailable",
RingBufferTruncationNote.HealthParserMessage(eventType, c.DisplayName, hoursBack, truncation),
RingBufferTruncationNote.HealthParserMessage(eventType, c.DisplayName, hoursBack, truncation, c.RawEventCount, noneQualifiedBecause),
sourceObserved: true, c.LastCapturedAt, lastCapturedOfTypeAt: lastOfType, eventsInWindow: c.RawEventCount);
}

Expand Down
27 changes: 27 additions & 0 deletions Lite.Tests/McpWindowNoticeSystemHealthToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,33 @@ INSERT INTO collection_log (log_id, server_id, server_name, collector_name, coll
Assert.DoesNotContain("quiet", message, StringComparison.Ordinal);
}

/* #6650: events of the tool's type WERE read in the window and its gate dropped them. The truncation answer must say
how many were read, not "No ... events were found" over a count of one or more. */
[Fact]
public async Task ATruncatedRingBuffer_WithEventsReadButGatedOut_SaysHowManyWereRead_NotThatNoneWereFound()
{
await _duckDb.InitializeFromTemplateAsync();
await SeedLogRunsAsync(Anchor.AddDays(-2), Anchor.AddMinutes(-30), everyMinutes: 30);
var (eventType, fixture, _) = SourceOf(Tool.MemoryBroker);
await ExecuteAsync(@"
INSERT INTO system_health_events (system_health_event_id, collection_time, server_id, server_name, event_time, event_type, event_xml)
VALUES ($1, $2, $3, $4, $2, $5, $6)",
_nextId++, Naive(Anchor.AddDays(-1)), _serverId, ServerName, eventType, LoadFixture(fixture));
await ExecuteAsync(@"
INSERT INTO collection_log (log_id, server_id, server_name, collector_name, collection_time, duration_ms, status, rows_collected, error_message)
VALUES ($1, $2, $3, 'system_health_events', $4, 12, 'SUCCESS', 0, 'ring_buffer_truncated=1 ring_buffer_events_hidden=773 newest_visible_event_age_s=19380')",
_nextId++, _serverId, ServerName, Naive(Anchor));

var root = Root(await CallAsync(Tool.MemoryBroker));

Assert.Equal("unavailable", root.GetProperty("status").GetString());
var message = root.GetProperty("message").GetString()!;
Assert.StartsWith("1 " + eventType + " event(s) were read for " + ServerName, message, StringComparison.Ordinal);
Assert.DoesNotContain("events were found", message, StringComparison.Ordinal);
Assert.Contains("NOT an all-clear", message, StringComparison.Ordinal);
Assert.Contains("773 event(s) are hidden", message, StringComparison.Ordinal);
}

/* #6441: a clean newest run after a truncated one clears the warning; the read answers as it did before. */
[Fact]
public async Task ATruncatedOlderRun_ThenACleanNewestRun_KeepsTheQuietAnswer()
Expand Down
19 changes: 19 additions & 0 deletions Lite.Tests/RingBufferTruncationSignalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ public void FormatCollectionNote_ATruncatedNote_SaysSoInPlainWords()
Assert.Contains("773 event(s) are hidden", some, StringComparison.Ordinal);
}

/* #6650: the health-parser truncation answer says how many events the read counted when it counted some, and keeps
"No ... events were found" only when it counted none. */
[Fact]
public void HealthParserMessage_WithEventsRead_SaysHowManyAndWhyNoneQualified_NotThatNoneWereFound()
{
var truncation = RingBufferTruncationNote.Describe(TruncatedNote)!;

var counted = RingBufferTruncationNote.HealthParserMessage(
"memory_broker", "srv", 24, truncation, eventsRead: 412, noneQualifiedBecause: "none passed the significance gate");

Assert.StartsWith("412 memory_broker event(s) were read for srv in the last 24 hour(s), and none passed the significance gate, and this is NOT an all-clear", counted, StringComparison.Ordinal);
Assert.DoesNotContain("were found", counted, StringComparison.Ordinal);
Assert.Contains("773 event(s) are hidden", counted, StringComparison.Ordinal);

var none = RingBufferTruncationNote.HealthParserMessage("memory_broker", "srv", 24, truncation);
Assert.StartsWith("No memory_broker events were found for srv in the last 24 hour(s), and this is NOT an all-clear", none, StringComparison.Ordinal);
Assert.Contains("773 event(s) are hidden", none, StringComparison.Ordinal);
}

[Theory]
[InlineData(45, "45 s")]
[InlineData(1200, "20 min")]
Expand Down
2 changes: 1 addition & 1 deletion Lite/Mcp/McpHealthParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private static async Task<string> EmptyAsync(
{
return WitnessStatus(
"unavailable",
RingBufferTruncationNote.HealthParserMessage(eventType, serverName, hoursBack, truncation),
RingBufferTruncationNote.HealthParserMessage(eventType, serverName, hoursBack, truncation, captured, noneQualifiedBecause),
sourceObserved: true, lastCapturedAt, lastCapturedOfTypeAt: lastOfType, eventsInWindow: captured);
}

Expand Down
32 changes: 26 additions & 6 deletions PerformanceMonitor.Common/RingBufferTruncationNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,35 @@ public static bool TryParse(string? note, out long eventsHidden, out long newest
/// The health-parser reads' answer (Lite and Darling, one string) when a category came back empty and the newest
/// system_health collection run says the ring buffer was truncated. Without it those reads called the window
/// "genuinely quiet" or "the healthy answer" while the newest events sat on the server unread (#6441).
/// <para>#6650: when the read did count events of the type (<paramref name="eventsRead"/> above 0) the first clause
/// says so, with the filter that left none (<paramref name="noneQualifiedBecause"/>), instead of "No ... events were
/// found" over a count of hundreds. At 0 it keeps that wording.</para>
/// </summary>
public static string HealthParserMessage(string eventType, string serverName, int hoursBack, string truncation) =>
string.Format(
public static string HealthParserMessage(
string eventType, string serverName, int hoursBack, string truncation,
int eventsRead = 0, string? noneQualifiedBecause = null)
Comment on lines +115 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, and not a reason to hold the PR.

Two observations about the optional-parameter shape here, both about the next caller rather than these two:

  1. eventsRead = 0 makes the pre-Health-parser reads say "No ... events were found" while the same answer counts 982 of them (ring-buffer truncation message) #6650 wording the default. A third reader of this helper that forgets the two arguments compiles clean and silently re-emits "No … events were found" over a nonzero count — the exact defect this PR fixes, with no test failing, because the two behaviour tests added here pin the two call sites that do pass them. Both current call sites are correct (Lite/Mcp/McpHealthParserTools.cs:689, Darling/…/DarlingMcpHealthParserTools.cs:899), so nothing is wrong today; required parameters would just make the regression impossible rather than merely untested.

  2. noneQualifiedBecause ?? "none qualified" (line 127) is unreachable: both call sites thread a non-null gate description down from EmptyAsync's required string noneQualifiedBecause parameter, and eventsRead > 0 is the only branch that reads it. Harmless as defence; just noting it is not exercised by anything.

{
var first = eventsRead > 0
? string.Format(
CultureInfo.InvariantCulture,
"{0} {1} event(s) were read for {2} in the last {3} hour(s), and {4}",
eventsRead,
eventType,
serverName,
hoursBack,
noneQualifiedBecause ?? "none qualified")
: string.Format(
CultureInfo.InvariantCulture,
"No {0} events were found for {1} in the last {2} hour(s)",
eventType,
serverName,
hoursBack);

return first + string.Format(
CultureInfo.InvariantCulture,
"No {0} events were found for {1} in the last {2} hour(s), and this is NOT an all-clear: the newest system_health collection run reported that {3}. Events of this type may exist on the server and not be stored here. Restarting the system_health session empties its ring buffer, and collection resumes until the buffer fills again.",
eventType,
serverName,
hoursBack,
", and this is NOT an all-clear: the newest system_health collection run reported that {0}. Events of this type may exist on the server and not be stored here. Restarting the system_health session empties its ring buffer, and collection resumes until the buffer fills again.",
truncation);
}

/// <summary>An age in seconds as <c>5 h 23 min</c>, <c>20 min</c> or <c>45 s</c>.</summary>
public static string FormatAge(long seconds)
Expand Down
Loading