From 916c09e55410e13aca0f40715c0eb47ca61b3c07 Mon Sep 17 00:00:00 2001 From: mnoah1 Date: Fri, 4 Dec 2026 20:48:25 +0000 Subject: [PATCH] feat(stovepipe): wire fix tracking and handle dead letters Summary: ## Why? Exhausted deliveries need a terminal outcome without running the repair a second time. ## What? Register the primary and dead-letter workers. Reconcile exhausted tasks while preserving terminal results and verified links. Test Plan: The real-queue MySQL test covers both rejected and exhausted deliveries. Run with `./tool/bazel test //test/integration/stovepipe/extension/storage/mysql:go_default_test`. Revert Plan: Revert this change after reverting any dependent stack entries. --- doc/rfc/stovepipe/fix-tracking.md | 2 +- service/stovepipe/server/BUILD.bazel | 1 + service/stovepipe/server/main.go | 20 ++++ stovepipe/controller/fixtrack/BUILD.bazel | 7 +- stovepipe/controller/fixtrack/README.md | 2 + stovepipe/controller/fixtrack/dlq.go | 67 ++++++++++++ .../controller/fixtrack/fixtrack_test.go | 39 +++++++ .../extension/storage/mysql/BUILD.bazel | 17 +++ .../storage/mysql/fix_tracking_test.go | 101 ++++++++++++++++++ .../extension/storage/mysql/storage_test.go | 5 + 10 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 stovepipe/controller/fixtrack/dlq.go create mode 100644 test/integration/stovepipe/extension/storage/mysql/fix_tracking_test.go diff --git a/doc/rfc/stovepipe/fix-tracking.md b/doc/rfc/stovepipe/fix-tracking.md index 8dad4b608..6b8ca523e 100644 --- a/doc/rfc/stovepipe/fix-tracking.md +++ b/doc/rfc/stovepipe/fix-tracking.md @@ -22,6 +22,6 @@ For example, a formatter accepts two issues from one request under `fix_id=run-4 ## Retry and deployment boundaries -Each report has its own poll budget and terminal outcome (`succeeded`, `failed`, `skipped`, or `inconclusive`). One terminal report does not close the fix to later reports. Progress for the fix is versioned together so concurrent reports cannot erase each other's verified links. An unavailable tracker or an exhausted polling budget yields `inconclusive`; the dead-letter worker preserves verified links without calling the executor again. +Each report has its own poll budget and terminal outcome (`succeeded`, `failed`, `skipped`, or `inconclusive`). One terminal report does not close the fix to later reports. Progress for the fix is versioned together so concurrent reports cannot erase each other's verified links. An unavailable tracker or an exhausted polling budget yields `inconclusive`; the [dead-letter worker](../../../stovepipe/controller/fixtrack/README.md) preserves verified links without calling the executor again. The [reference host](../../../service/stovepipe/README.md) uses a no-op fixer and restricts the callback RPC to loopback. A custom host must authorize its executor workloads. Deploy the [storage schema](../../../stovepipe/extension/storage/README.md), RPC writers, and primary and dead-letter workers before enabling callbacks. In particular, drain workers that do not understand `report_id` before sending named reports: they interpret a named task as the unnamed report. diff --git a/service/stovepipe/server/BUILD.bazel b/service/stovepipe/server/BUILD.bazel index d432b5bea..606d397b1 100644 --- a/service/stovepipe/server/BUILD.bazel +++ b/service/stovepipe/server/BUILD.bazel @@ -31,6 +31,7 @@ go_library( "//stovepipe/controller/buildsignal:go_default_library", "//stovepipe/controller/dlq:go_default_library", "//stovepipe/controller/fix:go_default_library", + "//stovepipe/controller/fixtrack:go_default_library", "//stovepipe/controller/issueagemetrics:go_default_library", "//stovepipe/controller/issuetrack:go_default_library", "//stovepipe/controller/periodicmetrics:go_default_library", diff --git a/service/stovepipe/server/main.go b/service/stovepipe/server/main.go index bfcf49a40..8746c22a6 100644 --- a/service/stovepipe/server/main.go +++ b/service/stovepipe/server/main.go @@ -54,6 +54,7 @@ import ( "github.com/uber/submitqueue/stovepipe/controller/buildsignal" "github.com/uber/submitqueue/stovepipe/controller/dlq" "github.com/uber/submitqueue/stovepipe/controller/fix" + "github.com/uber/submitqueue/stovepipe/controller/fixtrack" "github.com/uber/submitqueue/stovepipe/controller/issueagemetrics" "github.com/uber/submitqueue/stovepipe/controller/issuetrack" "github.com/uber/submitqueue/stovepipe/controller/periodicmetrics" @@ -498,6 +499,11 @@ func registerPrimaryControllers( } count++ + if err := c.Register(fixtrack.NewController(store, repairExecutors, "stovepipe-fixtrack")); err != nil { + return count, fmt.Errorf("failed to register fix tracking controller: %w", err) + } + count++ + projectController := projectanalysis.NewController(logger, scope, store, materializer, projectstatusnoop.New(), projectissuesnoop.New(), registry, stovepipemq.TopicKeyProjectAnalysis, "stovepipe-projectanalysis") if err := c.Register(projectController); err != nil { return count, fmt.Errorf("failed to register projectanalysis controller: %w", err) @@ -562,6 +568,11 @@ func registerDLQControllers( } count++ + if err := c.Register(fixtrack.NewDLQController(logger, store, dlq.TopicKey(stovepipemq.TopicKeyFixTrack), "stovepipe-fixtrack-dlq")); err != nil { + return count, fmt.Errorf("register fix tracking DLQ: %w", err) + } + count++ + fixDLQController := fix.NewDLQController(logger, scope, store, materializer, repairExecutors, dlq.TopicKey(stovepipemq.TopicKeyFix), "stovepipe-fix-dlq") if err := c.Register(fixDLQController); err != nil { return count, fmt.Errorf("failed to register fix dlq controller: %w", err) @@ -602,6 +613,7 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe issueAgeSubscription.Retry.MaxAttempts = 0 issueAgeSubscription.DLQ.Enabled = false + fixTrackingSubscription := extqueue.SingleMessageSubscriptionConfig(subscriberName, "stovepipe-fixtrack") return consumer.NewTopicRegistry([]consumer.TopicConfig{ { Key: stovepipemq.TopicKeyQueueHealthMetrics, @@ -701,6 +713,14 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe Queue: q, Subscription: extqueue.DLQSubscriptionConfig(subscriberName, "stovepipe-issuetrack-dlq"), }, + {Key: dlq.TopicKey(stovepipemq.TopicKeyFixTrack), Name: "fixtrack_dlq", Queue: q, + Subscription: extqueue.DLQSubscriptionConfig(subscriberName, "stovepipe-fixtrack-dlq")}, + { + Key: stovepipemq.TopicKeyFixTrack, + Name: "fixtrack", + Queue: q, + Subscription: fixTrackingSubscription, + }, { Key: stovepipemq.TopicKeyFix, Name: "fix", diff --git a/stovepipe/controller/fixtrack/BUILD.bazel b/stovepipe/controller/fixtrack/BUILD.bazel index ca4365ed4..f74802325 100644 --- a/stovepipe/controller/fixtrack/BUILD.bazel +++ b/stovepipe/controller/fixtrack/BUILD.bazel @@ -2,7 +2,10 @@ load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["fixtrack.go"], + srcs = [ + "dlq.go", + "fixtrack.go", + ], importpath = "github.com/uber/submitqueue/stovepipe/controller/fixtrack", visibility = ["//visibility:public"], deps = [ @@ -12,6 +15,7 @@ go_library( "//stovepipe/entity:go_default_library", "//stovepipe/extension/fixer:go_default_library", "//stovepipe/extension/storage:go_default_library", + "@org_uber_go_zap//:go_default_library", ], ) @@ -30,5 +34,6 @@ go_test( "//stovepipe/extension/storage/mock:go_default_library", "@com_github_stretchr_testify//require:go_default_library", "@org_uber_go_mock//gomock:go_default_library", + "@org_uber_go_zap//:go_default_library", ], ) diff --git a/stovepipe/controller/fixtrack/README.md b/stovepipe/controller/fixtrack/README.md index d0f607e49..0c6cb56a3 100644 --- a/stovepipe/controller/fixtrack/README.md +++ b/stovepipe/controller/fixtrack/README.md @@ -3,3 +3,5 @@ A fix report schedules one durable task per queue, executor ID, and fix ID. Tracking observes existing work through the executor's optional `ReportTracker` capability. It never submits a repair or depends on the per-issue submission receipt being written. An observed outcome is a complete snapshot, including all known change URLs, and does not imply the original issues were fixed. While publication is pending, the controller durably saves progress and postpones that delivery with backoff from 30 seconds up to 15 minutes. The next check time survives redelivery. A terminal outcome stops polling; an unavailable tracker or exhausted pending-check budget produces an inconclusive outcome, not a failed fix. Storage and backend errors follow the host's retry classifier. Optimistic locking prevents a stale worker from overwriting progress. + +A rejected task or exhausted infrastructure retry goes to the terminal reconciler, which stores `inconclusive` without calling the executor again. Dead-letter recovery preserves discovered links and never overwrites a terminal observation. Its storage retries are unlimited. diff --git a/stovepipe/controller/fixtrack/dlq.go b/stovepipe/controller/fixtrack/dlq.go new file mode 100644 index 000000000..3ae146586 --- /dev/null +++ b/stovepipe/controller/fixtrack/dlq.go @@ -0,0 +1,67 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package fixtrack + +import ( + "context" + + entityqueue "github.com/uber/submitqueue/platform/base/messagequeue" + "github.com/uber/submitqueue/platform/consumer" + mq "github.com/uber/submitqueue/stovepipe/core/messagequeue" + "github.com/uber/submitqueue/stovepipe/entity" + "github.com/uber/submitqueue/stovepipe/extension/storage" + "go.uber.org/zap" +) + +type terminalController struct { + logger *zap.SugaredLogger + stores storage.Factory + topic consumer.TopicKey + group string +} + +// NewDLQController retains terminal evidence without re-invoking the executor. The host must retry storage errors. +func NewDLQController(logger *zap.SugaredLogger, stores storage.Factory, topic consumer.TopicKey, group string) consumer.Controller { + return &terminalController{logger: logger, stores: stores, topic: topic, group: group} +} +func (c *terminalController) Name() string { return string(c.topic) } +func (c *terminalController) TopicKey() consumer.TopicKey { return c.topic } +func (c *terminalController) ConsumerGroup() string { return c.group } +func (c *terminalController) Process(ctx context.Context, delivery consumer.Delivery) error { + msg := delivery.Message() + var key mq.FixTrack + if err := mq.Unmarshal(msg.Payload, &key); err != nil || entityqueue.ValidatePayloadQueue(msg, key.QueueName) != nil || key.ExecutorId == "" || key.FixId == "" { + c.logger.Errorw("discarding malformed fix tracking dead letter", "message_id", msg.ID) + return nil + } + scoped, err := c.stores.For(storage.Config{QueueName: key.QueueName}) + if err != nil { + return err + } + store := scoped.GetFixReportStore() + progress, err := store.GetTrackingState(ctx, key.ExecutorId, key.FixId) + if storage.IsNotFound(err) { + c.logger.Warnw("no callback for dead letter", "queue", key.QueueName, "executor_id", key.ExecutorId, "fix_id", key.FixId) + return nil + } + if err != nil { + return err + } + if progress.State != "" && progress.State != entity.FixStatePending { + return nil + } + progress.State, progress.Reason, progress.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0 + return store.UpdateTrackingState(ctx, key.ExecutorId, key.FixId, progress, progress.Version, progress.Version+1) +} diff --git a/stovepipe/controller/fixtrack/fixtrack_test.go b/stovepipe/controller/fixtrack/fixtrack_test.go index afe2ae8ee..4345baa6d 100644 --- a/stovepipe/controller/fixtrack/fixtrack_test.go +++ b/stovepipe/controller/fixtrack/fixtrack_test.go @@ -29,6 +29,7 @@ import ( "github.com/uber/submitqueue/stovepipe/extension/storage" storagemock "github.com/uber/submitqueue/stovepipe/extension/storage/mock" "go.uber.org/mock/gomock" + "go.uber.org/zap" ) func TestFixTrack(t *testing.T) { @@ -95,3 +96,41 @@ func TestFixTrack(t *testing.T) { }) } } + +func TestDeadLetterRetainsOutcome(t *testing.T) { + pending := entity.FixTrackingState{FixObservation: entity.FixObservation{State: entity.FixStatePending, ChangeURLs: []string{"https://example.org/pr/3"}}, NextCheckAt: 1000, Version: 3} + terminal := pending + terminal.State, terminal.Reason, terminal.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0 + for _, tt := range []struct { + name string + current entity.FixTrackingState + write bool + err error + }{ + {"rejected before first observation", entity.FixTrackingState{}, true, nil}, + {"exhausted retries preserve links", pending, true, nil}, + {"lost CAS retries instead of acknowledging", pending, true, storage.ErrVersionMismatch}, + {"duplicate delivery preserves winner", terminal, false, nil}, + } { + t.Run(tt.name, func(t *testing.T) { + m := gomock.NewController(t) + stores := storagemock.NewMockFactory(m) + scoped := storagemock.NewMockStorage(m) + store := storagemock.NewMockFixReportStore(m) + d := consumermock.NewMockDelivery(m) + payload, err := mq.Marshal(&mq.FixTrack{QueueName: "q", ExecutorId: "e", FixId: "f"}) + require.NoError(t, err) + d.EXPECT().Message().Return(entityqueue.Message{Tenant: "q", Payload: payload}) + stores.EXPECT().For(storage.Config{QueueName: "q"}).Return(scoped, nil) + scoped.EXPECT().GetFixReportStore().Return(store) + store.EXPECT().GetTrackingState(gomock.Any(), "e", "f").Return(tt.current, nil) + if tt.write { + want := tt.current + want.State, want.Reason, want.NextCheckAt = entity.FixStateInconclusive, "tracking_abandoned", 0 + store.EXPECT().UpdateTrackingState(gomock.Any(), "e", "f", want, tt.current.Version, tt.current.Version+1).Return(tt.err) + } + c := NewDLQController(zap.NewNop().Sugar(), stores, "fixtrack_dlq", "dlq") + require.ErrorIs(t, c.Process(t.Context(), d), tt.err) + }) + } +} diff --git a/test/integration/stovepipe/extension/storage/mysql/BUILD.bazel b/test/integration/stovepipe/extension/storage/mysql/BUILD.bazel index b88c8ec51..21c6c7903 100644 --- a/test/integration/stovepipe/extension/storage/mysql/BUILD.bazel +++ b/test/integration/stovepipe/extension/storage/mysql/BUILD.bazel @@ -6,6 +6,7 @@ go_test( "build_issue_list_test.go", "build_issue_test.go", "build_issue_update_test.go", + "fix_tracking_test.go", "issue_log_test.go", "issue_state_list_test.go", "issue_state_test.go", @@ -25,6 +26,7 @@ go_test( ], data = [ "docker-compose.yml", + "//platform/extension/messagequeue/mysql/schema", "//stovepipe/extension/storage/mysql/schema", ], tags = [ @@ -32,11 +34,24 @@ go_test( "requires-network", ], deps = [ + "//platform/consumer:go_default_library", + "//platform/consumer/mock:go_default_library", + "//platform/errs:go_default_library", + "//platform/errs/yarpc:go_default_library", + "//platform/extension/consumergate/noop:go_default_library", + "//platform/extension/messagequeue:go_default_library", + "//platform/extension/messagequeue/mysql:go_default_library", + "//stovepipe/controller:go_default_library", + "//stovepipe/controller/dlq:go_default_library", + "//stovepipe/controller/fixtrack:go_default_library", "//stovepipe/core/issuelog:go_default_library", + "//stovepipe/core/messagequeue:go_default_library", "//stovepipe/core/queuelog:go_default_library", "//stovepipe/core/queuestate:go_default_library", "//stovepipe/core/requestlog:go_default_library", "//stovepipe/entity:go_default_library", + "//stovepipe/extension/fixer:go_default_library", + "//stovepipe/extension/fixer/mock:go_default_library", "//stovepipe/extension/sourcecontrol:go_default_library", "//stovepipe/extension/sourcecontrol/fake:go_default_library", "//stovepipe/extension/sourcecontrol/mock:go_default_library", @@ -51,5 +66,7 @@ go_test( "@com_github_stretchr_testify//suite:go_default_library", "@com_github_uber_go_tally//:go_default_library", "@org_uber_go_mock//gomock:go_default_library", + "@org_uber_go_yarpc//yarpcerrors:go_default_library", + "@org_uber_go_zap//zaptest:go_default_library", ], ) diff --git a/test/integration/stovepipe/extension/storage/mysql/fix_tracking_test.go b/test/integration/stovepipe/extension/storage/mysql/fix_tracking_test.go new file mode 100644 index 000000000..174e57781 --- /dev/null +++ b/test/integration/stovepipe/extension/storage/mysql/fix_tracking_test.go @@ -0,0 +1,101 @@ +// Copyright (c) 2025 Uber Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package mysql + +import ( + "database/sql" + "testing" + "time" + + "github.com/stretchr/testify/require" + "github.com/uber-go/tally" + "github.com/uber/submitqueue/platform/consumer" + consumermock "github.com/uber/submitqueue/platform/consumer/mock" + "github.com/uber/submitqueue/platform/errs" + yarpcclassifier "github.com/uber/submitqueue/platform/errs/yarpc" + "github.com/uber/submitqueue/platform/extension/consumergate/noop" + extqueue "github.com/uber/submitqueue/platform/extension/messagequeue" + sqlqueue "github.com/uber/submitqueue/platform/extension/messagequeue/mysql" + "github.com/uber/submitqueue/stovepipe/controller" + "github.com/uber/submitqueue/stovepipe/controller/dlq" + "github.com/uber/submitqueue/stovepipe/controller/fixtrack" + mq "github.com/uber/submitqueue/stovepipe/core/messagequeue" + "github.com/uber/submitqueue/stovepipe/entity" + "github.com/uber/submitqueue/stovepipe/extension/fixer" + fixermock "github.com/uber/submitqueue/stovepipe/extension/fixer/mock" + "github.com/uber/submitqueue/stovepipe/extension/storage" + "go.uber.org/mock/gomock" + "go.uber.org/yarpc/yarpcerrors" + "go.uber.org/zap/zaptest" +) + +func testFixTrackingDeadLetter(t *testing.T, db *sql.DB, stores storage.Factory) { + const tenant = "repairs" + logger := zaptest.NewLogger(t) + q, err := sqlqueue.NewQueue(sqlqueue.Params{DB: db, Logger: logger, MetricsScope: tally.NoopScope, Tenants: []string{tenant}}) + require.NoError(t, err) + defer q.Close() + sub := extqueue.SingleMessageSubscriptionConfig("worker", "observe") + sub.Retry.MaxAttempts = 2 + sub.Retry.InitialBackoffMs = 1 + sub.Retry.MaxBackoffMs = 10 + sub.PollIntervalMs = 10 + sub.PartitionDiscoveryIntervalMs = 10 + dead := extqueue.DLQSubscriptionConfig("worker", "recover") + dead.PartitionDiscoveryIntervalMs = 10 + dead.PollIntervalMs = 10 + key := mq.TopicKeyFixTrack + topic := "fixtrack" + registry, err := consumer.NewTopicRegistry([]consumer.TopicConfig{{Key: key, Name: topic, Queue: q, Subscription: sub}, {Key: dlq.TopicKey(key), Name: topic + sub.DLQ.TopicSuffix, Queue: q, Subscription: dead}}) + require.NoError(t, err) + deliveries, err := q.Subscriber().Subscribe(t.Context(), topic+sub.DLQ.TopicSuffix, dead) + require.NoError(t, err) + mocks := gomock.NewController(t) + factory := fixermock.NewMockFactory(mocks) + observer := fixermock.NewMockReportTracker(mocks) + executor := struct { + fixer.RepairExecutor + fixer.ReportTracker + }{fixermock.NewMockRepairExecutor(mocks), observer} + factory.EXPECT().For(fixer.Config{QueueName: tenant}).Return([]fixer.Registration{{ID: "rep", Executor: executor}}, nil).AnyTimes() + worker := consumer.New(logger.Sugar(), tally.NoopScope, registry, errs.NewClassifierProcessor(yarpcclassifier.Classifier), noop.New()) + require.NoError(t, worker.Register(fixtrack.NewController(stores, factory, sub.ConsumerGroup))) + require.NoError(t, worker.Start(t.Context())) + defer func() { require.NoError(t, worker.Stop(time.Minute.Milliseconds())) }() + record := controller.NewRecordFixReportController(stores, []string{tenant}, registry) + recoverer := fixtrack.NewDLQController(logger.Sugar(), stores, dlq.TopicKey(key), dead.ConsumerGroup) + scoped, err := stores.For(storage.Config{QueueName: tenant}) + require.NoError(t, err) + for _, tt := range []struct { + id string + err error + calls int + }{{"denied", yarpcerrors.PermissionDeniedErrorf("denied"), 1}, {"exhausted", yarpcerrors.UnavailableErrorf("down"), sub.Retry.MaxAttempts}} { + report := entity.FixReport{Queue: tenant, FixID: tt.id, ExecutorID: "rep", Payload: []byte(`{}`)} + observer.EXPECT().ObserveFix(gomock.Any(), report).Return(entity.FixObservation{}, tt.err).Times(tt.calls) + require.NoError(t, record.RecordFixReport(t.Context(), report)) + delivery := <-deliveries + require.NotNil(t, delivery) + d := consumermock.NewMockDelivery(mocks) + d.EXPECT().Message().Return(delivery.Message()).Times(2) + require.NoError(t, recoverer.Process(t.Context(), d)) + require.NoError(t, recoverer.Process(t.Context(), d)) + require.NoError(t, delivery.Ack(t.Context())) + progress, err := scoped.GetFixReportStore().GetTrackingState(t.Context(), "rep", tt.id) + require.NoError(t, err) + require.Equal(t, entity.FixStateInconclusive, progress.State) + require.EqualValues(t, 1, progress.Version) + } +} diff --git a/test/integration/stovepipe/extension/storage/mysql/storage_test.go b/test/integration/stovepipe/extension/storage/mysql/storage_test.go index c501e878c..68c9e857b 100644 --- a/test/integration/stovepipe/extension/storage/mysql/storage_test.go +++ b/test/integration/stovepipe/extension/storage/mysql/storage_test.go @@ -65,6 +65,11 @@ func TestMySQLStorage(t *testing.T) { return backend.For(config.QueueName) }).AnyTimes() + t.Run("FixTrackingDeadLetter", func(t *testing.T) { + testutil.ApplySchema(t, log, db, testutil.SchemaDir("platform/extension/messagequeue/mysql/schema")) + testFixTrackingDeadLetter(t, db, factory) + }) + t.Run("FixReport", func(t *testing.T) { result := entity.FixReport{Queue: "result/main", ExecutorID: "repair", FixID: "AbC", Payload: json.RawMessage(`{"results":[]}`)} bound, err := backend.For(result.Queue)