Skip to content

Commit feece38

Browse files
Add CHASM visibility task handling of alias to field mapping for custom search attributes (#8558)
Add CHASM visibility task handling of alias to field mapping for custom search attributes. The Visibility component stores aliased custom search attributes and their corresponding payloads. On the WRITE path, Visibility Store CURRENTLY assumes search attributes are schema field names, and does not apply any mappings from alias -> field. This is because FrontEnd "Unaliases" to its field names before sending to History. ## What changed? Before calling the visibility manager `UpsertWorkflowExecution`, the search attributes need to be mapped from their aliases to their field names. ## Why? Support Visibility component compatibility with current Visibility Store implementation. ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s)
1 parent 9ce746d commit feece38

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

common/persistence/visibility/store/elasticsearch/visibility_store_read_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (s *ESVisibilitySuite) Test_convertQueryLegacy() {
336336
query = `StartTime = "2018-06-07T15:04:05.123456789-08:00"`
337337
queryParams, err = s.visibilityStore.convertQueryLegacy(testNamespace, testNamespaceID, query)
338338
s.NoError(err)
339-
s.Equal(`{"bool":{"filter":[{"term":{"NamespaceId":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}},{"bool":{"filter":{"match":{"StartTime":{"query":"2018-06-07T15:04:05.123456789-08:00"}}}}}],"must_not":{"exists":{"field":"TemporalNamespaceDivision"}}}}`, s.queryToJSON(queryParams.Query))
339+
s.JSONEq(`{"bool":{"filter":[{"term":{"NamespaceId":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}},{"bool":{"filter":{"match":{"StartTime":{"query":"2018-06-07T15:04:05.123456789-08:00"}}}}}],"must_not":{"exists":{"field":"TemporalNamespaceDivision"}}}}`, s.queryToJSON(queryParams.Query))
340340
s.Nil(queryParams.Sorter)
341341

342342
query = `WorkflowId = 'wid' and StartTime > "2018-06-07T15:04:05+00:00"`

service/history/visibility_queue_task_executor.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,33 @@ func (t *visibilityQueueTaskExecutor) processChasmTask(
389389
return serviceerror.NewInternalf("expected visibility component, but got %T", visComponent)
390390
}
391391

392-
searchattributes, err := visComponent.GetSearchAttributes(visTaskContext)
392+
namespaceEntry, err := t.shardContext.GetNamespaceRegistry().
393+
GetNamespaceByID(namespace.ID(task.GetNamespaceID()))
394+
if err != nil {
395+
return err
396+
}
397+
398+
searchattributesMapperProvider := t.shardContext.GetSearchAttributesMapperProvider()
399+
searchAttributesMapper, err := searchattributesMapperProvider.GetMapper(namespaceEntry.Name())
393400
if err != nil {
394401
return err
395402
}
396-
if searchattributes == nil {
397-
searchattributes = make(map[string]*commonpb.Payload)
403+
404+
searchattributes := make(map[string]*commonpb.Payload)
405+
406+
aliasedSearchAttributes, err := visComponent.GetSearchAttributes(visTaskContext)
407+
if err != nil {
408+
return err
398409
}
410+
411+
for alias, value := range aliasedSearchAttributes {
412+
fieldName, err := searchAttributesMapper.GetFieldName(alias, namespaceEntry.Name().String())
413+
if err != nil {
414+
return err
415+
}
416+
searchattributes[fieldName] = value
417+
}
418+
399419
memo, err := visComponent.GetMemo(visTaskContext)
400420
if err != nil {
401421
return err
@@ -419,11 +439,6 @@ func (t *visibilityQueueTaskExecutor) processChasmTask(
419439
}
420440
}
421441

422-
namespaceEntry, err := t.shardContext.GetNamespaceRegistry().
423-
GetNamespaceByID(namespace.ID(task.GetNamespaceID()))
424-
if err != nil {
425-
return err
426-
}
427442
requestBase := t.getVisibilityRequestBase(
428443
task,
429444
namespaceEntry,

service/history/visibility_queue_task_executor_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ func (s *visibilityQueueTaskExecutorSuite) SetupTest() {
107107
config,
108108
)
109109

110+
// Set up expectations on the SearchAttributesMapper mocks created by NewTestContext
111+
mockMapper := searchattribute.NewMockMapper(s.controller)
112+
mockMapper.EXPECT().GetFieldName(gomock.Any(), gomock.Any()).DoAndReturn(
113+
func(alias string, _ string) (string, error) {
114+
return alias, nil
115+
},
116+
).AnyTimes()
117+
118+
mockMapperProvider := s.mockShard.Resource.SearchAttributesMapperProvider
119+
mockMapperProvider.EXPECT().GetMapper(gomock.Any()).Return(mockMapper, nil).AnyTimes()
120+
110121
reg := hsm.NewRegistry()
111122
err := workflow.RegisterStateMachine(reg)
112123
s.NoError(err)

0 commit comments

Comments
 (0)