Skip to content

Commit

Permalink
bump go-sqllexer to v0.0.15 with new KeepJsonPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zhengda committed Sep 30, 2024
1 parent e31532d commit 09c76ae
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 30 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.56.2
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.

39 changes: 39 additions & 0 deletions releasenotes/notes/bump-go-sqllexer-0.0.15-18432a15bec8d683.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
upgrade:
- |
List upgrade notes here, or remove this section.
Upgrade notes should be rare: only list known/potential breaking changes,
or major behaviorial changes that require user action before the upgrade.
Notes here must include steps that users can follow to 1. know if they're
affected and 2. handle the change gracefully on their end.
features:
- |
List new features here, or remove this section.
enhancements:
- |
List enhancements (new behavior that is too small to be
considered a new feature), or remove this section.
issues:
- |
List known issues here, or remove this section.
deprecations:
- |
List deprecations notes here, or remove this section.
security:
- |
Add security notes here, or remove this section.
fixes:
- |
Add normal bug fixes here, or remove this section.
other:
- |
Add here every other information you want in the CHANGELOG that
don't fit in any other section. This section should rarely be
used.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
features:
- |
DBM: Add configuration options to SQL obfuscator to customize the normalization of SQL statements:
- ``KeepTrailingSemicolon`` - disable removing trailing semicolon. This option is only valid when ``ObfuscationMode`` is ``obfuscate_and_normalize``.
- ``KeepIdentifierQuotation`` - disable removing quotation marks around identifiers. This option is only valid when ``ObfuscationMode`` is ``obfuscate_and_normalize``.
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 09c76ae

Please sign in to comment.