Skip to content

feat(dbi): Add SQL Server Database Insights support - #2234

Merged
Klarsen04 merged 19 commits into
feature/dbi-sqlserverfrom
larkirs/dbi-sqlserver
Aug 6, 2026
Merged

feat(dbi): Add SQL Server Database Insights support#2234
Klarsen04 merged 19 commits into
feature/dbi-sqlserverfrom
larkirs/dbi-sqlserver

Conversation

@Klarsen04

Copy link
Copy Markdown

Add complete SQL Server Database Insights implementation with workload detection and application-level session tracking.

Overview

This PR adds SQL Server support to Database Insights, enabling monitoring of SQL Server instances on both Windows and Linux with automatic workload detection.

Key Features

SQL Server Receiver Integration

  • 50+ metrics enabled for comprehensive SQL Server monitoring
  • Performance & resource metrics (blocked processes, deadlocks, memory grants)
  • Page & buffer pool metrics
  • Wait statistics (latch waits, lock waits, lock timeouts)
  • Database I/O and latency metrics
  • Connection & session tracking
  • Index and query performance metrics
  • TempDB metrics

Windows-Specific Support

  • 13 Windows Performance Monitor metrics (automatically disabled on Linux)
  • UTF-16LE decoding for SQL Server ERRORLOG on Windows
  • Named instance port resolution via Windows registry

Application-Level Monitoring

  • Track sessions by sqlserver.application.name attribute
  • sqlserver.active_sessions.by_app connector metric
  • Automatic handling of NULL application names (set to 'unknown')

Workload Detection

  • Automatic SQL Server instance discovery
  • Integration with process discovery system
  • Named instance detection and port resolution

Configuration & Tuning

  • Query sample limits: MaxRowsPerQuery=5000, MaxQuerySampleCount=1000
  • Query plan caching with gzip+base64 compression (always-on)
  • Cache: 1000 plans, TTL: 1 hour, Max size: 900KB
  • Added to combined v1/v2 EC2 and EKS sample configs

Dependencies

  • Updated go.mod to point to sqlserverreceiver with application.name support
  • Updated go.mod for latest mysqlreceiver from dbi-mysql branch

Testing

  • All unit tests passing (connectors, processors, receivers, translators)
  • Pipeline integration tests passing
  • Linux config verified (Windows-only metrics correctly disabled)
  • Windows config verified (all 13 Performance Monitor metrics enabled)
  • Sample YAML configs regenerated and validated

Components Added

  • SQL Server receiver translator (translator/translate/otel/receiver/sqlserver/)
  • SQL Server DBI pipeline configuration
  • SQL Server connector metrics (8 total including by_app)
  • SQL Server transform processors (6 statements)
  • SQL Server workload detector (internal/detector/sqlserver/)
  • Component registration in DBI translator

Klarsen04 added 18 commits July 26, 2026 19:36
- Enable 26 additional metrics for RDS parity (43 counter + 7 DB Load)
- Configure query plan caching (1000 plans, 1hr TTL, 900KB max)
- Enable query sample and top query collection
- Add sample configuration files for Linux
- Platform coverage: Linux 94%, Windows 100%

Metrics include:
- Performance & Resource (4): blocked processes, deadlocks, memory
- Page & Buffer Pool (3): lookups, free list stalls
- Wait Statistics (3): latch waits, lock timeouts
- Transaction & Log (4): active transactions, log metrics
- Database I/O (4): io, latency, operations, Resource Governor queue
- Connection & Workload (3): login/logout rates, session count
- Index & Query (3): index searches, full scans, errors
- TempDB (2): space usage, version store

New metrics:
- sqlserver.database.io.stall_queued (Resource Governor I/O queue wait)
- sqlserver.session.count (sessions by state)
- Fix console detection: set db.system.name in resource attributes
- Fix query sample filter: use false for SQL Server/MySQL
- Add DB Load connector configuration (7 metrics)
- Add Top SQL signal-to-metrics connector
- Add transform processor for start time fix
- Configure full DBI metrics pipeline

DB Load metrics:
- active_sessions.count (total sessions)
- active_sessions.by_wait (by wait type)
- active_sessions.by_user (by username)
- active_sessions.by_db (by database)
- active_sessions.by_sql (by SQL hash)
- active_sessions.by_sql_wait (by SQL + wait)
- active_sessions.by_host (by host)

Fixes:
- Console now detects SQL Server instances correctly
- Query samples flow to CloudWatch Logs
Component Registration:
- Register SQL Server receiver in default components
- Update common component utilities
- Update configuration schema
- Add platform-specific tests

Changes:
- Add sqlserverreceiver to default receiver list
- Update component factory to include SQL Server
- Add SQL Server to configuration validation
- Add test coverage for new components
- Add SQL Server DBI to combined EC2 sample configs
- Add SQL Server DBI to combined EKS sample configs
- Update go.mod/go.sum with SQL Server receiver dependencies
- Use local receiver via replace directive for development

Configuration examples show:
- SQL Server endpoint (localhost:1433)
- Monitoring user credentials (passfile)
- Instance naming
- Integration with other DBI engines (PostgreSQL, MySQL)
SQL Server Detector:
- Detects SQL Server process (sqlservr, sqlservr.exe)
- Extracts port from command line flags (-p) or environment (MSSQL_TCP_PORT)
- Defaults to port 1433
- Supports custom installation paths
- Platform: Linux and Windows

Port Extraction:
- Parses -p flag from command line arguments
- Reads MSSQL_TCP_PORT environment variable
- Command line takes precedence over environment
- Falls back to default port 1433

Detection logic:
- Searches for sqlservr process in ps output
- Excludes sqlcmd (client tool, not server)
- Handles both default and custom SQL Server installations
- Works on Linux and Windows platforms

Files:
- internal/detector/sqlserver/sqlserver.go - Main detector
- internal/detector/sqlserver/extract/port.go - Port extraction logic
- internal/detector/metadata.go - Register SQL Server detector
- Add SQL Server process scraping to hostmetrics pipeline
- Configure sqlservr.* process pattern for SQL Server detection
- Add merge rule tests for SQL Server database_insights config
- Enable process metrics (CPU, memory, threads) for SQL Server instances
…ort for tracking SQL Server sessions by application name, matching PostgreSQL's existing application.name dimension for DBI workload analysis. Changes: - Add sqlserver.active_sessions.by_app connector metric with sqlserver.application.name attribute dimension - Add replace_match transform for sqlserver.application.name to set 'unknown' default for NULL values - Update tests to expect 8 connector metrics (was 7) and 6 transform statements (was 5) - Ensure 13 Windows-only Performance Monitor metrics are correctly disabled on Linux (lock.wait_time.avg, page metrics, transaction metrics, and transaction_log metrics) - Add SQLServerKey constant and DatabaseInsightsSqlServerKey to common package - Integrate SQL Server receiver creation in databaseinsights translator - Update go.mod to point to committed sqlserverreceiver with application.name support (v0.0.0-20260729175257-2c50db1bb14e) - Regenerate all sample YAML configs with new metrics and transforms The application.name attribute enables DBAs to: - Identify which applications are generating database load - Track performance and resource consumption per application - Correlate application behavior with database metrics Testing: - All unit tests passing for connectors, processors, receivers - All pipeline integration tests passing - Linux config verified with Windows-only metrics disabled - Windows config verified with all 13 Performance Monitor metrics enabled
Adjust SQL Server query sample configuration to optimize resource usage:
- Increase MaxRowsPerQuery from 500 to 5000 (aligns with PostgreSQL)
- Decrease MaxQuerySampleCount from 5000 to 1000 (conservative limit)

This balances query plan collection with CloudWatch Logs limits while
maintaining the existing gzip+base64 compression for XML ShowPlan data.
Adjust MySQL query sample configuration to optimize resource usage:
- Increase MaxRowsPerQuery from 500 to 5000 (aligns with PostgreSQL)
- Decrease MaxQuerySampleCount from 5000 to 1000 (conservative limit)

This balances query plan collection with CloudWatch Logs limits.
Merge upstream main branch to incorporate latest changes including:
- GitHub workflow updates
- PostgreSQL detector additions
- Release notes updates

Resolved conflicts in:
- cmd/workload-discovery/discovery.go
- internal/detector/metadata.go
…registry

On Windows, SQL Server named instances store their TCP port in the
registry rather than passing it via command-line flags. The workload
discovery tool was falling back to the default port 1433 for all
instances, causing incorrect port reporting for named instances.

Add a Windows-specific registry port extractor that:
1. Extracts the instance name from the process command line (-s flag)
2. Resolves the instance name to its registry ID via Instance Names\SQL
3. Reads the TCP port from SuperSocketNetLib\Tcp\IPAll (static or dynamic)

The extractor chain on Windows is now: registry -> cmdline -> env -> default.
On Linux/other platforms, behavior is unchanged: cmdline -> env -> default.
Windows SQL Server writes its ERRORLOG in UTF-16LE encoding, causing
server log entries to appear as garbled null-interleaved text in
CloudWatch Logs (e.g. 'S\u0000t\u0000a\u0000r\u0000t\u0000i\u0000n\u0000g').

Add a runtime.GOOS check to set the filelog receiver encoding to
'utf-16le' when running on Windows. On Linux, SQL Server writes
ERRORLOG in UTF-8, so no encoding override is needed.

Verified on both instances:
- Windows (i-01992cda09d257426): server logs now appear as readable text
- Linux (i-0c4670d5ab711c0dd): server logs already UTF-8, no issue
…386b)

Update go.mod to point to the latest commit on the upstream dbi-mysql branch which includes PR #617 (InnoDB deadlocks and transaction metrics).
Update mysqlreceiver to latest dbi-mysql branch commit
@Klarsen04
Klarsen04 requested a review from a team as a code owner August 6, 2026 13:36
@Klarsen04
Klarsen04 merged commit f9a6dc9 into feature/dbi-sqlserver Aug 6, 2026
13 of 16 checks passed
@Klarsen04
Klarsen04 deleted the larkirs/dbi-sqlserver branch August 6, 2026 13:37
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.

1 participant