Skip to content

Commit 9d3fede

Browse files
authored
Add index name to constructor of search attribute validator (#3834)
1 parent c52848e commit 9d3fede

9 files changed

+46
-39
lines changed

common/searchattribute/validator.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type (
4343
searchAttributesNumberOfKeysLimit dynamicconfig.IntPropertyFnWithNamespaceFilter
4444
searchAttributesSizeOfValueLimit dynamicconfig.IntPropertyFnWithNamespaceFilter
4545
searchAttributesTotalSizeLimit dynamicconfig.IntPropertyFnWithNamespaceFilter
46+
indexName string
4647
}
4748
)
4849

@@ -53,19 +54,21 @@ func NewValidator(
5354
searchAttributesNumberOfKeysLimit dynamicconfig.IntPropertyFnWithNamespaceFilter,
5455
searchAttributesSizeOfValueLimit dynamicconfig.IntPropertyFnWithNamespaceFilter,
5556
searchAttributesTotalSizeLimit dynamicconfig.IntPropertyFnWithNamespaceFilter,
57+
indexName string,
5658
) *Validator {
5759
return &Validator{
5860
searchAttributesProvider: searchAttributesProvider,
5961
searchAttributesMapper: searchAttributesMapper,
6062
searchAttributesNumberOfKeysLimit: searchAttributesNumberOfKeysLimit,
6163
searchAttributesSizeOfValueLimit: searchAttributesSizeOfValueLimit,
6264
searchAttributesTotalSizeLimit: searchAttributesTotalSizeLimit,
65+
indexName: indexName,
6366
}
6467
}
6568

6669
// Validate search attributes are valid for writing.
6770
// The search attributes must be unaliased before calling validation.
68-
func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namespace string, indexName string) error {
71+
func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namespace string) error {
6972
if searchAttributes == nil {
7073
return nil
7174
}
@@ -81,7 +84,7 @@ func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namesp
8184
)
8285
}
8386

84-
saTypeMap, err := v.searchAttributesProvider.GetSearchAttributes(indexName, false)
87+
saTypeMap, err := v.searchAttributesProvider.GetSearchAttributes(v.indexName, false)
8588
if err != nil {
8689
return serviceerror.NewInvalidArgument(
8790
fmt.Sprintf("unable to get search attributes from cluster metadata: %v", err),

common/searchattribute/validator_test.go

+25-17
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate() {
5353
nil,
5454
dynamicconfig.GetIntPropertyFilteredByNamespace(numOfKeysLimit),
5555
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfValueLimit),
56-
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit))
56+
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit),
57+
"",
58+
)
5759

5860
namespace := "namespace"
5961
var attr *commonpb.SearchAttributes
6062

61-
err := saValidator.Validate(attr, namespace, "")
63+
err := saValidator.Validate(attr, namespace)
6264
s.NoError(err)
6365

6466
intPayload, err := payload.Encode(1)
@@ -69,7 +71,7 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate() {
6971
attr = &commonpb.SearchAttributes{
7072
IndexedFields: fields,
7173
}
72-
err = saValidator.Validate(attr, namespace, "")
74+
err = saValidator.Validate(attr, namespace)
7375
s.NoError(err)
7476

7577
fields = map[string]*commonpb.Payload{
@@ -78,15 +80,15 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate() {
7880
"CustomBoolField": payload.EncodeString("true"),
7981
}
8082
attr.IndexedFields = fields
81-
err = saValidator.Validate(attr, namespace, "")
83+
err = saValidator.Validate(attr, namespace)
8284
s.Error(err)
8385
s.Equal("number of search attributes 3 exceeds limit 2", err.Error())
8486

8587
fields = map[string]*commonpb.Payload{
8688
"InvalidKey": payload.EncodeString("1"),
8789
}
8890
attr.IndexedFields = fields
89-
err = saValidator.Validate(attr, namespace, "")
91+
err = saValidator.Validate(attr, namespace)
9092
s.Error(err)
9193
s.Equal("search attribute InvalidKey is not defined", err.Error())
9294

@@ -95,7 +97,7 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate() {
9597
"CustomBoolField": payload.EncodeString("123"),
9698
}
9799
attr.IndexedFields = fields
98-
err = saValidator.Validate(attr, namespace, "")
100+
err = saValidator.Validate(attr, namespace)
99101
s.Error(err)
100102
s.Equal("invalid value for search attribute CustomBoolField of type Bool: 123", err.Error())
101103

@@ -105,14 +107,14 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate() {
105107
"CustomIntField": intArrayPayload,
106108
}
107109
attr.IndexedFields = fields
108-
err = saValidator.Validate(attr, namespace, "")
110+
err = saValidator.Validate(attr, namespace)
109111
s.NoError(err)
110112

111113
fields = map[string]*commonpb.Payload{
112114
"StartTime": intPayload,
113115
}
114116
attr.IndexedFields = fields
115-
err = saValidator.Validate(attr, namespace, "")
117+
err = saValidator.Validate(attr, namespace)
116118
s.Error(err)
117119
s.Equal("StartTime attribute can't be set in SearchAttributes", err.Error())
118120
}
@@ -127,12 +129,14 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate_Mapper() {
127129
&TestMapper{},
128130
dynamicconfig.GetIntPropertyFilteredByNamespace(numOfKeysLimit),
129131
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfValueLimit),
130-
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit))
132+
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit),
133+
"",
134+
)
131135

132136
namespace := "test-namespace"
133137
var attr *commonpb.SearchAttributes
134138

135-
err := saValidator.Validate(attr, namespace, "")
139+
err := saValidator.Validate(attr, namespace)
136140
s.Nil(err)
137141

138142
intPayload, err := payload.Encode(1)
@@ -143,7 +147,7 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate_Mapper() {
143147
attr = &commonpb.SearchAttributes{
144148
IndexedFields: fields,
145149
}
146-
err = saValidator.Validate(attr, namespace, "")
150+
err = saValidator.Validate(attr, namespace)
147151
s.NoError(err)
148152

149153
fields = map[string]*commonpb.Payload{
@@ -152,18 +156,18 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate_Mapper() {
152156
attr = &commonpb.SearchAttributes{
153157
IndexedFields: fields,
154158
}
155-
err = saValidator.Validate(attr, "test-namespace", "")
159+
err = saValidator.Validate(attr, "test-namespace")
156160
s.NoError(err)
157161

158162
fields = map[string]*commonpb.Payload{
159163
"InvalidKey": payload.EncodeString("1"),
160164
}
161165
attr.IndexedFields = fields
162-
err = saValidator.Validate(attr, namespace, "")
166+
err = saValidator.Validate(attr, namespace)
163167
s.Error(err)
164168
s.Equal("search attribute alias_of_InvalidKey is not defined", err.Error())
165169

166-
err = saValidator.Validate(attr, "error-namespace", "")
170+
err = saValidator.Validate(attr, "error-namespace")
167171
s.Error(err)
168172
s.EqualError(err, "mapper error")
169173

@@ -172,7 +176,7 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidate_Mapper() {
172176
"CustomBoolField": payload.EncodeString("123"),
173177
}
174178
attr.IndexedFields = fields
175-
err = saValidator.Validate(attr, namespace, "")
179+
err = saValidator.Validate(attr, namespace)
176180
s.Error(err)
177181
s.Equal("invalid value for search attribute alias_of_CustomBoolField of type Bool: 123", err.Error())
178182
}
@@ -187,7 +191,9 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidateSize() {
187191
nil,
188192
dynamicconfig.GetIntPropertyFilteredByNamespace(numOfKeysLimit),
189193
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfValueLimit),
190-
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit))
194+
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit),
195+
"",
196+
)
191197

192198
namespace := "namespace"
193199

@@ -223,7 +229,9 @@ func (s *searchAttributesValidatorSuite) TestSearchAttributesValidateSize_Mapper
223229
&TestMapper{},
224230
dynamicconfig.GetIntPropertyFilteredByNamespace(numOfKeysLimit),
225231
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfValueLimit),
226-
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit))
232+
dynamicconfig.GetIntPropertyFilteredByNamespace(sizeOfTotalLimit),
233+
"",
234+
)
227235

228236
namespace := "test-namespace"
229237

service/frontend/workflow_handler.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func NewWorkflowHandler(
181181
saMapper,
182182
config.SearchAttributesNumberOfKeysLimit,
183183
config.SearchAttributesSizeOfValueLimit,
184-
config.SearchAttributesTotalSizeLimit),
184+
config.SearchAttributesTotalSizeLimit,
185+
config.ESIndexName,
186+
),
185187
archivalMetadata: archivalMetadata,
186188
healthServer: healthServer,
187189
overrides: NewOverrides(),
@@ -4271,7 +4273,7 @@ func (wh *WorkflowHandler) processOutgoingSearchAttributes(events []*historypb.H
42714273
}
42724274

42734275
func (wh *WorkflowHandler) validateSearchAttributes(searchAttributes *commonpb.SearchAttributes, namespaceName namespace.Name) error {
4274-
if err := wh.saValidator.Validate(searchAttributes, namespaceName.String(), wh.config.ESIndexName); err != nil {
4276+
if err := wh.saValidator.Validate(searchAttributes, namespaceName.String()); err != nil {
42754277
return err
42764278
}
42774279
if err := wh.saValidator.ValidateSize(searchAttributes, namespaceName.String()); err != nil {

service/history/commandChecker.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ func (v *commandAttrValidator) validateSignalExternalWorkflowExecutionAttributes
550550
func (v *commandAttrValidator) validateUpsertWorkflowSearchAttributes(
551551
namespace namespace.Name,
552552
attributes *commandpb.UpsertWorkflowSearchAttributesCommandAttributes,
553-
visibilityIndexName string,
554553
) (enumspb.WorkflowTaskFailedCause, error) {
555554

556555
const failedCause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES
@@ -563,7 +562,7 @@ func (v *commandAttrValidator) validateUpsertWorkflowSearchAttributes(
563562
if len(attributes.GetSearchAttributes().GetIndexedFields()) == 0 {
564563
return failedCause, serviceerror.NewInvalidArgument("IndexedFields is empty on command.")
565564
}
566-
if err := v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), namespace.String(), visibilityIndexName); err != nil {
565+
if err := v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), namespace.String()); err != nil {
567566
return failedCause, err
568567
}
569568

@@ -600,7 +599,6 @@ func (v *commandAttrValidator) validateContinueAsNewWorkflowExecutionAttributes(
600599
namespace namespace.Name,
601600
attributes *commandpb.ContinueAsNewWorkflowExecutionCommandAttributes,
602601
executionInfo *persistencespb.WorkflowExecutionInfo,
603-
visibilityIndexName string,
604602
) (enumspb.WorkflowTaskFailedCause, error) {
605603

606604
const failedCause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_CONTINUE_AS_NEW_ATTRIBUTES
@@ -664,7 +662,7 @@ func (v *commandAttrValidator) validateContinueAsNewWorkflowExecutionAttributes(
664662
return failedCause, err
665663
}
666664

667-
if err = v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), namespace.String(), visibilityIndexName); err != nil {
665+
if err = v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), namespace.String()); err != nil {
668666
return enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, err
669667
}
670668

@@ -678,7 +676,6 @@ func (v *commandAttrValidator) validateStartChildExecutionAttributes(
678676
attributes *commandpb.StartChildWorkflowExecutionCommandAttributes,
679677
parentInfo *persistencespb.WorkflowExecutionInfo,
680678
defaultWorkflowTaskTimeoutFn dynamicconfig.DurationPropertyFnWithNamespaceFilter,
681-
visibilityIndexName string,
682679
) (enumspb.WorkflowTaskFailedCause, error) {
683680

684681
const failedCause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_START_CHILD_EXECUTION_ATTRIBUTES
@@ -733,7 +730,7 @@ func (v *commandAttrValidator) validateStartChildExecutionAttributes(
733730
return failedCause, err
734731
}
735732

736-
if err := v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), targetNamespace.String(), visibilityIndexName); err != nil {
733+
if err := v.searchAttributesValidator.Validate(attributes.GetSearchAttributes(), targetNamespace.String()); err != nil {
737734
return enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, err
738735
}
739736

service/history/commandChecker_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (s *commandAttrValidatorSuite) SetupTest() {
130130
config.SearchAttributesNumberOfKeysLimit,
131131
config.SearchAttributesSizeOfValueLimit,
132132
config.SearchAttributesTotalSizeLimit,
133+
"index-name",
133134
))
134135
}
135136

@@ -190,17 +191,17 @@ func (s *commandAttrValidatorSuite) TestValidateUpsertWorkflowSearchAttributes()
190191
namespace := namespace.Name("tests.Namespace")
191192
var attributes *commandpb.UpsertWorkflowSearchAttributesCommandAttributes
192193

193-
fc, err := s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes, "index-name")
194+
fc, err := s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes)
194195
s.EqualError(err, "UpsertWorkflowSearchAttributesCommandAttributes is not set on command.")
195196
s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, fc)
196197

197198
attributes = &commandpb.UpsertWorkflowSearchAttributesCommandAttributes{}
198-
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes, "index-name")
199+
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes)
199200
s.EqualError(err, "SearchAttributes is not set on command.")
200201
s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, fc)
201202

202203
attributes.SearchAttributes = &commonpb.SearchAttributes{}
203-
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes, "index-name")
204+
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes)
204205
s.EqualError(err, "IndexedFields is empty on command.")
205206
s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES, fc)
206207

@@ -209,7 +210,7 @@ func (s *commandAttrValidatorSuite) TestValidateUpsertWorkflowSearchAttributes()
209210
attributes.SearchAttributes.IndexedFields = map[string]*commonpb.Payload{
210211
"CustomKeywordField": saPayload,
211212
}
212-
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes, "index-name")
213+
fc, err = s.validator.validateUpsertWorkflowSearchAttributes(namespace, attributes)
213214
s.NoError(err)
214215
s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED, fc)
215216
}
@@ -238,7 +239,6 @@ func (s *commandAttrValidatorSuite) TestValidateContinueAsNewWorkflowExecutionAt
238239
tests.Namespace,
239240
attributes,
240241
executionInfo,
241-
"index-name",
242242
)
243243
s.NoError(err)
244244
s.Equal(enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED, fc)

service/history/historyEngine.go

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func NewEngineWithShardContext(
229229
config.SearchAttributesNumberOfKeysLimit,
230230
config.SearchAttributesSizeOfValueLimit,
231231
config.SearchAttributesTotalSizeLimit,
232+
config.DefaultVisibilityIndexName,
232233
)
233234

234235
historyEngImpl.workflowTaskHandler = newWorkflowTaskHandlerCallback(historyEngImpl)

service/history/historyEngine2_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (s *engine2Suite) SetupTest() {
192192
s.config.SearchAttributesNumberOfKeysLimit,
193193
s.config.SearchAttributesSizeOfValueLimit,
194194
s.config.SearchAttributesTotalSizeLimit,
195+
s.config.DefaultVisibilityIndexName,
195196
),
196197
workflowConsistencyChecker: api.NewWorkflowConsistencyChecker(mockShard, s.workflowCache),
197198
}

service/history/workflowTaskHandler.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ func (handler *workflowTaskHandlerImpl) handleCommandContinueAsNewWorkflow(
784784
namespaceName,
785785
attr,
786786
handler.mutableState.GetExecutionInfo(),
787-
handler.config.DefaultVisibilityIndexName,
788787
)
789788
},
790789
); err != nil || handler.stopProcessing {
@@ -899,7 +898,6 @@ func (handler *workflowTaskHandlerImpl) handleCommandStartChildWorkflow(
899898
attr,
900899
handler.mutableState.GetExecutionInfo(),
901900
handler.config.DefaultWorkflowTaskTimeout,
902-
handler.config.DefaultVisibilityIndexName,
903901
)
904902
},
905903
); err != nil || handler.stopProcessing {
@@ -1038,11 +1036,7 @@ func (handler *workflowTaskHandlerImpl) handleCommandUpsertWorkflowSearchAttribu
10381036
// valid search attributes for upsert
10391037
if err := handler.validateCommandAttr(
10401038
func() (enumspb.WorkflowTaskFailedCause, error) {
1041-
return handler.attrValidator.validateUpsertWorkflowSearchAttributes(
1042-
namespace,
1043-
attr,
1044-
handler.config.DefaultVisibilityIndexName,
1045-
)
1039+
return handler.attrValidator.validateUpsertWorkflowSearchAttributes(namespace, attr)
10461040
},
10471041
); err != nil || handler.stopProcessing {
10481042
return err

service/history/workflowTaskHandlerCallbacks_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (s *WorkflowTaskHandlerCallbackSuite) SetupTest() {
125125
config.SearchAttributesNumberOfKeysLimit,
126126
config.SearchAttributesSizeOfValueLimit,
127127
config.SearchAttributesTotalSizeLimit,
128+
config.DefaultVisibilityIndexName,
128129
),
129130
workflowConsistencyChecker: api.NewWorkflowConsistencyChecker(mockShard, workflowCache),
130131
}

0 commit comments

Comments
 (0)