Skip to content

Commit

Permalink
Filtering the prefix in custom query log for pinot response comparator (
Browse files Browse the repository at this point in the history
#5643)

* Filtering the  prefix in custom query log for pinot response comparator

* add a unit test for that

* run copy right stuff

* add comment for the new function, and add a false positive test
  • Loading branch information
bowenxia authored Feb 6, 2024
1 parent 21dc9e9 commit 83d55c7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/persistence/pinotVisibilityTripleManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"fmt"
"math/rand"
"strings"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/dynamicconfig"
Expand Down Expand Up @@ -341,7 +342,14 @@ 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)))
}

// 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)
}

func (v *pinotVisibilityTripleManager) ListOpenWorkflowExecutions(
Expand Down
62 changes: 62 additions & 0 deletions common/persistence/pinotVisibilityTripleManager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 (
"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')",
},
"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 {
t.Run(name, func(t *testing.T) {
assert.NotPanics(t, func() {
actualOutput := filterAttrPrefix(test.expectedInput)
assert.Equal(t, test.expectedOutput, actualOutput)
})
})
}
}

0 comments on commit 83d55c7

Please sign in to comment.