-
Notifications
You must be signed in to change notification settings - Fork 8
feat(stovepipe): reconcile dead-lettered build signals and free the slot #565
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| // 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 dlq | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/uber-go/tally" | ||
| "github.com/uber/submitqueue/platform/consumer" | ||
| "github.com/uber/submitqueue/platform/metrics" | ||
| stovepipemq "github.com/uber/submitqueue/stovepipe/core/messagequeue" | ||
| "github.com/uber/submitqueue/stovepipe/extension/storage" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // _buildSignalOpName is the metric operation name shared by every emit in this file. | ||
| const _buildSignalOpName = "buildsignal_dlq" | ||
|
|
||
| // BuildSignalController is the DLQ reconciler for the buildsignal stage. The | ||
| // payload names a build, not a request, so it takes one more step than the | ||
| // process reconciler: read the build to get its RequestID, then fail that | ||
| // request via failRequest. | ||
| // | ||
| // This DLQ is the one that matters most. A request only reaches buildsignal | ||
| // after process admitted it, so it holds one of the queue's in_flight_count | ||
| // build slots, and buildsignal's terminal path is the only thing that gives that | ||
| // slot back. Once a poll message dead-letters — a Status call that stayed broken | ||
| // through every retry, an unknown build id, a storage write that kept failing — | ||
| // nothing else in the pipeline will look at that build again. Without this | ||
| // reconciler the request stays processing for good and the slot is never | ||
| // returned, so the queue loses one slot per incident until it has none left and | ||
| // stops admitting work. | ||
| // | ||
| // The Build row keeps whatever non-terminal status the runner last reported. | ||
| // There is nothing useful to fix: record decides greenness from Request.State, | ||
| // not Build.Status, and writing a terminal status here would claim we saw an | ||
| // outcome we never saw. | ||
| type BuildSignalController struct { | ||
| logger *zap.SugaredLogger | ||
| metricsScope tally.Scope | ||
| stores storage.Factory | ||
| topicKey consumer.TopicKey | ||
| consumerGroup string | ||
| } | ||
|
|
||
| // Verify BuildSignalController implements consumer.Controller at compile time. | ||
| var _ consumer.Controller = (*BuildSignalController)(nil) | ||
|
|
||
| // NewBuildSignalController creates a DLQ controller for the buildsignal stage's | ||
| // dead-letter topic. topicKey is typically | ||
| // dlq.TopicKey(stovepipemq.TopicKeyBuildSignal). | ||
| func NewBuildSignalController( | ||
| logger *zap.SugaredLogger, | ||
| scope tally.Scope, | ||
| stores storage.Factory, | ||
| topicKey consumer.TopicKey, | ||
| consumerGroup string, | ||
| ) *BuildSignalController { | ||
| return &BuildSignalController{ | ||
| logger: logger.Named("buildsignal_dlq_controller"), | ||
| metricsScope: scope.SubScope("buildsignal_dlq_controller"), | ||
| stores: stores, | ||
| topicKey: topicKey, | ||
| consumerGroup: consumerGroup, | ||
| } | ||
| } | ||
|
|
||
| // Process reconciles a single DLQ delivery for the buildsignal topic. Returns nil | ||
| // to ack (success) or an error to nack (retry) — pair this controller only with a | ||
| // consumer wired with errs.AlwaysRetryableProcessor so a transient reconcile | ||
| // failure retries instead of dead-lettering the DLQ message itself. | ||
| func (c *BuildSignalController) Process(ctx context.Context, delivery consumer.Delivery) error { | ||
| msg := delivery.Message() | ||
|
|
||
| sig := &stovepipemq.BuildSignal{} | ||
| if err := stovepipemq.Unmarshal(msg.Payload, sig); err != nil { | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "deserialize_errors", 1) | ||
| // Retried rather than acked, for the same deployment-skew reason the | ||
| // process reconciler gives: a newer producer's payload decodes fine once | ||
| // the rollout finishes, and acking here would skip the slot release | ||
| // without saying so. | ||
| return fmt.Errorf("failed to decode dlq payload: %w", err) | ||
| } | ||
| if sig.Id == "" { | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "empty_id_errors", 1) | ||
| return fmt.Errorf("dlq payload decoded to empty build id") | ||
| } | ||
|
|
||
| store, err := c.stores.For(storage.Config{QueueName: sig.GetQueueName()}) | ||
| if err != nil { | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "storage_resolve_errors", 1) | ||
| // Non-retryable: a missing or unresolvable queue is a malformed message. | ||
| return fmt.Errorf("failed to resolve storage for queue %q: %w", sig.GetQueueName(), err) | ||
| } | ||
|
|
||
| dmeta := delivery.Metadata() | ||
| c.logger.Warnw("dlq message received", | ||
| "build_id", sig.Id, | ||
| "attempt", delivery.Attempt(), | ||
| "dlq_original_topic", dmeta["dlq.original_topic"], | ||
| "dlq_failure_count", dmeta["dlq.failure_count"], | ||
| "dlq_last_error", dmeta["dlq.last_error"], | ||
| ) | ||
|
|
||
| build, err := store.GetBuildStore().Get(ctx, sig.Id) | ||
| if err != nil { | ||
| if errors.Is(err, storage.ErrNotFound) { | ||
| // The build row was never written — a crash between Trigger and | ||
| // Create. There is no request to recover from this payload; the build | ||
| // stage's own DLQ handles the request that triggered it. | ||
| c.logger.Warnw("dlq reconcile: build not found, skipping", "build_id", sig.Id) | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "build_not_found", 1) | ||
| return nil | ||
| } | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "build_store_errors", 1) | ||
| return fmt.Errorf("failed to get build %s: %w", sig.Id, err) | ||
| } | ||
|
|
||
| if build.RequestID == "" { | ||
| // Defensive: a build with no request has nothing to reconcile and no slot | ||
| // to release. Ack it so the DLQ does not grow forever. | ||
| c.logger.Errorw("dlq reconcile: build has empty request id, skipping", "build_id", sig.Id) | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "build_missing_request", 1) | ||
| return nil | ||
| } | ||
|
|
||
| // Every request reachable from a build row is either still processing, and holding | ||
| // the slot failRequest releases, or already terminal, and past releasing it: build | ||
| // triggers only once process has written the strategy, which lands in the same CAS | ||
| // as accepted→processing, and processing exits only to a terminal outcome. | ||
| if err := failRequest(ctx, store, c.logger, build.RequestID); err != nil { | ||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "reconcile_errors", 1) | ||
| return err | ||
| } | ||
|
|
||
| metrics.NamedCounter(c.metricsScope, _buildSignalOpName, "reconciled", 1) | ||
| return nil | ||
| } | ||
|
|
||
| // Name returns the controller name for logging and metrics. | ||
| func (c *BuildSignalController) Name() string { | ||
| return "buildsignal_dlq" | ||
| } | ||
|
|
||
| // TopicKey returns the topic key this controller subscribes to. | ||
| func (c *BuildSignalController) TopicKey() consumer.TopicKey { | ||
| return c.topicKey | ||
| } | ||
|
|
||
| // ConsumerGroup returns the consumer group for offset tracking. | ||
| func (c *BuildSignalController) 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.