Analysis: server-local analysis window + null-safe blocking analyzer#1068
Merged
Conversation
Two correctness fixes found while debugging why windowed analysis surfaced nothing on a non-UTC server (sql2022 is UTC-7). Server-local analysis window: - AnalysisService built the window from DateTime.UtcNow, but every collector stamps rows with SYSDATETIME() (server-local). So all 102 windowed reads (wait/CPU/blocking facts, anomaly detection, every drill-down enrichment) filtered server-local data against a UTC window and silently matched nothing on any non-UTC server -- the entire windowed half of the engine was dark there (proven: 0 rows in the UTC window vs 11,050 wait rows in the server-local window on sql2022). - Fix at the source: AnalyzeAsync / CollectAndScoreFactsAsync probe the monitored server's clock (SELECT SYSDATETIME(), SYSUTCDATETIME()) and build a SERVER-LOCAL window, capturing the UTC offset on AnalysisContext. The 102 windowed reads are unchanged. SqlServerFindingStore converts the window back to UTC for persistence, so stored time_range_*/analysis_time stay UTC and the reader's AsUtc, the deep-link offset math, and the retention purge are all unchanged. compare_analysis uses the server clock too. Falls back to host UTC if the probe fails (prior behavior; no new hard-failure mode). Null-safe blocking_deadlock_analyzer (install/26): - total_blocking_duration_ms = SUM(wait_time_ms) / MAX(...) and total_deadlock_wait_time_ms = SUM(wait_time) feed NOT NULL columns, but those source columns are nullable -- a report missing the duration made the SUM/MAX NULL and failed the whole insert. Wrapped in ISNULL(..., 0). Verified on sql2022: windowed facts return real data (292 wait facts vs 0 before); persisted time_range stays UTC; the analyzer aggregates a NULL-wait row to 0 instead of erroring. Dashboard + Lite build clean; 346 Dashboard.Tests pass. 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.
The bug (server-local window)
AnalysisServicebuilt the analysis window fromDateTime.UtcNow, but every collector stamps rows withSYSDATETIME()(server-local). So all 102 windowed reads (wait/CPU/blocking facts, anomaly detection, every drill-down enrichment) filtered server-local data against a UTC window and silently matched nothing on any non-UTC server — the entire windowed half of the analysis engine was dark there.Proven on sql2022 (UTC−7): the UTC window saw 0 wait-stats and 0 CPU rows; the server-local window saw 11,050 wait rows + 293 CPU rows.
The fix
AnalyzeAsync/CollectAndScoreFactsAsyncprobe the monitored server's clock (SELECT SYSDATETIME(), SYSUTCDATETIME()) and build a server-local window, capturing the UTC offset onAnalysisContext. The 102 windowed reads are unchanged (they consume the context window).SqlServerFindingStoreconverts the window back to UTC for persistence, so storedtime_range_*/analysis_timestay UTC — the reader'sAsUtc, the deep-link offset math, and the retention purge are all unchanged.compare_analysisuses the server clock too. Falls back to host UTC if the probe fails (prior behavior; no new hard-failure mode).Bundled: null-safe
blocking_deadlock_analyzer(install/26)SUM(wait_time_ms)/MAX(...)andSUM(wait_time)feed NOT NULL columns, but those source columns are nullable — a report missing the duration made the aggregate NULL and failed the whole insert (it was failing on sql2022). Wrapped inISNULL(..., 0).Verification
get_analysis_factsnow returns 292 wait facts (vs 0 before); persistedtime_range_end= serverSYSUTCDATETIME(UTC), not server-local.wait_time_msrow to0instead of erroring (deployed + tested on sql2022).🤖 Generated with Claude Code