Repository navigation
fix(start): report failed starts when no request was saved #1040
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
Open
sbalabanov
wants to merge
2
commits into
main
Choose a base branch
from
wt/sqc011
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+456
−34
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // 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 dlq | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/uber-go/tally" | ||
| entityqueue "github.com/uber/submitqueue/platform/base/messagequeue" | ||
| "github.com/uber/submitqueue/platform/consumer" | ||
| "github.com/uber/submitqueue/platform/metrics" | ||
| "github.com/uber/submitqueue/submitqueue/entity" | ||
| "github.com/uber/submitqueue/submitqueue/extension/storage" | ||
| corerequest "github.com/uber/submitqueue/submitqueue/orchestrator/core/request" | ||
| orchstorage "github.com/uber/submitqueue/submitqueue/orchestrator/extension/storage" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type startController struct { | ||
| logger *zap.SugaredLogger | ||
| metricsScope tally.Scope | ||
| stores orchstorage.Factory | ||
| registry consumer.TopicRegistry | ||
| topicKey consumer.TopicKey | ||
| consumerGroup string | ||
| } | ||
|
|
||
| // NewDLQStartController reconciles failed submissions without restarting processing. | ||
| func NewDLQStartController(logger *zap.SugaredLogger, scope tally.Scope, stores orchstorage.Factory, registry consumer.TopicRegistry, topicKey consumer.TopicKey, consumerGroup string) consumer.Controller { | ||
| return &startController{ | ||
| logger: logger.Named("start_dlq"), | ||
| metricsScope: scope.SubScope("start_dlq"), | ||
| stores: stores, | ||
| registry: registry, | ||
| topicKey: topicKey, | ||
| consumerGroup: consumerGroup, | ||
| } | ||
| } | ||
|
|
||
| func (c *startController) Process(ctx context.Context, delivery consumer.Delivery) (err error) { | ||
| defer func() { | ||
| if err != nil { | ||
| metrics.NamedCounter(c.metricsScope, "process", "reconcile_errors", 1, metrics.TagsFromContext(ctx)...) | ||
| } | ||
| }() | ||
|
|
||
| msg := delivery.Message() | ||
| rid, err := DecodeLandRequestID(msg.Payload) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to decode start dlq payload: %w", err) | ||
| } | ||
| if err := entityqueue.ValidatePayloadQueue(msg, rid.Queue); err != nil { | ||
| metrics.NamedCounter(c.metricsScope, "process", "queue_identity_errors", 1, metrics.TagsFromContext(ctx)...) | ||
| c.logger.Warnw("invalid start dlq queue identity", "error", err) | ||
| return nil | ||
| } | ||
| if rid.ID == "" { | ||
| return fmt.Errorf("dlq payload decoded to empty request id") | ||
| } | ||
|
|
||
| store, err := c.stores.For(orchstorage.Config{QueueName: msg.Tenant}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to resolve storage for queue %q: %w", rid.Queue, err) | ||
| } | ||
| lastError, metadata := failureContext(delivery) | ||
| c.logger.Warnw("reconciling failed start", "request_id", rid.ID, "queue", rid.Queue, "attempt", delivery.Attempt()) | ||
| request, err := store.GetRequestStore().Get(ctx, rid.ID) | ||
| switch { | ||
| case errors.Is(err, storage.ErrNotFound): | ||
| err = c.publishStartFailure(ctx, rid.ID, msg.Tenant, 0, lastError, metadata) | ||
| case err == nil: | ||
| err = c.failExistingStartRequest(ctx, store, request, rid, lastError, metadata) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (c *startController) failExistingStartRequest(ctx context.Context, store orchstorage.Storage, request entity.Request, rid entity.RequestID, lastError string, metadata map[string]string) error { | ||
| if request.ID != rid.ID || request.Queue != rid.Queue { | ||
| return fmt.Errorf("conflicting request identity for failed start request %s", rid.ID) | ||
| } | ||
| // A Start retry can fail after an earlier delivery published validation and the request joined a batch. | ||
| // Let that batch finish instead of changing its request to Error. | ||
| owner, err := owningBatch(ctx, store, request.ID) | ||
| if err != nil || owner != "" { | ||
| return err | ||
| } | ||
| switch request.State { | ||
| case entity.RequestStateError: | ||
| _, err := corerequest.TerminateRequest(ctx, store, c.registry, request.ID, entity.RequestStateError, lastError, metadata) | ||
| return err | ||
| case entity.RequestStateLanded, entity.RequestStateCancelled: | ||
| return nil | ||
| } | ||
| updated := request | ||
| updated.State = entity.RequestStateError | ||
| newVersion := request.Version + 1 | ||
| // The observed version guards against a batch claim or terminal winner after the owner lookup. | ||
| if err := store.GetRequestStore().Update(ctx, updated, request.Version, newVersion); err != nil { | ||
| return fmt.Errorf("failed to fail start request: %w", err) | ||
| } | ||
| updated.Version = newVersion | ||
| return c.publishStartFailure(ctx, updated.ID, updated.Queue, updated.Version, lastError, metadata) | ||
| } | ||
|
|
||
| func (c *startController) publishStartFailure(ctx context.Context, requestID, queue string, version int32, lastError string, metadata map[string]string) error { | ||
| entry := entity.NewRequestStatusLog(queue, requestID, entity.RequestStatusError, version, lastError, metadata) | ||
| return corerequest.PublishLog(ctx, c.registry, entry, requestID, "") | ||
| } | ||
|
|
||
| func (c *startController) Name() string { | ||
| return string(c.topicKey) | ||
| } | ||
|
|
||
| func (c *startController) TopicKey() consumer.TopicKey { | ||
| return c.topicKey | ||
| } | ||
|
|
||
| func (c *startController) ConsumerGroup() string { | ||
| return c.consumerGroup | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.