Skip to content

Commit 7f4018f

Browse files
authored
[chore] [receiver/sqlserver] Update performance counter query (#40425)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Update performance counter query to make it compatible with internal obfuscation. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Relevant to #40347 <!--Describe what testing was performed and which tests were added.--> #### Testing Added <!--Describe the documentation added.--> #### Documentation n/a <!--Please delete paragraphs that you did not use before submitting.-->
1 parent bee7e37 commit 7f4018f

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

receiver/sqlserverreceiver/obfuscate_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ func TestObfuscateInvalidSQL(t *testing.T) {
3131

3232
assert.Error(t, err)
3333
assert.Empty(t, result)
34+
35+
sql = "SELECT cpu_time AS [CPU Usage Time]"
36+
expected := "SELECT cpu_time"
37+
result, err = obfuscateSQL(sql)
38+
assert.NoError(t, err)
39+
assert.Equal(t, expected, result)
3440
}
3541

3642
func TestObfuscateQueryPlan(t *testing.T) {

receiver/sqlserverreceiver/queries.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ FROM
226226
,rgwg.total_request_count AS [Request Count]
227227
,rgwg.total_queued_request_count AS [Queued Request Count]
228228
,rgwg.total_cpu_limit_violation_count AS [CPU Limit Violation Count]
229-
,rgwg.total_cpu_usage_ms AS [CPU Usage (time)]
229+
,rgwg.total_cpu_usage_ms AS [CPU Usage Time]
230230
,rgwg.total_lock_wait_count AS [Lock Wait Count]
231231
,rgwg.total_lock_wait_time_ms AS [Lock Wait Time]
232232
,rgwg.total_reduced_memgrant_count AS [Reduced Memory Grant Count]
@@ -236,7 +236,7 @@ FROM
236236
ON rgwg.[pool_id] = rgrp.[pool_id]
237237
) AS rg
238238
UNPIVOT (
239-
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage (time)], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
239+
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage Time], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
240240
) AS vs'
241241
242242
INSERT INTO @PCounters

receiver/sqlserverreceiver/testdata/perfCounterQueryData.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,7 @@
28512851
},
28522852
{
28532853
"computer_name": "abcde",
2854-
"counter": "CPU Usage (time)",
2854+
"counter": "CPU Usage Time",
28552855
"counter_type": "1",
28562856
"instance": "default",
28572857
"measurement": "sqlserver_performance",
@@ -3001,7 +3001,7 @@
30013001
},
30023002
{
30033003
"computer_name": "abcde",
3004-
"counter": "CPU Usage (time)",
3004+
"counter": "CPU Usage Time",
30053005
"counter_type": "1",
30063006
"instance": "internal",
30073007
"measurement": "sqlserver_performance",

receiver/sqlserverreceiver/testdata/perfCounterQueryWithInstanceName.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ FROM
159159
,rgwg.total_request_count AS [Request Count]
160160
,rgwg.total_queued_request_count AS [Queued Request Count]
161161
,rgwg.total_cpu_limit_violation_count AS [CPU Limit Violation Count]
162-
,rgwg.total_cpu_usage_ms AS [CPU Usage (time)]
162+
,rgwg.total_cpu_usage_ms AS [CPU Usage Time]
163163
,rgwg.total_lock_wait_count AS [Lock Wait Count]
164164
,rgwg.total_lock_wait_time_ms AS [Lock Wait Time]
165165
,rgwg.total_reduced_memgrant_count AS [Reduced Memory Grant Count]
@@ -169,7 +169,7 @@ FROM
169169
ON rgwg.[pool_id] = rgrp.[pool_id]
170170
) AS rg
171171
UNPIVOT (
172-
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage (time)], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
172+
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage Time], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
173173
) AS vs'
174174

175175
INSERT INTO @PCounters

receiver/sqlserverreceiver/testdata/perfCounterQueryWithoutInstanceName.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ FROM
159159
,rgwg.total_request_count AS [Request Count]
160160
,rgwg.total_queued_request_count AS [Queued Request Count]
161161
,rgwg.total_cpu_limit_violation_count AS [CPU Limit Violation Count]
162-
,rgwg.total_cpu_usage_ms AS [CPU Usage (time)]
162+
,rgwg.total_cpu_usage_ms AS [CPU Usage Time]
163163
,rgwg.total_lock_wait_count AS [Lock Wait Count]
164164
,rgwg.total_lock_wait_time_ms AS [Lock Wait Time]
165165
,rgwg.total_reduced_memgrant_count AS [Reduced Memory Grant Count]
@@ -169,7 +169,7 @@ FROM
169169
ON rgwg.[pool_id] = rgrp.[pool_id]
170170
) AS rg
171171
UNPIVOT (
172-
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage (time)], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
172+
value FOR counter IN ( [Request Count], [Queued Request Count], [CPU Limit Violation Count], [CPU Usage Time], [Lock Wait Count], [Lock Wait Time], [Reduced Memory Grant Count] ' + @PivotColumns + N')
173173
) AS vs'
174174

175175
INSERT INTO @PCounters

0 commit comments

Comments
 (0)