Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Description

Implements a periodic background task that queries SQL Server Query Store and logs top queries by total execution time with index usage information.

Implementation

  • SqlQueryStoreWatchdog: Extends Watchdog<T> pattern, runs hourly by default
  • Query extraction: Aggregates runtime stats from last 24 hours, extracts top N queries by avg_duration × count_executions
  • Index parsing: XQuery on execution plans to extract IndexScan/IndexSeek operations
  • Metrics logged (JSON): query_id, plan_id, sql_text, duration_ms, cpu_time_ms, io_reads, execution_count, indexes_used

Configuration

Parameters table controls behavior:

  • SqlQueryStore.IsEnabled (default: 1)
  • SqlQueryStore.TopQueriesCount (default: 50)

Integration

  • Registered in WatchdogsBackgroundService alongside existing watchdogs
  • DI container registration as singleton
  • Lease-based execution for multi-instance deployments

Related issues

Addresses requested feature for SQL query performance monitoring.

Testing

Unit tests validate parameter initialization and default values.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Enhancement
  • Tag the PR with Azure Healthcare APIs (SQL or common code)
  • Tag the PR with Schema Version unchanged
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Feature

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • microsofthealthoss.pkgs.visualstudio.com
    • Triggering command: dotnet build Microsoft.Health.Fhir.sln --configuration Release -v minimal (dns block)
    • Triggering command: dotnet build src/Microsoft.Health.Fhir.SqlServer/Microsoft.Health.Fhir.SqlServer.csproj --configuration Release -v minimal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Add periodic task to look at sql query store and extract sql queries and used in them indexes, and log this info in the FHIR server log.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 11, 2025 22:12
Co-authored-by: SergeyGaluzo <95932081+SergeyGaluzo@users.noreply.github.com>
Co-authored-by: SergeyGaluzo <95932081+SergeyGaluzo@users.noreply.github.com>
Copilot AI changed the title [WIP] Add periodic task to log SQL queries and indexes Add SQL Query Store watchdog for periodic query performance logging Nov 11, 2025
Copilot AI requested a review from SergeyGaluzo November 11, 2025 22:17
Copy link
Contributor

@SergeyGaluzo SergeyGaluzo left a comment

Choose a reason for hiding this comment

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

  1. Reduce aggregate interval from 24 hours to 1.
  2. Remove TOP restriction from query against query store.
  3. Add filter '%cte%' for the queries from query store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants