-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database_type config to Split up sql queries by engine type #7934
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1759750
split functionality by database engine type
denzilribeiro 749a6b2
Split out SQL Managed instance queries
denzilribeiro 2bfa6b2
Adding database_type SQLServer
denzilribeiro 31acde7
Updating tests
denzilribeiro a435ecb
Reverting test file changes
denzilribeiro 9f71952
V2 Queries split and deprecation notice
denzilribeiro 2dbdcc5
Changed requests to include blocking sessions
denzilribeiro 9c9c085
Added New counter - Lock Timeouts (timeout>0)/sec
denzilribeiro 2aa2036
Fixing unintentional syntax bug with AzureDBServerProperties
denzilribeiro 93a2751
Split on-prem SQL Server queries
denzilribeiro ba1b40c
Adding SQL Server On-prem queries file
denzilribeiro e6be374
Reverting to request database ID for SQL 2008/R2 compat
denzilribeiro 19ede7c
Change to dynamic sql for 2008/R2 compat
denzilribeiro c3b0da8
Changing SqlRequests collector for 2008/R2 compatibility
denzilribeiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1016,15 +1016,29 @@ IF SERVERPROPERTY('EngineEdition') IN (2,3,4) /*Standard,Enterpris,Express*/ | |
` | ||
|
||
const sqlServerRequests string = ` | ||
SET NOCOUNT ON; | ||
SET NOCOUNT ON; | ||
DECLARE | ||
@SqlStatement AS nvarchar(max) | ||
,@EngineEdition AS tinyint = CAST(SERVERPROPERTY('EngineEdition') AS int) | ||
,@MajorMinorVersion AS int = CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') as nvarchar),4) AS int) * 100 + CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion') as nvarchar),3) AS int) | ||
|
||
-- 2008R2 and before doesn't have open_transaction_count in sys.dm_exec_sessions | ||
DECLARE @Columns as nvarchar(max) = '' | ||
IF @MajorMinorVersion >= 1200 | ||
SET @Columns = ',s.open_transaction_count as open_transaction ' | ||
ELSE | ||
SET @Columns = ',r.open_transaction_count as open_transaction' | ||
|
||
SET @SqlStatement = N' | ||
SELECT blocking_session_id into #blockingSessions FROM sys.dm_exec_requests WHERE blocking_session_id != 0 | ||
create index ix_blockingSessions_1 on #blockingSessions (blocking_session_id) | ||
SELECT | ||
'sqlserver_requests' AS [measurement] | ||
, REPLACE(@@SERVERNAME,'\',':') AS [sql_instance] | ||
SELECT | ||
''sqlserver_requests'' AS [measurement] | ||
, REPLACE(@@SERVERNAME,''\'','':'') AS [sql_instance] | ||
, DB_NAME() as [database_name] | ||
, s.session_id | ||
, ISNULL(r.request_id,0) as request_id | ||
, DB_NAME(r.database_id) as session_db_name | ||
, DB_NAME(s.database_id) as session_db_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 2008 and 2008R2 compatibility get col from dm_exec_requests , DB_NAME(r.database_id) as session_db_name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do, this was a change I picked up from 45a83b9 and can revert it. |
||
, COALESCE(r.status,s.status) AS status | ||
, COALESCE(r.cpu_time,s.cpu_time) AS cpu_time_ms | ||
, COALESCE(r.total_elapsed_time,s.total_elapsed_time) AS total_elapsed_time_ms | ||
|
@@ -1037,16 +1051,16 @@ SELECT | |
, r.blocking_session_id | ||
, s.program_name | ||
, s.host_name | ||
, s.nt_user_name | ||
, s.open_transaction_count AS open_transaction | ||
, LEFT (CASE COALESCE(r.transaction_isolation_level, s.transaction_isolation_level) | ||
WHEN 0 THEN '0-Read Committed' | ||
WHEN 1 THEN '1-Read Uncommitted (NOLOCK)' | ||
WHEN 2 THEN '2-Read Committed' | ||
WHEN 3 THEN '3-Repeatable Read' | ||
WHEN 4 THEN '4-Serializable' | ||
WHEN 5 THEN '5-Snapshot' | ||
ELSE CONVERT (varchar(30), r.transaction_isolation_level) + '-UNKNOWN' | ||
, s.nt_user_name ' | ||
+ @Columns + | ||
N', LEFT (CASE COALESCE(r.transaction_isolation_level, s.transaction_isolation_level) | ||
WHEN 0 THEN ''0-Read Committed'' | ||
WHEN 1 THEN ''1-Read Uncommitted (NOLOCK)'' | ||
WHEN 2 THEN ''2-Read Committed'' | ||
WHEN 3 THEN ''3-Repeatable Read'' | ||
WHEN 4 THEN ''4-Serializable'' | ||
WHEN 5 THEN ''5-Snapshot'' | ||
ELSE CONVERT (varchar(30), r.transaction_isolation_level) + ''-UNKNOWN'' | ||
END, 30) AS transaction_isolation_level | ||
, r.granted_query_memory as granted_query_memory_pages | ||
, r.percent_complete | ||
|
@@ -1059,7 +1073,7 @@ SELECT | |
END - r.statement_start_offset) / 2 + 1 | ||
) AS statement_text | ||
, qt.objectid | ||
, QUOTENAME(OBJECT_SCHEMA_NAME(qt.objectid,qt.dbid)) + '.' + QUOTENAME(OBJECT_NAME(qt.objectid,qt.dbid)) as stmt_object_name | ||
, QUOTENAME(OBJECT_SCHEMA_NAME(qt.objectid,qt.dbid)) + ''.'' + QUOTENAME(OBJECT_NAME(qt.objectid,qt.dbid)) as stmt_object_name | ||
, DB_NAME(qt.dbid) stmt_db_name | ||
, CONVERT(varchar(20),[query_hash],1) as [query_hash] | ||
, CONVERT(varchar(20),[query_plan_hash],1) as [query_plan_hash] | ||
|
@@ -1068,9 +1082,12 @@ LEFT OUTER JOIN sys.dm_exec_requests AS r | |
ON s.session_id = r.session_id | ||
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) AS qt | ||
WHERE 1 = 1 | ||
AND (r.session_id IS NOT NULL AND (s.is_user_process = 1 OR r.status COLLATE Latin1_General_BIN NOT IN ('background', 'sleeping'))) | ||
AND (r.session_id IS NOT NULL AND (s.is_user_process = 1 | ||
OR r.status COLLATE Latin1_General_BIN NOT IN (''background'', ''sleeping''))) | ||
OR (s.session_id IN (SELECT blocking_session_id FROM #blockingSessions)) | ||
OPTION(MAXDOP 1) | ||
OPTION(MAXDOP 1)' | ||
|
||
EXEC sp_executesql @SqlStatement | ||
` | ||
|
||
const sqlServerVolumeSpace string = ` | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.database_id is not available in SQL 2008 and R2, it should be r.database_id
But since this is dynamic SQL now you can just pass it in the column parameter
after this the PR is approved to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang it sorry moving target should install a 2008/R2 instance at some point. should be done now.