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

Set auto config hint for empty polls #6611

Merged
merged 10 commits into from
Jan 14, 2025
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
neil-xie marked this conversation as resolved.
Show resolved Hide resolved
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
Loading