From 3f5b8f4d6d483d4fff02372d06e9d25b8b4e3f1d Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Fri, 23 Oct 2026 15:47:10 -0400 Subject: [PATCH 1/8] Leave dropped databases out of the Viewer's Top Procedures read and say so (#6651) --- .../ViewerHourlyWindowEdgesTests.cs | 22 +- ...ViewerTopProceduresDroppedDatabaseTests.cs | 189 ++++++++++++++++++ .../ViewerDataService.ProcedureStats.cs | 66 +++++- .../ViewerDataService.RollupAvailability.cs | 5 +- .../ViewerServerTab.Queries.cs | 47 +++++ .../ViewerServerTab.xaml | 6 + 6 files changed, 315 insertions(+), 20 deletions(-) create mode 100644 Darling/Darling.Tests/ViewerTopProceduresDroppedDatabaseTests.cs diff --git a/Darling/Darling.Tests/ViewerHourlyWindowEdgesTests.cs b/Darling/Darling.Tests/ViewerHourlyWindowEdgesTests.cs index 816b113b39..47babc1cdf 100644 --- a/Darling/Darling.Tests/ViewerHourlyWindowEdgesTests.cs +++ b/Darling/Darling.Tests/ViewerHourlyWindowEdgesTests.cs @@ -50,24 +50,26 @@ public void HourlyCeilingSql_IsEmptyWithoutACeiling_AndBoundsTheBucketWithOne() public void HourlySql_BindsTheCeilingOnlyWhenOneIsKnown_OnBothGrids() { const string From = "collect.query_stats_io_hourly AS f"; - foreach (var build in new Func[] + /* The procedures grid binds the dropped-database exclusion at $6 (#6651), so its ceiling is the seventh parameter. */ + foreach (var (build, slot) in new (Func, int)[] { - ceiling => ViewerDataService.BuildTopQueriesHourlySql(From, withIo: true, ceiling: ceiling), - ceiling => ViewerDataService.BuildTopQueriesHourlySql(From, withIo: false, ceiling: ceiling), - ceiling => ViewerDataService.BuildTopProceduresHourlySql(From, withIo: true, ceiling: ceiling), - ceiling => ViewerDataService.BuildTopProceduresHourlySql(From, withIo: false, ceiling: ceiling), + (ceiling => ViewerDataService.BuildTopQueriesHourlySql(From, withIo: true, ceiling: ceiling), 6), + (ceiling => ViewerDataService.BuildTopQueriesHourlySql(From, withIo: false, ceiling: ceiling), 6), + (ceiling => ViewerDataService.BuildTopProceduresHourlySql(From, withIo: true, ceiling: ceiling), 7), + (ceiling => ViewerDataService.BuildTopProceduresHourlySql(From, withIo: false, ceiling: ceiling), 7), }) { + var ceilingSlot = "bucket < $" + slot; var bounded = build(Aligned); - Assert.Contains("bucket < $6", bounded, StringComparison.Ordinal); + Assert.Contains(ceilingSlot, bounded, StringComparison.Ordinal); /* The ceiling rides beside the window end, ahead of the grouping. */ Assert.True( - bounded.IndexOf("bucket < $3", StringComparison.Ordinal) < bounded.IndexOf("bucket < $6", StringComparison.Ordinal) - && bounded.IndexOf("bucket < $6", StringComparison.Ordinal) < bounded.IndexOf("GROUP BY", StringComparison.Ordinal)); + bounded.IndexOf("bucket < $3", StringComparison.Ordinal) < bounded.IndexOf(ceilingSlot, StringComparison.Ordinal) + && bounded.IndexOf(ceilingSlot, StringComparison.Ordinal) < bounded.IndexOf("GROUP BY", StringComparison.Ordinal)); - /* A null ceiling means no bound: today's text, with no sixth parameter. */ + /* A null ceiling means no bound: today's text, with no ceiling parameter. */ var open = build(null); - Assert.DoesNotContain("$6", open, StringComparison.Ordinal); + Assert.DoesNotContain(ceilingSlot, open, StringComparison.Ordinal); Assert.Contains("bucket < $3", open, StringComparison.Ordinal); } } diff --git a/Darling/Darling.Tests/ViewerTopProceduresDroppedDatabaseTests.cs b/Darling/Darling.Tests/ViewerTopProceduresDroppedDatabaseTests.cs new file mode 100644 index 0000000000..5fccb03add --- /dev/null +++ b/Darling/Darling.Tests/ViewerTopProceduresDroppedDatabaseTests.cs @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2026 Erik Darling, Darling Data LLC + * + * This file is part of the SQL Server Performance Monitor. + * + * Licensed under the MIT License. See LICENSE file in the project root for full license information. + */ + +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Npgsql; +using PerformanceMonitor.Collectors; +using PerformanceMonitor.Common; +using PerformanceMonitor.Darling.Storage; +using PerformanceMonitor.Darling.Viewer; +using Xunit; + +namespace Darling.Tests; + +/* #1776 own-store: the live tests mint their own scratch database and seed their own server, so they share no rows with another test. */ +/// +/// #6651 (#5633 item 4): the Viewer's Top Procedures by Duration read leaves out the databases the server dropped, as +/// get_top_procedures_by_cpu does, on the raw tier and on the hourly rollup. The dropped database is the HEAVIER one and the page +/// is top 1, so a read that only filtered after the LIMIT would come back empty or wrong. A database the caller names is read as asked. +/// +public sealed class ViewerTopProceduresDroppedDatabaseTests +{ + private const string Gone = "GoneDb"; + private const string Live = "LiveDb"; + + private static async Task SnapshotAsync(NpgsqlConnection connection, int serverId, string serverName, DateTime at, CancellationToken ct, params string[] databases) + { + var id = 1; + foreach (var database in databases) + { + await DarlingMcpTestData.ExecAsync(connection, ct, + "INSERT INTO database_states (collection_id, collection_time, server_id, server_name, database_name, database_id, state_desc, is_in_standby) VALUES ($1,$2,$3,$4,$5,$6,'ONLINE',FALSE)", + CollectionIdGenerator.Next(), DateTime.SpecifyKind(at, DateTimeKind.Unspecified), serverId, serverName, database, id++); + } + } + + private static async Task PlantProcedureAsync(NpgsqlConnection connection, int serverId, string serverName, string database, DateTime at, long executions, CancellationToken ct) + { + await DarlingMcpTestData.ExecAsync(connection, ct, + @"INSERT INTO collect.procedure_stats (collection_id, collection_time, server_id, server_name, database_name, schema_name, object_name, sql_handle, + delta_worker_time, delta_elapsed_time, delta_execution_count, delta_spills, sample_interval_seconds) + VALUES ($1,$2,$3,$4,$5,'dbo','usp_Work',$6,$7,$8,$9,0,3600)", + CollectionIdGenerator.Next(), DarlingMcpTestData.TruncateToSeconds(at), serverId, serverName, database, "0xH" + database, + executions * 1_000L, executions * 2_000L, executions); + } + + [Fact] + public async Task RawTier_LeavesTheDroppedDatabaseOut_RanksTheLiveOneAtTop1_AndReadsANamedDroppedDatabaseAsAsked() + { + var baseConnectionString = Environment.GetEnvironmentVariable("DARLING_TEST_PG"); + Assert.SkipWhen(string.IsNullOrEmpty(baseConnectionString), "Set DARLING_TEST_PG to a Postgres connection string to run the live Viewer dropped-database test."); + var ct = TestContext.Current.CancellationToken; + await using var scratch = await ScratchPostgres.CreateAsync(baseConnectionString!, ct); + await using var connection = new NpgsqlConnection(scratch.ConnectionString); + await connection.OpenAsync(ct); + await PgMigrations.MigrateAsync(connection, ct); + + const string serverName = "viewer-dropped-raw"; + var serverId = ServerIdHelper.GetDeterministicHashCode(serverName); + await DarlingMcpTestData.RegisterServerAsync(connection, serverId, serverName, ct); + var now = DateTime.UtcNow; + await PlantProcedureAsync(connection, serverId, serverName, Gone, now.AddHours(-2), 900, ct); + await PlantProcedureAsync(connection, serverId, serverName, Live, now.AddHours(-2), 100, ct); + + await using var viewer = new ViewerDataService(scratch.ConnectionString); + var start = now.AddHours(-24); + var end = now.AddMinutes(1); + + /* No snapshot: the set of databases is unknown, so nothing is left out and the heavier database ranks first. */ + var unknown = await viewer.GetTopProceduresByCpuRoutedAsync(serverId, start, end, 20, cancellationToken: ct); + Assert.Equal(new[] { Gone, Live }, unknown.Rows.Select(r => r.DatabaseName).ToArray()); + Assert.Null(unknown.LeftOutDatabases); + + /* An earlier snapshot named both; the newest names LiveDb only, so GoneDb was dropped in between. */ + await SnapshotAsync(connection, serverId, serverName, now.AddHours(-1), ct, Gone, Live); + await SnapshotAsync(connection, serverId, serverName, now.AddMinutes(-5), ct, Live); + + var top1 = await viewer.GetTopProceduresByCpuRoutedAsync(serverId, start, end, 1, cancellationToken: ct); + Assert.Equal("raw", top1.Tier); + Assert.Equal(new[] { Live }, top1.Rows.Select(r => r.DatabaseName).ToArray()); + Assert.Equal(new[] { Gone }, top1.LeftOutDatabases); + + /* Named, a dropped database is a question about its history and is read as asked, with nothing left out. */ + var named = await viewer.GetTopProceduresByCpuRoutedAsync(serverId, start, end, 20, new[] { Gone }, cancellationToken: ct); + Assert.Equal(new[] { Gone }, named.Rows.Select(r => r.DatabaseName).ToArray()); + Assert.Null(named.LeftOutDatabases); + } + + [Fact] + public async Task HourlyTier_LeavesTheDroppedDatabaseOut_AtTop1() + { + var baseConnectionString = Environment.GetEnvironmentVariable("DARLING_TEST_PG"); + Assert.SkipWhen(string.IsNullOrEmpty(baseConnectionString), "Set DARLING_TEST_PG to a Postgres connection string (with TimescaleDB installed) to run the live Viewer dropped-database hourly test."); + var ct = TestContext.Current.CancellationToken; + await using var scratch = await ScratchPostgres.CreateAsync(baseConnectionString!, ct); + await using var connection = new NpgsqlConnection(scratch.ConnectionString); + await connection.OpenAsync(ct); + await PgMigrations.MigrateAsync(connection, ct); + + var timescaleEnabled = await TimescaleSupport.TryEnableAsync(connection, null, ct); + Assert.SkipWhen(!timescaleEnabled, "The live Viewer dropped-database hourly test needs TimescaleDB."); + await TimescaleSupport.ConvertToHypertablesAsync(connection, null, ct); + Assert.True(await TimescaleSupport.EnsureCollectionLogHypertableAsync(connection, null, ct)); + await using (var stop = new NpgsqlCommand("SELECT _timescaledb_functions.stop_background_workers()", connection)) + { + await stop.ExecuteNonQueryAsync(ct); + } + + const string serverName = "viewer-dropped-hourly"; + var serverId = ServerIdHelper.GetDeterministicHashCode(serverName); + await DarlingMcpTestData.RegisterServerAsync(connection, serverId, serverName, ct); + await TimescaleSupport.EnsureContinuousAggregatesAsync(connection, null, ct); + + /* A fixed past window, as the other hourly live tests use; the snapshots sit just before the window's end, which the read anchors at. */ + var windowStart = new DateTime(2026, 1, 5, 0, 0, 0, DateTimeKind.Unspecified); + var hour = windowStart.AddHours(1); + var end = windowStart.AddHours(8); + var bodySucceeded = false; + try + { + await PlantProcedureAsync(connection, serverId, serverName, Gone, hour.AddMinutes(10), 900, ct); + await PlantProcedureAsync(connection, serverId, serverName, Live, hour.AddMinutes(10), 100, ct); + await SnapshotAsync(connection, serverId, serverName, end.AddHours(-4), ct, Gone, Live); + await SnapshotAsync(connection, serverId, serverName, end.AddHours(-1), ct, Live); + + foreach (var view in new[] { TimescaleSupport.ProcedureStatsHourlyView, TimescaleSupport.ProcedureStatsIntervalHourlyView, TimescaleSupport.ProcedureStatsIoHourlyView }) + { + await using var refresh = new NpgsqlCommand($"CALL refresh_continuous_aggregate('collect.{view}'::regclass, $1::timestamp, $2::timestamp)", connection); + refresh.Parameters.AddWithValue(windowStart); + refresh.Parameters.AddWithValue(end); + await refresh.ExecuteNonQueryAsync(ct); + } + + /* Purge raw so the router answers from the rollup. */ + await DarlingMcpTestData.ExecAsync(connection, ct, + "DELETE FROM collect.procedure_stats WHERE server_id = $1 AND collection_time >= $2 AND collection_time < $3", serverId, windowStart, windowStart.AddDays(1)); + + await using var viewer = new ViewerDataService(scratch.ConnectionString); + var read = await viewer.GetTopProceduresByCpuRoutedAsync(serverId, hour, end, 1, cancellationToken: ct); + Assert.Equal("hourly", read.Tier); + Assert.Equal(new[] { Live }, read.Rows.Select(r => r.DatabaseName).ToArray()); + Assert.Equal(new[] { Gone }, read.LeftOutDatabases); + + var named = await viewer.GetTopProceduresByCpuRoutedAsync(serverId, hour, end, 1, new[] { Gone }, cancellationToken: ct); + Assert.Equal(new[] { Gone }, named.Rows.Select(r => r.DatabaseName).ToArray()); + Assert.Null(named.LeftOutDatabases); + bodySucceeded = true; + } + finally + { + await LiveStoreCleanup.RunAsync(scratch.ConnectionString, bodySucceeded, (cleanup, cleanupCt) => Task.CompletedTask); + } + } + + private static readonly string[] Dropped = { "zz_a", "zz_b" }; + + [Fact] + public void LeftOutText_IsNullWhenNothingWasLeftOut() + { + Assert.Null(ViewerServerTab.ProcedureLeftOutText(null, 5, null, 24)); + Assert.Null(ViewerServerTab.ProcedureLeftOutText(Array.Empty(), 0, null, 24)); + } + + [Fact] + public void LeftOutText_WithRows_NamesTheDatabasesAndSaysHowToReadThem() + { + var text = ViewerServerTab.ProcedureLeftOutText(Dropped, 3, null, 24)!; + Assert.Contains("Left out: zz_a, zz_b.", text, StringComparison.Ordinal); + Assert.Contains("left out of this read", text, StringComparison.Ordinal); + } + + [Fact] + public void LeftOutText_OnAnEmptyPage_SaysNoProcedureRanInADatabaseTheServerStillHas_AndHidesTheMcpKey() + { + var facts = new CollectorRunFacts(10, 4, DateTime.UtcNow, null); + var text = ViewerServerTab.ProcedureLeftOutText(Dropped, 0, facts, 24)!; + Assert.Contains("No procedure ran in the last 24h in a database this server still has", text, StringComparison.Ordinal); + Assert.Contains("2 database(s) the server no longer lists were left out of this read", text, StringComparison.Ordinal); + Assert.DoesNotContain("databases_left_out", text, StringComparison.Ordinal); + Assert.Contains("Left out: zz_a, zz_b.", text, StringComparison.Ordinal); + } +} diff --git a/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.ProcedureStats.cs b/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.ProcedureStats.cs index de2e4a1d76..b0561fa51a 100644 --- a/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.ProcedureStats.cs +++ b/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.ProcedureStats.cs @@ -86,7 +86,8 @@ public sealed partial class ViewerDataService /// default), and cap at top — no LATERAL / WAITFOR trim (procedures aren't ad-hoc text). Viewer /// deviations: summed bigints CAST back to bigint for GetInt64; Lite's staleness filter + /// utcOffsetMinutes param dropped. - /// $1 server_id, $2 window start, $3 window end (naive UTC), $4 top. + /// $1 server_id, $2 window start, $3 window end (naive UTC), $4 top, $5 the databases chosen (NULL is every one), + /// $6 the databases the server dropped (#6651, NULL leaves out none). /// public const string TopProceduresSql = """ SELECT @@ -134,6 +135,7 @@ FROM procedure_stats AND collection_time >= $2 AND collection_time <= $3 AND ($5::text[] IS NULL OR database_name = ANY($5)) + AND ($6::text[] IS NULL OR database_name IS NULL OR database_name <> ALL($6)) /*TAG:object:database_name,schema_name,object_name*/ GROUP BY database_name, schema_name, object_name, object_type HAVING SUM(delta_execution_count) > 0 OR SUM(delta_elapsed_time) > 0 @@ -185,9 +187,20 @@ public async Task> GetTopProceduresByC private async Task> GetTopProceduresByCpuRoutedUntaggedAsync( int serverId, DateTime startUtc, DateTime endUtc, int top, IReadOnlyList? databaseNames, QueryTagFilter? tags, CancellationToken cancellationToken) { + /* #6651 (#5633 item 4): with no database chosen the ranking leaves out the databases the server dropped, the way + get_top_procedures_by_cpu does (CurrentDatabaseScope.NarrowAsync, the one rule the service and the web share). The exclusion + is in the statement ($6), so the rank's LIMIT is not filled by a dropped database; a database the user names is read as asked; + an unknown set (no recent snapshot) leaves out nothing. A custom range that ended in the past is anchored at its end, as the + MCP tool's as_of read is, so a database dropped since still ranks for a window it existed in. */ + var now = DateTime.UtcNow; + var databases = await CurrentDatabaseScope.NarrowAsync( + _dataSource, serverId, DatabaseFilter.Of(databaseNames), nowUtc: now, asOfUtc: endUtc < now ? endUtc : null, + windowStartUtc: startUtc, cancellationToken: cancellationToken); + var leftOut = DatabasesLeftOut.Distinct(databases.ExcludedNames); + var (rollups, coverage) = await GetRollupAvailabilityAsync(cancellationToken); var routedTier = RetentionTierRouter.Resolve( - DateTime.UtcNow, startUtc, rollups.ProcedureGrainHourly, dailyAvailable: false, + now, startUtc, rollups.ProcedureGrainHourly, dailyAvailable: false, coverage.For(TimescaleSupport.ProcedureStatsHourlyView, TimescaleSupport.ProcedureStatsDailyView)); if (routedTier == RetentionTier.Daily) { @@ -196,10 +209,13 @@ private async Task> GetTopProceduresBy if (routedTier == RetentionTier.Hourly) { - return await GetTopProceduresByCpuHourlyAsync(rollups, coverage, serverId, startUtc, endUtc, top, databaseNames, tags, cancellationToken); + var hourly = await GetTopProceduresByCpuHourlyAsync(rollups, coverage, serverId, startUtc, endUtc, top, databaseNames, databases, tags, cancellationToken); + return hourly with { LeftOutDatabases = leftOut }; } - return new ViewerRoutedRead(await GetTopProceduresByCpuRawAsync(serverId, startUtc, endUtc, top, databaseNames, tags, cancellationToken), "raw", null); + return new ViewerRoutedRead( + await GetTopProceduresByCpuRawAsync(serverId, startUtc, endUtc, top, databaseNames, databases, tags, cancellationToken), "raw", null, + LeftOutDatabases: leftOut); } /// #4231 stage 3b: the hourly-rollup arm — builds its FROM clause ONLY through @@ -209,7 +225,7 @@ private async Task> GetTopProceduresBy /// rollup has none of those columns. private async Task> GetTopProceduresByCpuHourlyAsync( RollupAvailability rollups, RollupCoverage coverage, int serverId, DateTime startUtc, DateTime endUtc, int top, - IReadOnlyList? databaseNames, QueryTagFilter? tags, CancellationToken cancellationToken) + IReadOnlyList? databaseNames, DatabaseFilter databases, QueryTagFilter? tags, CancellationToken cancellationToken) { /* #5329: the io hourly rollup, when it reaches the window's start, in place of the interval rollup (same columns plus the three I/O sums); otherwise today's route and blank columns. See the queries arm. */ @@ -231,6 +247,7 @@ private async Task> GetTopProceduresBy AddServerWindowParameters(command, serverId, startUtc, endUtc); command.Parameters.Add(new Npgsql.NpgsqlParameter { TypedValue = top }); command.Parameters.Add(DatabaseFilterParameter(databaseNames)); + command.Parameters.Add(databases.ExcludeParameter()); AddHourlyCeilingParameter(command, ceiling); await using var reader = await command.ExecuteReaderAsync(cancellationToken); while (await reader.ReadAsync(cancellationToken)) @@ -280,8 +297,8 @@ internal static string BuildTopProceduresHourlySql(string fromClause, bool withI FROM {fromClause} WHERE server_id = $1 AND bucket >= $2 - AND bucket < $3{HourlyCeilingSql(ceiling)} - AND ($5::text[] IS NULL OR database_name = ANY($5)) + AND bucket < $3{HourlyCeilingSql(ceiling, 7)} + AND ($5::text[] IS NULL OR database_name = ANY($5)){DatabaseFilter.ExcludeClause("database_name", 6)} /*TAG:object:database_name,schema_name,object_name*/ GROUP BY database_name, schema_name, object_name HAVING (SUM(execution_count_sum) > 0 OR SUM(elapsed_time_sum) > 0) @@ -292,7 +309,7 @@ ORDER BY SUM(worker_time_sum) DESC /// The Raw-tier read, unchanged — what ran before #4231 /// stage 3b added the hourly arm. private async Task> GetTopProceduresByCpuRawAsync( - int serverId, DateTime startUtc, DateTime endUtc, int top, IReadOnlyList? databaseNames, QueryTagFilter? tags, CancellationToken cancellationToken) + int serverId, DateTime startUtc, DateTime endUtc, int top, IReadOnlyList? databaseNames, DatabaseFilter databases, QueryTagFilter? tags, CancellationToken cancellationToken) { var rows = new List(); @@ -301,6 +318,7 @@ private async Task> GetTopProceduresByCpuRawAsync( AddServerWindowParameters(command, serverId, startUtc, endUtc); command.Parameters.Add(new Npgsql.NpgsqlParameter { TypedValue = top }); command.Parameters.Add(DatabaseFilterParameter(databaseNames)); + command.Parameters.Add(databases.ExcludeParameter()); await using var reader = await command.ExecuteReaderAsync(cancellationToken); while (await reader.ReadAsync(cancellationToken)) { @@ -341,6 +359,38 @@ private async Task> GetTopProceduresByCpuRawAsync( return rows; } + /// #6651: the procedure_stats collector's own run history (successful runs, and how many fell inside the window), the + /// facts words an empty page from. The same three counts as the service's + /// DarlingCollectorRunFactsReader, in one statement; read only when the page is empty and databases were left out. + public const string ProcedureStatsRunFactsSql = """ + SELECT + (SELECT COUNT(*) FROM (SELECT 1 FROM v_collection_log + WHERE server_id = $1 AND collector_name = 'procedure_stats' AND status = 'SUCCESS' + ORDER BY collection_time DESC LIMIT 2) AS newest) AS runs, + (SELECT MAX(collection_time) FROM v_collection_log + WHERE server_id = $1 AND collector_name = 'procedure_stats' AND status = 'SUCCESS' AND collection_time <= $3) AS last_success, + (SELECT COUNT(*) FROM v_collection_log + WHERE server_id = $1 AND collector_name = 'procedure_stats' AND status = 'SUCCESS' + AND collection_time >= $2 AND collection_time <= $3) AS in_window + """; + + /// #6651: for the window [, ]. + public async Task GetProcedureStatsRunFactsAsync( + int serverId, DateTime startUtc, DateTime endUtc, CancellationToken cancellationToken = default) + { + await using var command = _dataSource.CreateCommand(ProcedureStatsRunFactsSql); + command.CommandTimeout = ViewerCommandDeadlines.CurrentInteractiveReadSeconds; + AddServerWindowParameters(command, serverId, startUtc, endUtc); + await using var reader = await command.ExecuteReaderAsync(cancellationToken); + if (!await reader.ReadAsync(cancellationToken)) + { + return CollectorRunFacts.None; + } + + DateTime? last = reader.IsDBNull(1) ? null : DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc); + return new CollectorRunFacts(reader.GetInt64(0), reader.GetInt64(2), last, null); + } + /// /// #4231: the raw floor for procedure_stats over [, /// ] — the shared probe (), never a second, hand-copied diff --git a/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.RollupAvailability.cs b/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.RollupAvailability.cs index 59b5660f5c..605b0a4e48 100644 --- a/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.RollupAvailability.cs +++ b/Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.RollupAvailability.cs @@ -96,7 +96,7 @@ internal static bool IoHourlyCoversWindow( /// the service's MCP reads bind too), the empty string when it has none (a null ceiling means no bound). A bucket at /// or after the ceiling is never read, so "nothing after the ceiling was read" holds by construction. /// - internal static string HourlyCeilingSql(DateTime? ceiling) => ceiling is null ? "" : "\n AND bucket < $6"; + internal static string HourlyCeilingSql(DateTime? ceiling, int index = 6) => ceiling is null ? "" : $"\n AND bucket < ${index}"; /// Binds the ceiling names, as a naive UTC instant, when there is one. internal static void AddHourlyCeilingParameter(NpgsqlCommand command, DateTime? ceiling) @@ -150,4 +150,5 @@ internal Task WarmRollupCoverageAsync(CancellationToken cancellationToken = defa /// grid really covers). /// public sealed record ViewerRoutedRead( - List Rows, string Tier, string? HourlyEdgesNote, bool IoRoute = false, DateTime? HourlyFirstBucket = null); + List Rows, string Tier, string? HourlyEdgesNote, bool IoRoute = false, DateTime? HourlyFirstBucket = null, + IReadOnlyList? LeftOutDatabases = null); diff --git a/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.Queries.cs b/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.Queries.cs index e0c87f142d..f86f59c0a2 100644 --- a/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.Queries.cs +++ b/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.Queries.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using System.Windows; @@ -266,6 +267,7 @@ private async Task LoadTopProceduresAsync(DateTime startUtc, DateTime endUtc, Vi /* #4231 stage 3b: an hourly-routed page holds no object_type/sql_handle/plan_handle — the raw-floor banner and this tier disclosure are independent facts, same reasoning as the Queries sub-tab. */ UpdateTruncationBanner(ProcStatsTruncationBanner, await DataStartOrNullAsync(floorTask, "Procedure Stats"), startUtc, HourlyBannerSuffix(read.Tier, read.IoRoute, read.HourlyEdgesNote), HourlyServedOf(read.Tier, read.HourlyFirstBucket)); + await UpdateProcStatsLeftOutBannerAsync(read, startUtc, endUtc); await LoadProcStatsSlicerAsync(startUtc, endUtc, slicerTask); } catch @@ -279,6 +281,50 @@ private async Task LoadTopProceduresAsync(DateTime startUtc, DateTime endUtc, Vi await RefreshProcStatsComparisonAsync(startUtc, endUtc, timer); } + /// + /// #6651 (#5633 item 4): says what the Top Procedures read left out. The grid's ranking skips the databases the server no longer + /// lists, so the page names them (the words the web page and get_top_procedures_by_cpu use), and an EMPTY page says only that + /// no procedure ran in a database the server still has, from the collector's own run history, never "nothing was recorded". + /// Collapsed when nothing was left out. + /// + private async Task UpdateProcStatsLeftOutBannerAsync(ViewerRoutedRead read, DateTime startUtc, DateTime endUtc) + { + CollectorRunFacts? facts = null; + if (read.Rows.Count == 0 && read.LeftOutDatabases is { Count: > 0 }) + { + facts = await _dataService.GetProcedureStatsRunFactsAsync(_server.ServerId, startUtc, endUtc); + } + + var text = ProcedureLeftOutText(read.LeftOutDatabases, read.Rows.Count, facts, (int)Math.Max(1, Math.Round((endUtc - startUtc).TotalHours))); + ProcStatsLeftOutBanner.Text = text ?? ""; + ProcStatsLeftOutBanner.Visibility = text is null ? Visibility.Collapsed : Visibility.Visible; + } + + /// + /// #6651: the banner text for a Top Procedures read that left databases out, or null when it left none. With rows, the names and + /// the shared . With none, the shared empty-page sentence + /// (, so the wording matches the web page and the MCP tool) followed by the names. The + /// shared sentence points at the MCP key databases_left_out; a person reading this window has the names in the same banner, so + /// that pointer is dropped. + /// + internal static string? ProcedureLeftOutText(IReadOnlyList? leftOut, int rowCount, CollectorRunFacts? facts, int hoursBack) + { + if (leftOut is null || leftOut.Count == 0) + { + return null; + } + + var named = DatabasesLeftOut.Named(leftOut)!; + var names = "Left out: " + string.Join(", ", named) + (leftOut.Count > named.Count ? string.Format(CultureInfo.InvariantCulture, " and {0} more", leftOut.Count - named.Count) : "") + "."; + if (rowCount == 0 && facts is not null) + { + var (_, message) = facts.ProcedureStatsEmpty(hoursBack, leftOut.Count); + return message.Replace(" (see databases_left_out)", "", StringComparison.Ordinal) + " " + names; + } + + return DatabasesLeftOut.Note(leftOut) + " " + names; + } + private async Task LoadQueryStoreAsync(DateTime startUtc, DateTime endUtc, ViewerLoadTimer? timer = null) { timer?.Surface = "Queries > Query Store by Duration"; @@ -580,6 +626,7 @@ private async void OnProcStatsSlicerChanged(object? sender, SlicerRangeEventArgs var rows = read.Rows; _procStatsFilterMgr!.UpdateData(rows); UpdateTruncationBanner(ProcStatsTruncationBanner, await DataStartOrNullAsync(floorTask, "Procedure Stats"), e.StartUtc, HourlyBannerSuffix(read.Tier, read.IoRoute, read.HourlyEdgesNote), HourlyServedOf(read.Tier, read.HourlyFirstBucket)); + await UpdateProcStatsLeftOutBannerAsync(read, e.StartUtc, e.EndUtc); await RefreshProcStatsComparisonAsync(e.StartUtc, e.EndUtc); } catch (Exception ex) diff --git a/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.xaml b/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.xaml index a3efec8932..0571fdf6d3 100644 --- a/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.xaml +++ b/Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.xaml @@ -1217,6 +1217,12 @@ Padding="8,4" FontWeight="Bold" Foreground="{DynamicResource ForegroundBrush}" Background="#22FFAA00"/> + + Date: Fri, 23 Oct 2026 15:55:48 -0400 Subject: [PATCH 2/8] Remove the Job History Last Success column that repeated the job's newest success on every row (#6651) --- Darling/Darling.Tests/StoredServerClockRowTextTests.cs | 4 ---- .../Darling.Tests/ViewerGridTimeColumnSortMemberTests.cs | 1 - .../PerformanceMonitor.Darling.Viewer/JobHistoryTab.xaml | 8 -------- .../ViewerDataService.JobHistory.cs | 5 ----- 4 files changed, 18 deletions(-) diff --git a/Darling/Darling.Tests/StoredServerClockRowTextTests.cs b/Darling/Darling.Tests/StoredServerClockRowTextTests.cs index 1e70719b81..a9559812a2 100644 --- a/Darling/Darling.Tests/StoredServerClockRowTextTests.cs +++ b/Darling/Darling.Tests/StoredServerClockRowTextTests.cs @@ -118,8 +118,6 @@ public void AJobStepReadFromTheStoredWallClock_PrintsNoOffset_InBothPassesOfTheR Assert.Equal("2026-11-01 01:30:00", firstPass.RunTimeLocal); Assert.Equal("2026-11-01 01:30:00", secondPass.RunTimeLocal); - Assert.Equal("2026-11-01 01:45:00", firstPass.LastSuccessfulRunLocal); - Assert.Equal("2026-11-01 01:45:00", secondPass.LastSuccessfulRunLocal); /* A real instant in the same test keeps the offset: the two passes of 01:30 are 05:30Z and 06:30Z. */ Assert.Equal("2026-11-01 01:30:00 -04:00", TrueUtcRowText(Naive(2026, 11, 1, 5, 30))); @@ -138,8 +136,6 @@ public void AJobStepOutsideTheRepeatedHour_ReadsAsTheDisplayTextItAlwaysDid() Assert.Equal("2026-11-01 00:59:00", beforeTheHour.RunTimeLocal); Assert.Equal("2026-11-01 02:00:00", afterTheHour.RunTimeLocal); Assert.Equal("2026-07-06 12:00:00", summer.RunTimeLocal); - Assert.Equal("2026-07-06 11:00:00", summer.LastSuccessfulRunLocal); - Assert.Equal("Never", beforeTheHour.LastSuccessfulRunLocal); Assert.Equal("", new ViewerJobHistoryRow().RunTimeLocal); } diff --git a/Darling/Darling.Tests/ViewerGridTimeColumnSortMemberTests.cs b/Darling/Darling.Tests/ViewerGridTimeColumnSortMemberTests.cs index b888ffd227..85a135b78c 100644 --- a/Darling/Darling.Tests/ViewerGridTimeColumnSortMemberTests.cs +++ b/Darling/Darling.Tests/ViewerGridTimeColumnSortMemberTests.cs @@ -106,7 +106,6 @@ public sealed class ViewerGridTimeColumnSortMemberTests /* Columns whose row already had a UTC (or display-zone) DateTime and only lacked the SortMemberPath. */ { "AlertsHistoryTab.xaml", "AlertsDataGrid", "TimeLocal", Name(typeof(ViewerAlertRow)), "AlertTime" }, { "JobHistoryTab.xaml", "JobHistoryDataGrid", "RunTimeLocal", Name(typeof(ViewerJobHistoryRow)), "RunDateTimeUtc" }, - { "JobHistoryTab.xaml", "JobHistoryDataGrid", "LastSuccessfulRunLocal", Name(typeof(ViewerJobHistoryRow)), "LastSuccessfulRunUtc" }, { "MuteRulesWindow.xaml", "RulesGrid", "ExpiresDisplay", Name(typeof(MuteRule)), "ExpiresAtUtc" }, { "ProcedureHistoryWindow.xaml", "HistoryDataGrid", "CollectionTimeLocal", Name(typeof(ViewerProcedureStatsHistoryRow)), "CollectionTime" }, { "QueryStatsHistoryWindow.xaml", "HistoryDataGrid", "CollectionTimeLocal", Name(typeof(ViewerQueryStatsHistoryRow)), "CollectionTime" }, diff --git a/Darling/PerformanceMonitor.Darling.Viewer/JobHistoryTab.xaml b/Darling/PerformanceMonitor.Darling.Viewer/JobHistoryTab.xaml index 43b731d2ed..c0d50cb23a 100644 --- a/Darling/PerformanceMonitor.Darling.Viewer/JobHistoryTab.xaml +++ b/Darling/PerformanceMonitor.Darling.Viewer/JobHistoryTab.xaml @@ -189,14 +189,6 @@ - - - -