Skip to content

Commit dee7e39

Browse files
sincejunecrobert-1
andauthored
[receiver/sqlserver] reports empty strings for query texts and query … (#40527)
…plans when obfuscation failed <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This ensures the protection of customer privacy data in cases where obfuscation fails. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue n/a <!--Describe what testing was performed and which tests were added.--> #### Testing Updated <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Curtis Robert <[email protected]>
1 parent e687c62 commit dee7e39

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sqlserverreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Only empty strings for query texts and query plans when obfuscation failed.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40527]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This change applies only to top query collection and query sample collection.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/sqlserverreceiver/obfuscate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func obfuscateXMLPlan(rawPlan string) (string, error) {
7676
val, err := obfuscateSQL(elem.Attr[i].Value)
7777
if err != nil {
7878
fmt.Println("Unable to obfuscate SQL statement in query plan, skipping: " + elem.Attr[i].Value)
79-
continue
79+
return "", nil
8080
}
8181
elem.Attr[i].Value = val
8282
}

receiver/sqlserverreceiver/obfuscate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ func TestInvalidQueryPlans(t *testing.T) {
6868
assert.Empty(t, result)
6969
assert.Error(t, err)
7070

71-
// obfuscate failure, but no error
71+
// obfuscate failure, return empty string
7272
plan = `<ShowPlanXML StatementText="[msdb].[dbo].[sysjobhistory].[run_duration] as [sjh].[run_duration]/(10000)*(3600)+[msdb].[dbo].[sysjobhistory].[run_duration] as [sjh].[run_duration]%(10000)/(100)*(60)+[msdb].[dbo].[sysjobhistory].[run_duration] as [sjh].[run_duration]%(100)"></ShowPlanXML>`
7373
result, err = obfuscateXMLPlan(plan)
74-
assert.Equal(t, plan, result)
74+
assert.Empty(t, result)
7575
assert.NoError(t, err)
7676
}
7777

receiver/sqlserverreceiver/scraper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
676676
obfuscated, err := obfuscateSQL(statement)
677677
if err != nil {
678678
s.logger.Error(fmt.Sprintf("failed to obfuscate SQL statement: %v", statement))
679-
return statement, nil
679+
return "", nil
680680
}
681681

682682
return obfuscated, nil
@@ -972,7 +972,7 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
972972
obfuscated, err := obfuscateSQL(statement)
973973
if err != nil {
974974
s.logger.Error(fmt.Sprintf("failed to obfuscate SQL statement: %v", statement))
975-
return statement, nil
975+
return "", nil
976976
}
977977
return obfuscated, nil
978978
}).(string)

receiver/sqlserverreceiver/testdata/expectedQueryTextAndPlanQueryWithInvalidData.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resourceLogs:
1818
doubleValue: 0
1919
- key: db.query.text
2020
value:
21-
stringValue: SELECT cpu_time AS [CPU Usage (time)]
21+
stringValue: ""
2222
- key: sqlserver.execution_count
2323
value:
2424
intValue: "0"

receiver/sqlserverreceiver/testdata/expectedRecordDatabaseSampleQueryWithInvalidData.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resourceLogs:
2424
stringValue: master
2525
- key: db.query.text
2626
value:
27-
stringValue: SELECT cpu_time AS [CPU Usage (time)]
27+
stringValue: ""
2828
- key: db.system.name
2929
value:
3030
stringValue: microsoft.sql_server

0 commit comments

Comments
 (0)