Skip to content

Commit 417fb9b

Browse files
committed
feat(submitqueue): Publish request hook events from the gateway to the orchestrator's hook stage
1 parent 5540e3f commit 417fb9b

7 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎doc/rfc/hook-framework.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Fire-and-forget side effects for pipeline lifecycle events: one shared event con
44

55
## Status
66

7-
Implemented. The contract is `api/base/hook`, the dispatcher and DLQ reconciler are `platform/hook`, and the extension is `platform/extension/hook`. Stovepipe's `process` and `record` publish repository-scoped hook events, and `service/stovepipe/server` registers the stage. The SubmitQueue orchestrator pipeline registers a `submitqueue-hook` stage; no orchestrator controller publishes a hook event, and `service/submitqueue/orchestrator/server` resolves every event to noop. A deployment's real integrations are whatever its resolver returns.
7+
Implemented. The contract is `api/base/hook`, the dispatcher and DLQ reconciler are `platform/hook`, and the extension is `platform/extension/hook`. Stovepipe's `process` and `record` publish repository-scoped hook events, and `service/stovepipe/server` registers the stage. The SubmitQueue orchestrator pipeline registers a `submitqueue-hook` stage. The SubmitQueue gateway's request materializer publishes `request.received`, `request.landed`, and `request.failed` (`submitqueue/core/hookevent`) to it; no orchestrator controller publishes a hook event, and `service/submitqueue/orchestrator/server` resolves every event to noop. A deployment's real integrations are whatever its resolver returns.
88

99
## Problem
1010

@@ -52,6 +52,7 @@ Delivery promise:
5252
- Partition key = subject id; per-subject order only.
5353
- Replay finding the target state already written → republish (idempotent). Beyond it → superseded; the event may be lost. Named, accepted gap.
5454
- RPC-caused transitions are at-most-once; needing the guarantee means publishing from the first queue-driven stage.
55+
- SubmitQueue request events follow the gateway's request summary, the status users see, rather than pipeline transitions, so a hook agrees with the UI even for a request whose start failed before the orchestrator saved it. Each status announces one event per change, so a hook retrying one change's failure never repeats another's. A finish is announced on every delivery of a log that restates it, which keeps the replay rule above: a failed publish fails the delivery and its redelivery republishes. `request.received` is published inside `Land`, which makes it RPC-caused and at-most-once; a later status standing in for a lost `accepted` log announces it instead. The events cross from the gateway to the orchestrator's hook stage, so their payload carries the change's URI, which never changes.
5556
- Opt-in per host via topic-key registration; a registered host never skips, so off and loss are distinguishable.
5657

5758
### Contract

‎doc/rfc/submitqueue/workflow.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Two cycles re-enter speculation. `speculate` dispatches funded paths to `build`;
66

77
Terminal request states are not `conclude`'s alone. `cancel` completes a request that has not been enrolled in a batch. `landconflictsignal` fails a request Runway reports as conflicted. `conclude` maps a terminal batch onto its member requests. The DLQ reconcilers force a failed terminal state when a consumed stage cannot finish.
88

9-
The same `Stages` table registers a `submitqueue-hook` stage, outside the order of the flow above. It consumes hook events and invokes the wired hooks, and it publishes nothing onward. No orchestrator controller publishes a hook event; `service/submitqueue/orchestrator/server` resolves every event to noop. The comment on that row in `pipeline.go` is the contract: any stage can publish there.
9+
The same `Stages` table registers a `submitqueue-hook` stage, outside the order of the flow above. It consumes hook events and invokes the wired hooks, and it publishes nothing onward. The gateway's request materializer publishes request events there (see the [gateway README](../../../submitqueue/gateway/README.md)); no orchestrator controller does, and `service/submitqueue/orchestrator/server` resolves every event to noop. The comment on that row in `pipeline.go` is the contract: any stage can publish there.
1010

1111
## Diagram
1212

@@ -131,7 +131,7 @@ class node_storagecontract,node_queuestorage,node_requestlog,node_messagequeue t
131131
class node_submitter toneIndigo
132132
```
133133

134-
`hook` is drawn with the other stages because the topology registers it. Nothing in the orchestrator publishes to it, so the diagram has no edge into that node.
134+
`hook` is drawn with the other stages because the topology registers it. Only the gateway's request materializer publishes to it, so the diagram has no edge into that node from an orchestrator stage.
135135

136136
## Per-controller summary
137137

‎service/submitqueue/gateway/server/BUILD.bazel‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ go_library(
1919
importpath = "github.com/uber/submitqueue/service/submitqueue/gateway/server",
2020
visibility = ["//visibility:private"],
2121
deps = [
22+
"//api/base/hook:go_default_library",
2223
"//api/submitqueue/gateway/protopb:go_default_library",
2324
"//platform/consumer:go_default_library",
2425
"//platform/errs:go_default_library",
@@ -93,6 +94,7 @@ go_test(
9394
],
9495
embed = [":gateway_lib"], # keep
9596
deps = [
97+
"//api/base/hook:go_default_library",
9698
"//api/submitqueue/gateway/protopb:go_default_library",
9799
"//platform/base/failure:go_default_library",
98100
"//platform/base/messagequeue:go_default_library",
@@ -103,12 +105,14 @@ go_test(
103105
"//platform/extension/messagequeue/mock:go_default_library",
104106
"//platform/lifecycle:go_default_library",
105107
"//submitqueue/core/messagequeue:go_default_library",
108+
"//submitqueue/core/topickey:go_default_library",
106109
"//submitqueue/entity:go_default_library",
107110
"//submitqueue/extension/queueconfig/mock:go_default_library",
108111
"//submitqueue/gateway/controller:go_default_library",
109112
"//submitqueue/gateway/core/request:go_default_library",
110113
"//submitqueue/gateway/extension/storage:go_default_library",
111114
"//submitqueue/gateway/extension/storage/mock:go_default_library",
115+
"//submitqueue/orchestrator:go_default_library",
112116
"@com_github_stretchr_testify//assert:go_default_library",
113117
"@com_github_stretchr_testify//require:go_default_library",
114118
"@com_github_uber_go_tally//:go_default_library",

‎service/submitqueue/gateway/server/log_consumer.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/uber-go/tally"
23+
basehook "github.com/uber/submitqueue/api/base/hook"
2324
"github.com/uber/submitqueue/platform/consumer"
2425
"github.com/uber/submitqueue/platform/errs"
2526
genericerrs "github.com/uber/submitqueue/platform/errs/generic"
@@ -47,6 +48,8 @@ func newGatewayTopicRegistry(queue extqueue.Queue, subscriberName string) (consu
4748
{Key: topickey.TopicKeyStart, Name: "start", Queue: queue},
4849
{Key: topickey.TopicKeyCancel, Name: "cancel", Queue: queue},
4950
{Key: topickey.TopicKeyLog, Name: "log", Queue: queue, Subscription: primary},
51+
// Publish-only: the orchestrator pipeline's hook stage consumes it under this name.
52+
{Key: basehook.TopicKeyHook, Name: "submitqueue-hook", Queue: queue},
5053
{
5154
Key: logDLQTopicKey, Name: "log" + logDLQSuffix, Queue: queue,
5255
Subscription: extqueue.DLQSubscriptionConfig(subscriberName, logDLQConsumerGroup),

‎service/submitqueue/gateway/server/log_consumer_test.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/stretchr/testify/assert"
2323
"github.com/stretchr/testify/require"
2424
"github.com/uber-go/tally"
25+
basehook "github.com/uber/submitqueue/api/base/hook"
2526
"github.com/uber/submitqueue/platform/base/failure"
2627
entityqueue "github.com/uber/submitqueue/platform/base/messagequeue"
2728
"github.com/uber/submitqueue/platform/consumer"
@@ -30,10 +31,12 @@ import (
3031
queuemock "github.com/uber/submitqueue/platform/extension/messagequeue/mock"
3132
"github.com/uber/submitqueue/platform/lifecycle"
3233
sqmq "github.com/uber/submitqueue/submitqueue/core/messagequeue"
34+
"github.com/uber/submitqueue/submitqueue/core/topickey"
3335
"github.com/uber/submitqueue/submitqueue/entity"
3436
requestcore "github.com/uber/submitqueue/submitqueue/gateway/core/request"
3537
gwstorage "github.com/uber/submitqueue/submitqueue/gateway/extension/storage"
3638
gwstoragemock "github.com/uber/submitqueue/submitqueue/gateway/extension/storage/mock"
39+
"github.com/uber/submitqueue/submitqueue/orchestrator"
3740
"go.uber.org/mock/gomock"
3841
"go.uber.org/zap"
3942
"google.golang.org/grpc"
@@ -112,6 +115,25 @@ func TestLogConsumers_RetainFailedRecovery(t *testing.T) {
112115
}
113116
}
114117

118+
func TestGatewayTopicRegistry_MatchesOrchestratorStages(t *testing.T) {
119+
registry, err := newGatewayTopicRegistry(queuemock.NewMockQueue(gomock.NewController(t)), "worker")
120+
require.NoError(t, err)
121+
stageNames := map[consumer.TopicKey]string{}
122+
for _, stage := range orchestrator.Stages {
123+
stageNames[stage.Key] = stage.Name
124+
}
125+
126+
for _, key := range []consumer.TopicKey{topickey.TopicKeyStart, topickey.TopicKeyCancel, basehook.TopicKeyHook} {
127+
t.Run(string(key), func(t *testing.T) {
128+
want, ok := stageNames[key]
129+
require.True(t, ok, "the orchestrator consumes every topic the gateway publishes to")
130+
got, ok := registry.TopicName(key)
131+
require.True(t, ok)
132+
assert.Equal(t, want, got)
133+
})
134+
}
135+
}
136+
115137
type lifecycleTestConsumer struct {
116138
consumer.Consumer
117139
name string

‎service/submitqueue/gateway/server/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func run() error {
334334
// Land creates receipt projections, request-summary and List controllers
335335
// read materialized views, and request-history controllers read retained
336336
// logs. Normal log-topic persistence and terminal DLQ repair both use the
337-
// materializer.
337+
// materializer, which also publishes request hook events.
338338
store, err := mysqlstorage.NewStorage(appDB, scope.SubScope("storage"))
339339
if err != nil {
340340
return fmt.Errorf("failed to create storage: %w", err)
@@ -343,7 +343,7 @@ func run() error {
343343
// Create controllers and wrap them for gRPC. Every store is queue-scoped and
344344
// resolves through the factory adapter; land/cancel/log share one materializer.
345345
storageFty := storageFactory{backend: store}
346-
materializer := requestcore.NewMaterializer(storageFty, requestcore.WithMetricsScope(scope))
346+
materializer := requestcore.NewMaterializer(storageFty, requestcore.WithMetricsScope(scope), requestcore.WithHookPublishing(registry))
347347
pingController := controller.NewPingController(logger, scope)
348348
landController := controller.NewLandController(logger.Sugar(), scope, cnt, storageFty, materializer, queueConfigs, queuePauses, registry)
349349
cancelController := controller.NewCancelController(logger.Sugar(), scope, storageFty, materializer, registry)

‎submitqueue/gateway/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ The gateway owns the request log read model and is the only service that reads i
2525

2626
The materializer appends every audit event, selects the current authoritative winner, and repairs the queue projection. The normal orchestrator pipeline does not read or write the request-log store directly.
2727

28+
## Request hook events
29+
30+
The materializer publishes SubmitQueue's request hook events (`submitqueue/core/hookevent`) to the `submitqueue-hook` topic, which the orchestrator pipeline's hook stage consumes, one event per change of the request. The update that takes the summary out of `accepting` announces `request.received`; that happens inside `Land`, so a failed receipt publish is only counted on `request_hook.publish_errors`. Every delivery of a log that restates a `landed` or `error` summary announces `request.landed` or `request.failed`, so a failed publish is returned and the log's redelivery repairs it; a copy that arrives after the queue has forgotten the event id reaches hooks twice. Events therefore follow the summary users see, including a request whose start failed before the orchestrator saved it, and a stale or unfinished log publishes nothing.
31+
2832
## Final log recovery
2933

3034
The primary `gateway-log` consumer sends failed deliveries to `log_dlq` after a non-retryable error or exhaustion of its finite retry budget. The gateway's `gateway-log-dlq` consumer replays retained entries through the same log controller and materializer, with unlimited attempts, capped backoff, and no second-level DLQ. Valid log deliveries are acknowledged only after history, summary, URI mappings, and receipt projection succeed. Replays may append equivalent history rows; terminal-summary precedence and mapping repair are unchanged.

0 commit comments

Comments
 (0)