Skip to content

Commit 89dee7f

Browse files
authored
Set auto config hint for empty polls (#6611)
* Set auto config hint for empty polls * Get auto config hint enabled flag from matching engine config
1 parent 2d539d2 commit 89dee7f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

service/matching/handler/engine.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ pollLoop:
539539
if err != nil {
540540
return nil, fmt.Errorf("couldn't load tasklist namanger: %w", err)
541541
}
542+
startT := time.Now() // Record the start time
542543
task, err := tlMgr.GetTask(pollerCtx, nil)
543544
if err != nil {
544545
// TODO: Is empty poll the best reply for errPumpClosed?
@@ -561,9 +562,14 @@ pollLoop:
561562
"RequestForwardedFrom": req.GetForwardedFrom(),
562563
},
563564
})
565+
domainName, _ := e.domainCache.GetDomainName(domainID)
564566
return &types.MatchingPollForDecisionTaskResponse{
565567
PartitionConfig: tlMgr.TaskListPartitionConfig(),
566568
LoadBalancerHints: tlMgr.LoadBalancerHints(),
569+
AutoConfigHint: &types.AutoConfigHint{
570+
EnableAutoConfig: e.config.EnableClientAutoConfig(domainName, taskListName, persistence.TaskListTypeDecision),
571+
PollerWaitTimeInMs: time.Since(startT).Milliseconds(),
572+
},
567573
}, nil
568574
}
569575
return nil, fmt.Errorf("couldn't get task: %w", err)
@@ -722,13 +728,19 @@ pollLoop:
722728
if err != nil {
723729
return nil, fmt.Errorf("couldn't load tasklist namanger: %w", err)
724730
}
731+
startT := time.Now() // Record the start time
725732
task, err := tlMgr.GetTask(pollerCtx, maxDispatch)
726733
if err != nil {
727734
// TODO: Is empty poll the best reply for errPumpClosed?
728735
if errors.Is(err, tasklist.ErrNoTasks) || errors.Is(err, errPumpClosed) {
736+
domainName, _ := e.domainCache.GetDomainName(domainID)
729737
return &types.MatchingPollForActivityTaskResponse{
730738
PartitionConfig: tlMgr.TaskListPartitionConfig(),
731739
LoadBalancerHints: tlMgr.LoadBalancerHints(),
740+
AutoConfigHint: &types.AutoConfigHint{
741+
EnableAutoConfig: e.config.EnableClientAutoConfig(domainName, taskListName, persistence.TaskListTypeDecision),
742+
PollerWaitTimeInMs: time.Since(startT).Milliseconds(),
743+
},
732744
}, nil
733745
}
734746
e.logger.Error("Received unexpected err while getting task",

service/matching/handler/engine_integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ func (s *matchingEngineSuite) PollForDecisionTasksResultTest() {
311311
}
312312
resp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
313313
s.NoError(err)
314+
s.NotNil(resp.AutoConfigHint)
315+
resp.AutoConfigHint = nil
314316
s.Equal(&pollTaskResponse{}, resp)
315317
// add task to sticky tasklist again, this time it should pass
316318
_, err = addTask(s.matchingEngine, s.handlerContext, addRequest)
@@ -363,6 +365,8 @@ func (s *matchingEngineSuite) PollForTasksEmptyResultTest(callContext context.Co
363365
Identity: identity,
364366
}
365367
pollResp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
368+
s.NotNil(pollResp.AutoConfigHint)
369+
pollResp.AutoConfigHint = nil // poller wait time is not a fixed value, exclude it from comparison
366370
s.NoError(err)
367371
s.Equal(&pollTaskResponse{}, pollResp)
368372

@@ -952,6 +956,8 @@ func (s *matchingEngineSuite) PollWithExpiredContext(taskType int) {
952956
s.handlerContext.Context = ctx
953957
resp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
954958
s.Nil(err)
959+
s.NotNil(resp.AutoConfigHint)
960+
resp.AutoConfigHint = nil
955961
s.Equal(&pollTaskResponse{}, resp)
956962
}
957963

@@ -1134,6 +1140,8 @@ func (s *matchingEngineSuite) UnloadTasklistOnIsolationConfigChange(taskType int
11341140
}
11351141
result, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
11361142
s.NoError(err)
1143+
s.NotNil(result.AutoConfigHint)
1144+
result.AutoConfigHint = nil
11371145
s.Equal(&pollTaskResponse{}, result)
11381146

11391147
result, err = pollTask(s.matchingEngine, s.handlerContext, pollReq)
@@ -1644,6 +1652,7 @@ func pollTask(engine *matchingEngineImpl, hCtx *handlerContext, request *pollTas
16441652
WorkflowType: resp.WorkflowType,
16451653
WorkflowDomain: resp.WorkflowDomain,
16461654
Header: resp.Header,
1655+
AutoConfigHint: resp.AutoConfigHint,
16471656
}, nil
16481657
}
16491658
resp, err := engine.PollForDecisionTask(hCtx, &types.MatchingPollForDecisionTaskRequest{

0 commit comments

Comments
 (0)