Darling: live Current Active Queries via service-mediated command#1515
Merged
Conversation
Adds a LIVE, on-demand "what is running right now" DMV snapshot to the Darling viewer, delivered through the Stage-2 command plane exactly like execute_actual_plan / fetch_plan: the store-only viewer enqueues a new fetch_active_queries command, the service runs the query on the target server's live connection and returns the rows in result_json, and the viewer renders them in a new "Current Active Queries" sub-tab. Command plane (mirrors fetch_plan): - New CommandKind.FetchActiveQueries + "fetch_active_queries" case in DarlingCommandExecutor.ResolvePlan (requires target_server_id, no args) and the RunAsync dispatch to IDarlingCommandHost.FetchActiveQueriesLiveAsync. - WorkerCommandHost + DarlingWorker.RunFetchActiveQueriesLiveAsync resolve the runtime under the servers lock, return legible not-monitored / not-connected / timeout / permission / sql-error outcomes, and cap the SQL read at 30s (under the viewer's 60s poll budget). - Read-only DMV read (not consent-class like execute_actual_plan), but it rides the same read-write-seat-only enqueue as every other command. DMV query REUSED (not reinvented): - DarlingCollectorRunner.FetchRowsAsync runs the shared QuerySnapshotsCollector (BuildQuery + ReadAsync) against the live connection and returns the rows WITHOUT writing to the store, building the SAME CollectorContext the scheduled sweep builds, so the live snapshot carries the same columns as the stored one. Viewer: - ViewerDataService.RequestActiveQueriesLiveAsync enqueues, polls, deletes the (large) row, and parses result_json into ViewerQuerySnapshotRow (the stored grid's model), with read-only-seat / timeout / failure handling. - New "Current Active Queries" sub-tab (index 2, right after the stored Active Queries tab) with a Refresh button; on-demand only (never auto-fetched). Estimated/Actual plan buttons reuse the stored handlers. Tests (Darling.Tests green; build clean): - Pins the new command constant viewer<->executor, the ResolvePlan case, and the full service-serialize -> viewer-parse wire contract (no live SQL Server needed), plus timeout/failure mappings and the poll-budget ordering. Live fetch_active_queries executor round-trip gated on DARLING_TEST_PG like the fetch_plan one. Darling-only: no Lite, Dashboard, or install/*.sql changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a LIVE, on-demand "Current Active Queries" view to the Darling viewer — a DMV snapshot of what is running on a monitored server right now. Because Darling's viewer is store-only (no live SQL connection), it is delivered through the Stage-2 command plane exactly like
execute_actual_plan/fetch_plan: the viewer enqueues a newfetch_active_queriescommand, the SERVICE (which holds a live connection to every monitored server) runs the query on demand and returns the rows inresult_json, and the viewer renders them. This is the distinct LIVE counterpart of the collector's stored hourly "Active Queries" snapshot.Command plane (mirrors
fetch_plan)CommandKind.FetchActiveQueries+case "fetch_active_queries"inDarlingCommandExecutor.ResolvePlan(requirestarget_server_id, takes no args), and theRunAsyncdispatch toIDarlingCommandHost.FetchActiveQueriesLiveAsync.WorkerCommandHost+DarlingWorker.RunFetchActiveQueriesLiveAsyncresolve the runtime under the_serversLock, return legiblenot monitored/not connected/timed out/permission denied/sql erroroutcomes (mirroringRunFetchPlanAsync/RunExecuteActualPlanAsync), and cap the SQL read at 30s — comfortably under the viewer's 60s poll budget so the viewer sees a real timeout, not a poll miss (pinned by a test).result_json(jsonb); the command row is deleted after read (likefetch_plan/test_connect) since a live snapshot with inline plans can be large. Failure-isolated by the executor'sExecuteAndReportAsync.sys.dm_exec_requests/sessions+ the sql_text / query_plan DMFs), so — unlikeexecute_actual_plan— it is not consent-class, but it still rides the same read-write-seat-only enqueue as every other command.DMV query REUSED (not reinvented)
DarlingCollectorRunner.FetchRowsAsyncruns the sharedQuerySnapshotsCollector(BuildQuery+ReadAsync) against the live connection and returns the rows without writing to the store — the read-only "fetch phase only" twin ofRunAsync, building the SAMECollectorContextthe scheduled sweep builds. So the live snapshot carries the SAME columns as the stored one.Viewer
ViewerDataService.RequestActiveQueriesLiveAsyncenqueues → polls → deletes the row → parsesresult_jsonintoViewerQuerySnapshotRow(the stored grid's model), with read-only-seat / timeout / failure handling.Tests (
Darling.Testsgreen; builds clean)ViewerDataService.CommandFetchActiveQueries→CommandKind.FetchActiveQueries), theResolvePlancase, and the full service-serialize → viewer-parse wire contract (no live SQL Server needed), plus the timeout / failure mappings and the poll-budget-vs-SQL-cap ordering.fetch_active_queriesexecutor round-trip gated onDARLING_TEST_PG(skips in CI) like the existingfetch_planround-trip.Darling-only — no Lite, Full Dashboard, or
install/*.sqlchanges. No live SQL Server was hit during development.🤖 Generated with Claude Code