Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering the prefix in custom query log for pinot response comparator #5643

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 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,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can unintentionally replace value part in the query. correct way to do this would be to parse the whole query with regex capture groups or AST and then perform the sanitization. however this is probably a super edge case so don't block yourself on this but keep the current behavior caveat documented in the code and also add an example false positive test case to demonstrate it

Copy link
Contributor Author

@bowenxia bowenxia Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment and false positive unit test added.

return strings.Replace(str, "`", "", -1)
}

func (v *pinotVisibilityTripleManager) ListOpenWorkflowExecutions(
Expand Down
58 changes: 58 additions & 0 deletions common/persistence/pinotVisibilityTripleManager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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')",
},
}

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