Skip to content

Commit

Permalink
[dbm] bump go-sqllexer to v0.0.15 with new KeepJsonPath option (#29655)
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zhengda authored and wdhif committed Oct 2, 2024
1 parent 33fa5d4 commit 81296d0
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 27 deletions.
2 changes: 1 addition & 1 deletion comp/otelcol/ddflareextension/impl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ require (
github.com/DataDog/datadog-api-client-go/v2 v2.26.0 // indirect
github.com/DataDog/datadog-go/v5 v5.5.0 // indirect
github.com/DataDog/dd-sensitive-data-scanner/sds-go/go v0.0.0-20240816154533-f7f9beb53a42 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/mmh3 v0.0.0-20210722141835-012dc69a9e49 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.20.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/ddflareextension/impl/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ require (
github.com/DataDog/datadog-agent/pkg/version v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-api-client-go/v2 v2.26.0 // indirect
github.com/DataDog/dd-sensitive-data-scanner/sds-go/go v0.0.0-20240816154533-f7f9beb53a42 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/mmh3 v0.0.0-20210722141835-012dc69a9e49 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.20.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/otlp/components/exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion comp/otelcol/otlp/components/statsprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/pointer v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/otlp/components/statsprocessor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/winutil v0.57.0
github.com/DataDog/datadog-agent/pkg/version v0.57.0
github.com/DataDog/go-libddwaf/v3 v3.3.0
github.com/DataDog/go-sqllexer v0.0.14
github.com/DataDog/go-sqllexer v0.0.15
github.com/Datadog/dublin-traceroute v0.0.1
github.com/aquasecurity/trivy v0.49.2-0.20240227072422-e1ea02c7b80d
github.com/aws/aws-sdk-go-v2/service/kms v1.34.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/collector/python/datadog_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ type sqlConfig struct {
// By default, identifier quotation is removed during normalization.
// This option is only valid when ObfuscationMode is "normalize_only" or "obfuscate_and_normalize".
KeepIdentifierQuotation bool `json:"keep_identifier_quotation"`

// KeepJSONPath specifies whether to keep JSON paths following JSON operators in SQL statements in obfuscation.
// By default, JSON paths are treated as literals and are obfuscated to ?, e.g. "data::jsonb -> 'name'" -> "data::jsonb -> ?".
// This option is only valid when ObfuscationMode is "normalize_only" or "obfuscate_and_normalize".
KeepJSONPath bool `json:"keep_json_path" yaml:"keep_json_path"`
}

// ObfuscateSQL obfuscates & normalizes the provided SQL query, writing the error into errResult if the operation
Expand Down Expand Up @@ -354,6 +359,7 @@ func ObfuscateSQL(rawQuery, opts *C.char, errResult **C.char) *C.char {
KeepPositionalParameter: sqlOpts.KeepPositionalParameter,
KeepTrailingSemicolon: sqlOpts.KeepTrailingSemicolon,
KeepIdentifierQuotation: sqlOpts.KeepIdentifierQuotation,
KeepJSONPath: sqlOpts.KeepJSONPath,
})
if err != nil {
// memory will be freed by caller
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/remote/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/cache v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-go/v5 v5.5.0 // indirect
github.com/DataDog/go-libddwaf/v3 v3.3.0 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/sketches-go v1.4.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/remote/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/obfuscate/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/DataDog/datadog-go/v5 v5.5.0
github.com/DataDog/go-sqllexer v0.0.14
github.com/DataDog/go-sqllexer v0.0.15
github.com/outcaste-io/ristretto v0.2.1
github.com/stretchr/testify v1.9.0
go.uber.org/atomic v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions pkg/obfuscate/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/obfuscate/obfuscate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ type SQLConfig struct {
// This option is only valid when ObfuscationMode is "normalize_only" or "obfuscate_and_normalize".
KeepIdentifierQuotation bool `json:"keep_identifier_quotation" yaml:"keep_identifier_quotation"`

// KeepJSONPath specifies whether to keep JSON paths following JSON operators in SQL statements in obfuscation.
// By default, JSON paths are treated as literals and are obfuscated to ?, e.g. "data::jsonb -> 'name'" -> "data::jsonb -> ?".
// This option is only valid when ObfuscationMode is "normalize_only" or "obfuscate_and_normalize".
KeepJSONPath bool `json:"keep_json_path" yaml:"keep_json_path"`

// Cache reports whether the obfuscator should use a LRU look-up cache for SQL obfuscations.
Cache bool
}
Expand Down
1 change: 1 addition & 0 deletions pkg/obfuscate/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func (o *Obfuscator) ObfuscateWithSQLLexer(in string, opts *SQLConfig) (*Obfusca
sqllexer.WithReplacePositionalParameter(!opts.KeepPositionalParameter),
sqllexer.WithReplaceBoolean(!opts.KeepBoolean),
sqllexer.WithReplaceNull(!opts.KeepNull),
sqllexer.WithKeepJsonPath(opts.KeepJSONPath),
)
}

Expand Down
46 changes: 46 additions & 0 deletions pkg/obfuscate/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,7 @@ func TestSQLLexerObfuscationAndNormalization(t *testing.T) {
keepPositionalParameter bool
keepTrailingSemicolon bool
keepIdentifierQuotation bool
KeepJSONPath bool
metadata SQLMetadata
}{
{
Expand Down Expand Up @@ -2417,6 +2418,50 @@ func TestSQLLexerObfuscationAndNormalization(t *testing.T) {
Procedures: []string{},
},
},
{
name: "select with json path not keep",
query: "SELECT * FROM users WHERE id = 1 AND name->'first' = 'test'",
expected: "SELECT * FROM users WHERE id = ? AND name -> ? = ?",
metadata: SQLMetadata{
Size: 11,
TablesCSV: "users",
Commands: []string{
"SELECT",
},
Comments: []string{},
Procedures: []string{},
},
},
{
name: "select with json path ->",
query: "SELECT * FROM users WHERE id = 1 AND name->'first' = 'test'",
expected: "SELECT * FROM users WHERE id = ? AND name -> 'first' = ?",
KeepJSONPath: true,
metadata: SQLMetadata{
Size: 11,
TablesCSV: "users",
Commands: []string{
"SELECT",
},
Comments: []string{},
Procedures: []string{},
},
},
{
name: "select with json path ->>",
query: "SELECT * FROM users WHERE id = 1 AND name->>2 = 'test'",
expected: "SELECT * FROM users WHERE id = ? AND name ->> 2 = ?",
KeepJSONPath: true,
metadata: SQLMetadata{
Size: 11,
TablesCSV: "users",
Commands: []string{
"SELECT",
},
Comments: []string{},
Procedures: []string{},
},
},
}

for _, tt := range tests {
Expand All @@ -2437,6 +2482,7 @@ func TestSQLLexerObfuscationAndNormalization(t *testing.T) {
RemoveSpaceBetweenParentheses: tt.removeSpaceBetweenParentheses,
KeepTrailingSemicolon: tt.keepTrailingSemicolon,
KeepIdentifierQuotation: tt.keepIdentifierQuotation,
KeepJSONPath: tt.KeepJSONPath,
},
}).ObfuscateSQLString(tt.query)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/trace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
)

require (
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/trace/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/trace/stats/oteltest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/pointer v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/trace/stats/oteltest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
DBM: Add configuration options to SQL obfuscator to customize the obfuscation of SQL statements:
- ``KeepJSONPath`` - option to control whether JSON paths following JSON operators in SQL statements should be obfuscated. This option is only valid when ``ObfuscationMode`` is ``obfuscate_and_normalize``.
2 changes: 1 addition & 1 deletion test/otel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ require (
github.com/DataDog/datadog-api-client-go/v2 v2.26.0 // indirect
github.com/DataDog/datadog-go/v5 v5.5.0 // indirect
github.com/DataDog/dd-sensitive-data-scanner/sds-go/go v0.0.0-20240816154533-f7f9beb53a42 // indirect
github.com/DataDog/go-sqllexer v0.0.14 // indirect
github.com/DataDog/go-sqllexer v0.0.15 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/mmh3 v0.0.0-20210722141835-012dc69a9e49 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.20.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions test/otel/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 81296d0

Please sign in to comment.