From fc4371d44eab292a5b6d0a551cab283b6555e16e Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 5 Feb 2024 11:37:19 -0800 Subject: [PATCH 1/4] Filtering the prefix in custom query log for pinot response comparator --- common/persistence/pinotVisibilityTripleManager.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/persistence/pinotVisibilityTripleManager.go b/common/persistence/pinotVisibilityTripleManager.go index 4f536081c4d..538e6dca53b 100644 --- a/common/persistence/pinotVisibilityTripleManager.go +++ b/common/persistence/pinotVisibilityTripleManager.go @@ -24,6 +24,7 @@ import ( "context" "fmt" "math/rand" + "strings" "github.com/uber/cadence/common" "github.com/uber/cadence/common/dynamicconfig" @@ -341,7 +342,12 @@ func (v *pinotVisibilityTripleManager) logUserQueryParameters(userParam userPara tag.WorkflowType(userParam.workflowType), tag.WorkflowID(userParam.workflowID), tag.WorkflowCloseStatus(userParam.closeStatus), - tag.VisibilityQuery(userParam.customQuery)) + tag.VisibilityQuery(filterAttrPrefix(userParam.customQuery))) +} + +func filterAttrPrefix(str string) string { + str = strings.Replace(str, "`Attr.", "", -1) + return strings.Replace(str, "`", "", -1) } func (v *pinotVisibilityTripleManager) ListOpenWorkflowExecutions( From 4e271f1351d64947992ce1b0e8a8d6eb06a8c1ba Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 5 Feb 2024 11:48:22 -0800 Subject: [PATCH 2/4] add a unit test for that --- .../pinotVisibilityTripleManager_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 common/persistence/pinotVisibilityTripleManager_test.go diff --git a/common/persistence/pinotVisibilityTripleManager_test.go b/common/persistence/pinotVisibilityTripleManager_test.go new file mode 100644 index 00000000000..67f3ad69c20 --- /dev/null +++ b/common/persistence/pinotVisibilityTripleManager_test.go @@ -0,0 +1,36 @@ +package persistence + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFilterAttrPrefix(t *testing.T) { + tests := map[string]struct { + expectedInput string + expectedOutput string + }{ + "Case1: empty input": { + expectedInput: "", + expectedOutput: "", + }, + "Case2: filtered input": { + expectedInput: "`Attr.CustomIntField` = 12", + expectedOutput: "CustomIntField = 12", + }, + "Case3: complex input": { + expectedInput: "WorkflowID = 'test-wf' and (`Attr.CustomIntField` = 12 or `Attr.CustomStringField` = 'a-b-c' and WorkflowType = 'wf-type')", + expectedOutput: "WorkflowID = 'test-wf' and (CustomIntField = 12 or CustomStringField = 'a-b-c' and WorkflowType = 'wf-type')", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + assert.NotPanics(t, func() { + actualOutput := filterAttrPrefix(test.expectedInput) + assert.Equal(t, test.expectedOutput, actualOutput) + }) + }) + } +} From c5ebf60c9a18140f50cca7e5cac2199ce30b3caa Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 5 Feb 2024 11:52:10 -0800 Subject: [PATCH 3/4] run copy right stuff --- .../pinotVisibilityTripleManager_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/persistence/pinotVisibilityTripleManager_test.go b/common/persistence/pinotVisibilityTripleManager_test.go index 67f3ad69c20..6dc57c3ee3e 100644 --- a/common/persistence/pinotVisibilityTripleManager_test.go +++ b/common/persistence/pinotVisibilityTripleManager_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-2020 Uber Technologies Inc. + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + package persistence import ( From 1c492f909c9d9e39825bf7522d00750800cbba72 Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 5 Feb 2024 16:27:16 -0800 Subject: [PATCH 4/4] add comment for the new function, and add a false positive test --- common/persistence/pinotVisibilityTripleManager.go | 2 ++ common/persistence/pinotVisibilityTripleManager_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/common/persistence/pinotVisibilityTripleManager.go b/common/persistence/pinotVisibilityTripleManager.go index 538e6dca53b..749cf89ebce 100644 --- a/common/persistence/pinotVisibilityTripleManager.go +++ b/common/persistence/pinotVisibilityTripleManager.go @@ -345,6 +345,8 @@ func (v *pinotVisibilityTripleManager) logUserQueryParameters(userParam userPara tag.VisibilityQuery(filterAttrPrefix(userParam.customQuery))) } +// This is for only logUserQueryParameters (for Pinot Response comparator) usage. +// Be careful because there's a low possibility that there'll be false positive cases (shown in unit tests) func filterAttrPrefix(str string) string { str = strings.Replace(str, "`Attr.", "", -1) return strings.Replace(str, "`", "", -1) diff --git a/common/persistence/pinotVisibilityTripleManager_test.go b/common/persistence/pinotVisibilityTripleManager_test.go index 6dc57c3ee3e..016a04ec405 100644 --- a/common/persistence/pinotVisibilityTripleManager_test.go +++ b/common/persistence/pinotVisibilityTripleManager_test.go @@ -45,6 +45,10 @@ func TestFilterAttrPrefix(t *testing.T) { expectedInput: "WorkflowID = 'test-wf' and (`Attr.CustomIntField` = 12 or `Attr.CustomStringField` = 'a-b-c' and WorkflowType = 'wf-type')", expectedOutput: "WorkflowID = 'test-wf' and (CustomIntField = 12 or CustomStringField = 'a-b-c' and WorkflowType = 'wf-type')", }, + "Case4: false positive case": { + expectedInput: "`Attr.CustomStringField` = '`Attr.ABCtesting'", + expectedOutput: "CustomStringField = 'ABCtesting'", // this is supposed to be CustomStringField = '`Attr.ABCtesting' + }, } for name, test := range tests {