Add a hook point to the Matching service once a task has been matched or not#9311
Add a hook point to the Matching service once a task has been matched or not#931102strich merged 1 commit intoserverlessfrom
Conversation
cb2a1fa to
30a201a
Compare
rkannan82
left a comment
There was a problem hiding this comment.
Looks good to me. Lets add David/Shahab to this.
30a201a to
fa521df
Compare
fa521df to
1849a89
Compare
fee0744 to
0091e88
Compare
9fdf08f to
280df75
Compare
50abbf7 to
ef7ec27
Compare
ef7ec27 to
a40f820
Compare
| @@ -0,0 +1,36 @@ | |||
| package hooks | |||
There was a problem hiding this comment.
does this really need to be a new package? if it is a new package, let's remove "TaskHook" as a prefix from all these names to reduce stuttering.
There was a problem hiding this comment.
it can't be in matching as that causes a dependency loop. I would love if there was a different existing place instead of creating a new one
| tqConfig, | ||
| partition.TaskQueue().TaskType()) | ||
| var taskHooks []hooks.TaskHook | ||
| for _, hookProducer := range taskHookFactories { |
There was a problem hiding this comment.
do we have a case for more than one of these? can we simplify it to one optional hook factory/hook?
There was a problem hiding this comment.
We have a use case for one today, but I don't believe it is wise to limit today given all the difference is having this as a loop
| assignedBuildId = spoolQueue.QueueKey().Version().BuildId() | ||
| } | ||
|
|
||
| pm.processTaskAddHooks(ctx, targetVersion, false, dbq) |
There was a problem hiding this comment.
what about errors? do we care if we call this and then SpoolTask fails?
There was a problem hiding this comment.
Thinking about this some more. Originally, I didn't really care about errors as slight over-signaling isn't harmful for the specific use case. That said, It is likely to be confusing when debugging, and similarly under-signaling also cannot be a critical issue. So in the name of less confusion, changing it to only trigger the hooks on successful spool
a40f820 to
d7e9c5a
Compare
c41f922 to
a86c2ca
Compare
jaypipes
left a comment
There was a problem hiding this comment.
Obviously I need to read more about how the matching service works, but I would have thought that there would be an event sink that we could set up to receive an event/signal that a particular task queue + type tuple had no active pollers. Is there no such mechanism we can "hook into"?
| for _, hook := range pm.taskHooks { | ||
| hook.Start() | ||
| } |
There was a problem hiding this comment.
Here and below, do we need to have a deterministic order to the firing of task hook Start() and (reverse-orderered) Stop() calls?
There was a problem hiding this comment.
There is no promise on ordering of different hooks, so they need to be independent in general - which should extend to start and stop
@jaypipes this PR adds that hook point. Though we don't care about whether there are no active pollers in general, but just when a task needs to be matched so this is in the task dispatching path. |
| TaskQueueName string | ||
| TaskQueueType enumspb.TaskQueueType | ||
| TaskQueueKind enumspb.TaskQueueKind |
There was a problem hiding this comment.
I think it should be tqid.Partition to match the granularity in which we create the hook instances.
The Partition has all the info needed by the hook. I understand that the hook's usage of the data may be oblivious of the fact that it is partition level, but still the interface should be clear that instantiation is per partition.
I also have a problem with bringing TaskQueueKind to the interface, as the enum belongs to the outdated representation of sticky task queues. For context, sticky task queues are now considered a partition of the user-level task queue, and not as much of a separate task queue.
There was a problem hiding this comment.
Discussed offline, and added a stripped down interface to reduce the amount of exposed details
a86c2ca to
b327a9d
Compare
… (or not) This adds a hook point to the matching service once it has matched a task or decided to spool it. This can be leveraged to react to task sync or no-sync match events, while keeping matching service decoupled from the event handling logic.
b327a9d to
aef287a
Compare
| // TaskQueuePartition is a simplified version of tqid.Partition that removes details | ||
| // the hooks should not concern themselves with | ||
| TaskQueuePartition interface { | ||
| NamespaceId() string |
There was a problem hiding this comment.
could probably drop this since we have Namespace in the TaskHookFactoryCreateDetails?
| s.Require().Eventually(func() bool { | ||
| select { | ||
| case <-pollStarted: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| }, 2*time.Second, 1*time.Millisecond) |
There was a problem hiding this comment.
nit: it might be nice to move https://github.com/temporalio/temporal/blob/main/tests/testcore/functional_test_base.go#L660
to a common test utils so we could use it in unit tests. doesn't have to be now of course
What changed?
This adds a hook point to the matching service once it has matched a task or decided to spool it.
Why?
This can be leveraged to react to task sync or no-sync match events, while keeping matching service decoupled from the event handling logic.
How did you test it?