Skip to content

Commit

Permalink
Set auto config hint for empty polls (#6611)
Browse files Browse the repository at this point in the history
* Set auto config hint for empty polls
* Get auto config hint enabled flag from matching engine config
  • Loading branch information
neil-xie authored Jan 14, 2025
1 parent 2d539d2 commit 89dee7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions service/matching/handler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ pollLoop:
if err != nil {
return nil, fmt.Errorf("couldn't load tasklist namanger: %w", err)
}
startT := time.Now() // Record the start time
task, err := tlMgr.GetTask(pollerCtx, nil)
if err != nil {
// TODO: Is empty poll the best reply for errPumpClosed?
Expand All @@ -561,9 +562,14 @@ pollLoop:
"RequestForwardedFrom": req.GetForwardedFrom(),
},
})
domainName, _ := e.domainCache.GetDomainName(domainID)
return &types.MatchingPollForDecisionTaskResponse{
PartitionConfig: tlMgr.TaskListPartitionConfig(),
LoadBalancerHints: tlMgr.LoadBalancerHints(),
AutoConfigHint: &types.AutoConfigHint{
EnableAutoConfig: e.config.EnableClientAutoConfig(domainName, taskListName, persistence.TaskListTypeDecision),
PollerWaitTimeInMs: time.Since(startT).Milliseconds(),
},
}, nil
}
return nil, fmt.Errorf("couldn't get task: %w", err)
Expand Down Expand Up @@ -722,13 +728,19 @@ pollLoop:
if err != nil {
return nil, fmt.Errorf("couldn't load tasklist namanger: %w", err)
}
startT := time.Now() // Record the start time
task, err := tlMgr.GetTask(pollerCtx, maxDispatch)
if err != nil {
// TODO: Is empty poll the best reply for errPumpClosed?
if errors.Is(err, tasklist.ErrNoTasks) || errors.Is(err, errPumpClosed) {
domainName, _ := e.domainCache.GetDomainName(domainID)
return &types.MatchingPollForActivityTaskResponse{
PartitionConfig: tlMgr.TaskListPartitionConfig(),
LoadBalancerHints: tlMgr.LoadBalancerHints(),
AutoConfigHint: &types.AutoConfigHint{
EnableAutoConfig: e.config.EnableClientAutoConfig(domainName, taskListName, persistence.TaskListTypeDecision),
PollerWaitTimeInMs: time.Since(startT).Milliseconds(),
},
}, nil
}
e.logger.Error("Received unexpected err while getting task",
Expand Down
9 changes: 9 additions & 0 deletions service/matching/handler/engine_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ func (s *matchingEngineSuite) PollForDecisionTasksResultTest() {
}
resp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
s.NoError(err)
s.NotNil(resp.AutoConfigHint)
resp.AutoConfigHint = nil
s.Equal(&pollTaskResponse{}, resp)
// add task to sticky tasklist again, this time it should pass
_, err = addTask(s.matchingEngine, s.handlerContext, addRequest)
Expand Down Expand Up @@ -363,6 +365,8 @@ func (s *matchingEngineSuite) PollForTasksEmptyResultTest(callContext context.Co
Identity: identity,
}
pollResp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
s.NotNil(pollResp.AutoConfigHint)
pollResp.AutoConfigHint = nil // poller wait time is not a fixed value, exclude it from comparison
s.NoError(err)
s.Equal(&pollTaskResponse{}, pollResp)

Expand Down Expand Up @@ -952,6 +956,8 @@ func (s *matchingEngineSuite) PollWithExpiredContext(taskType int) {
s.handlerContext.Context = ctx
resp, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
s.Nil(err)
s.NotNil(resp.AutoConfigHint)
resp.AutoConfigHint = nil
s.Equal(&pollTaskResponse{}, resp)
}

Expand Down Expand Up @@ -1134,6 +1140,8 @@ func (s *matchingEngineSuite) UnloadTasklistOnIsolationConfigChange(taskType int
}
result, err := pollTask(s.matchingEngine, s.handlerContext, pollReq)
s.NoError(err)
s.NotNil(result.AutoConfigHint)
result.AutoConfigHint = nil
s.Equal(&pollTaskResponse{}, result)

result, err = pollTask(s.matchingEngine, s.handlerContext, pollReq)
Expand Down Expand Up @@ -1644,6 +1652,7 @@ func pollTask(engine *matchingEngineImpl, hCtx *handlerContext, request *pollTas
WorkflowType: resp.WorkflowType,
WorkflowDomain: resp.WorkflowDomain,
Header: resp.Header,
AutoConfigHint: resp.AutoConfigHint,
}, nil
}
resp, err := engine.PollForDecisionTask(hCtx, &types.MatchingPollForDecisionTaskRequest{
Expand Down

0 comments on commit 89dee7f

Please sign in to comment.