Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions submitqueue/core/messagequeue/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ const (
// speculate) on the conclude publish and read by conclude to stamp the request's
// terminal log; absent on the landed and cancelled paths.
const MetadataKeyFailureReason = "failure_reason"

// MetadataKeyFailureCategory is the conclude message's metadata attribute carrying
// a failed batch's entity.FailureCategory, set and read beside MetadataKeyFailureReason.
const MetadataKeyFailureCategory = "failure_category"
2 changes: 2 additions & 0 deletions submitqueue/core/topickey/topickey.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ const (
TopicKeyLog = messagequeue.TopicKeyLog
// MetadataKeyFailureReason is the conclude message metadata attribute for a failed batch's reason.
MetadataKeyFailureReason = messagequeue.MetadataKeyFailureReason
// MetadataKeyFailureCategory is the conclude message metadata attribute for a failed batch's failure category.
MetadataKeyFailureCategory = messagequeue.MetadataKeyFailureCategory
)
2 changes: 2 additions & 0 deletions submitqueue/entity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"change_provider.go",
"change_record.go",
"conflict.go",
"failure_category.go",
"land.go",
"list.go",
"path_build.go",
Expand Down Expand Up @@ -40,6 +41,7 @@ go_test(
srcs = [
"batch_test.go",
"build_test.go",
"failure_category_test.go",
"request_log_test.go",
"request_test.go",
"speculation_test.go",
Expand Down
53 changes: 53 additions & 0 deletions submitqueue/entity/failure_category.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 entity

// FailureCategory is the kind of failure that ended a request in error, as a
// user would act on it. The empty value means the failure was not classified.
type FailureCategory string

const (
// FailureCategoryUnknown means the failure was not classified.
FailureCategoryUnknown FailureCategory = ""
// FailureCategoryDuplicate means another in-flight request already holds one of the request's changes.
FailureCategoryDuplicate FailureCategory = "duplicate"
// FailureCategoryValidationRejected means a validation rule rejected the request.
FailureCategoryValidationRejected FailureCategory = "validation_rejected"
// FailureCategoryBuildFailed means no build that could land the request passed.
FailureCategoryBuildFailed FailureCategory = "build_failed"
// FailureCategoryLandFailed means merging the request into the target branch failed or was refused,
// whether by a conflict or another merge failure.
FailureCategoryLandFailed FailureCategory = "land_failed"
// FailureCategoryInternalError means SubmitQueue itself could not finish processing the request.
FailureCategoryInternalError FailureCategory = "internal_error"
)

// RequestLogMetadataKeyFailureCategory is the request log metadata key holding an
// error status's FailureCategory. It is absent when the failure was not classified.
const RequestLogMetadataKeyFailureCategory = "failure_category"

// FailureCategoryMetadata returns metadata with category recorded under
// RequestLogMetadataKeyFailureCategory, leaving metadata itself unchanged. An
// unknown category records nothing.
func FailureCategoryMetadata(metadata map[string]string, category FailureCategory) map[string]string {
withCategory := make(map[string]string, len(metadata)+1)
for key, value := range metadata {
withCategory[key] = value
}
if category != FailureCategoryUnknown {
withCategory[RequestLogMetadataKeyFailureCategory] = string(category)
}
return withCategory
}
47 changes: 47 additions & 0 deletions submitqueue/entity/failure_category_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 entity

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestFailureCategoryMetadata(t *testing.T) {
tests := []struct {
name string
metadata map[string]string
category FailureCategory
want map[string]string
}{
{name: "no metadata", category: FailureCategoryBuildFailed, want: map[string]string{RequestLogMetadataKeyFailureCategory: "build_failed"}},
{name: "adds to existing metadata", metadata: map[string]string{"batch_id": "b1"}, category: FailureCategoryLandFailed, want: map[string]string{"batch_id": "b1", RequestLogMetadataKeyFailureCategory: "land_failed"}},
{name: "unknown category records nothing", metadata: map[string]string{"batch_id": "b1"}, want: map[string]string{"batch_id": "b1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
original := map[string]string{}
for key, value := range tt.metadata {
original[key] = value
}

assert.Equal(t, tt.want, FailureCategoryMetadata(tt.metadata, tt.category))
if tt.metadata != nil {
assert.Equal(t, original, tt.metadata)
}
})
}
}
1 change: 1 addition & 0 deletions submitqueue/orchestrator/controller/conclude/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"//platform/metrics:go_default_library",
"//submitqueue/core/messagequeue:go_default_library",
"//submitqueue/core/topickey:go_default_library",
"//submitqueue/entity:go_default_library",
"//submitqueue/orchestrator/core/batch:go_default_library",
"//submitqueue/orchestrator/extension/storage:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion submitqueue/orchestrator/controller/conclude/conclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/uber/submitqueue/platform/metrics"
sqmq "github.com/uber/submitqueue/submitqueue/core/messagequeue"
"github.com/uber/submitqueue/submitqueue/core/topickey"
"github.com/uber/submitqueue/submitqueue/entity"
corebatch "github.com/uber/submitqueue/submitqueue/orchestrator/core/batch"
orchstorage "github.com/uber/submitqueue/submitqueue/orchestrator/extension/storage"
"go.uber.org/zap"
Expand Down Expand Up @@ -108,7 +109,7 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
"partition_key", msg.PartitionKey,
)

return corebatch.ConcludeBatchRequests(ctx, store, c.registry, c.logger, c.metricsScope, batch, msg.Metadata[topickey.MetadataKeyFailureReason])
return corebatch.ConcludeBatchRequests(ctx, store, c.registry, c.logger, c.metricsScope, batch, msg.Metadata[topickey.MetadataKeyFailureReason], entity.FailureCategory(msg.Metadata[topickey.MetadataKeyFailureCategory]))
}

// Name returns the controller name for logging and metrics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestController_Process_FailedBatchCarriesReasonToRequestLog(t *testing.T) {
},
)

msg := entityqueue.NewMessage(batch.ID, batchIDPayload(t, batch.ID), batch.Queue, map[string]string{topickey.MetadataKeyFailureReason: reason})
msg := entityqueue.NewMessage(batch.ID, batchIDPayload(t, batch.ID), batch.Queue, map[string]string{topickey.MetadataKeyFailureReason: reason, topickey.MetadataKeyFailureCategory: string(entity.FailureCategoryBuildFailed)})
msg.Tenant = batch.Queue
delivery := consumermock.NewMockDelivery(ctrl)
delivery.EXPECT().Message().Return(msg).AnyTimes()
Expand All @@ -511,6 +511,7 @@ func TestController_Process_FailedBatchCarriesReasonToRequestLog(t *testing.T) {

assert.Equal(t, entity.RequestStatusError, logged.Status)
assert.Equal(t, reason, logged.LastError)
assert.Equal(t, string(entity.FailureCategoryBuildFailed), logged.Metadata[entity.RequestLogMetadataKeyFailureCategory])
}

func TestController_Process_StorageFailure(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion submitqueue/orchestrator/controller/dlq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ When the Request is absent, Start reports the failed submission through an Error

Conclude repairs terminal queue membership before fan-out and never changes the batch state. Every non-terminal state, including Landing, returns an error, as do missing records and invalid payload identities. The same final delivery retries until member writes and log publication complete; it does not republish a fresh conclude message.

Newly failed members use the original message’s `failure_reason` metadata, not a later DLQ infrastructure error. Newly landed or cancelled members carry no LastError. Already-matching terminal members repair their status logs; a different terminal winner is logged and preserved without overwriting it. Queue-wide dependent reconsideration is outside conclusion’s fan-out contract.
Newly failed members use the original message’s `failure_reason` and `failure_category` metadata, not a later DLQ infrastructure error. Every other reconciler classifies the request it fails as `internal_error`. Newly landed or cancelled members carry no LastError. Already-matching terminal members repair their status logs; a different terminal winner is logged and preserved without overwriting it. Queue-wide dependent reconsideration is outside conclusion’s fan-out contract.

## Terminal outputs and ownership

Expand Down
3 changes: 2 additions & 1 deletion submitqueue/orchestrator/controller/dlq/conclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/uber/submitqueue/platform/consumer"
sqmq "github.com/uber/submitqueue/submitqueue/core/messagequeue"
"github.com/uber/submitqueue/submitqueue/core/topickey"
"github.com/uber/submitqueue/submitqueue/entity"
corebatch "github.com/uber/submitqueue/submitqueue/orchestrator/core/batch"
orchstorage "github.com/uber/submitqueue/submitqueue/orchestrator/extension/storage"
"go.uber.org/zap"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (c *concludeController) Process(ctx context.Context, delivery consumer.Deli
if err := corebatch.EnsureRecord(ctx, store, batch); err != nil {
return err
}
return corebatch.ConcludeBatchRequests(ctx, store, c.registry, c.logger, c.metricsScope, batch, msg.Metadata[topickey.MetadataKeyFailureReason])
return corebatch.ConcludeBatchRequests(ctx, store, c.registry, c.logger, c.metricsScope, batch, msg.Metadata[topickey.MetadataKeyFailureReason], entity.FailureCategory(msg.Metadata[topickey.MetadataKeyFailureCategory]))
}

func (c *concludeController) Name() string { return string(c.topicKey) }
Expand Down
10 changes: 6 additions & 4 deletions submitqueue/orchestrator/controller/dlq/conclude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func concludeDelivery(t *testing.T, ctrl *gomock.Controller, reason string) cons
t.Helper()
payload, err := sqmq.MarshalID(sqmq.TopicKeyConclude, "9", "q")
require.NoError(t, err)
message := queue.NewMessage("conclude", payload, "q", map[string]string{topickey.MetadataKeyFailureReason: reason})
message := queue.NewMessage("conclude", payload, "q", map[string]string{topickey.MetadataKeyFailureReason: reason, topickey.MetadataKeyFailureCategory: string(entity.FailureCategoryLandFailed)})
message.Tenant = "q"
delivery := consumermock.NewMockDelivery(ctrl)
delivery.EXPECT().Message().Return(message).AnyTimes()
Expand All @@ -51,10 +51,11 @@ func TestDLQConcludeController_TerminalOutcomes(t *testing.T) {
requestState entity.RequestState
status entity.RequestStatus
lastError string
category entity.FailureCategory
}{
{entity.BatchStateSucceeded, entity.RequestStateLanded, entity.RequestStatusLanded, ""},
{entity.BatchStateFailed, entity.RequestStateError, entity.RequestStatusError, "merge conflict"},
{entity.BatchStateCancelled, entity.RequestStateCancelled, entity.RequestStatusCancelled, ""},
{entity.BatchStateSucceeded, entity.RequestStateLanded, entity.RequestStatusLanded, "", entity.FailureCategoryUnknown},
{entity.BatchStateFailed, entity.RequestStateError, entity.RequestStatusError, "merge conflict", entity.FailureCategoryLandFailed},
{entity.BatchStateCancelled, entity.RequestStateCancelled, entity.RequestStatusCancelled, "", entity.FailureCategoryUnknown},
} {
t.Run(string(tt.batchState), func(t *testing.T) {
ctrl := gomock.NewController(t)
Expand All @@ -75,6 +76,7 @@ func TestDLQConcludeController_TerminalOutcomes(t *testing.T) {
assert.Equal(t, tt.status, log.Status)
assert.Equal(t, tt.lastError, log.LastError)
assert.Equal(t, "9", log.Metadata["batch_id"])
assert.Equal(t, string(tt.category), log.Metadata[entity.RequestLogMetadataKeyFailureCategory])
return nil
})
storageFactory := orchstoragemock.NewMockFactory(ctrl)
Expand Down
14 changes: 12 additions & 2 deletions submitqueue/orchestrator/controller/dlq/dlq.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func primaryTopicKey(dlqKey consumer.TopicKey) consumer.TopicKey {
// read well in a display surface where a JSON blob would not.
func failureContext(delivery consumer.Delivery) (string, map[string]string) {
dmeta := delivery.Metadata()
metadata := make(map[string]string, len(dmeta))
metadata := map[string]string{entity.RequestLogMetadataKeyFailureCategory: string(entity.FailureCategoryInternalError)}
for _, key := range []string{"dlq.original_topic", "dlq.failure_count", "dlq.failed_at"} {
if v, ok := dmeta[key]; ok && v != "" {
metadata[key] = v
Expand Down Expand Up @@ -142,6 +142,12 @@ func flattenDetail(prefix string, detail map[string]any, out map[string]string)
// metadata and is exposed through Status and History for diagnosis, alongside
// metadata carrying the rest of the failure context.
//
// A known gap: a request already in Error gets this dead letter's details on
// its resend. When the original log never reached the gateway, for example a
// rejection whose log publish kept failing until the message dead-lettered,
// they become its only record, internal_error included. When it did, the
// gateway keeps it and only adds the dlq.* keys the summary lacked.
//
// A request in RequestStateCancelling is reconciled to RequestStateError, not
// left in place: DLQ means the pipeline failed to converge, so we cannot
// confirm the cancel completed cleanly. Writing Error is the honest signal and
Expand Down Expand Up @@ -186,7 +192,11 @@ func failRequest(ctx context.Context, store orchstorage.Storage, registry consum
// attempt may have crashed after updating the batch. Succeeded and Cancelled
// are different terminal outcomes and do not fan out errors.
// lastError and metadata are propagated to each member request's terminal
// Error log.
// Error log. A known gap: a batch that already failed but whose conclude has
// not run yet gets this dead letter's details, internal_error included, and the
// conclude that follows only resends, so its category does not replace them.
// The batch's failure travels only on its conclude message, so nothing better
// is available here.
//
// It reports whether it transitioned the batch. A caller that only wants to act
// on real progress — republishing to wake the queue, say — can then tell a
Expand Down
1 change: 1 addition & 0 deletions submitqueue/orchestrator/controller/dlq/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestDLQRequestController_Process_RequestIDPayload(t *testing.T) {

registry := newTestLogRegistry(t, ctrl, 1, func(log entity.RequestLog) error {
assert.Equal(t, "boom", log.LastError)
assert.Equal(t, string(entity.FailureCategoryInternalError), log.Metadata[entity.RequestLogMetadataKeyFailureCategory])
return nil
})

Expand Down
1 change: 1 addition & 0 deletions submitqueue/orchestrator/controller/dlq/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func TestDLQStartController_ReconcilesOnlyError(t *testing.T) {
assert.Zero(t, writes)
assert.Zero(t, logs[0].RequestVersion)
assert.Equal(t, "boom", logs[0].LastError)
assert.Equal(t, string(entity.FailureCategoryInternalError), logs[0].Metadata[entity.RequestLogMetadataKeyFailureCategory])
return
}
assert.Equal(t, landRequest.Change, persisted.Change)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
// The failed conflict check may be terminal even though its final log was never
// published. A redelivered failure carries the same result, so the resend can say why.
if request.State == entity.RequestStateError {
var reason string
if result.Outcome != runwaypb.Outcome_SUCCEEDED {
reason = result.Reason
if result.Outcome == runwaypb.Outcome_SUCCEEDED {
return corerequest.ResendTerminalRequestLog(ctx, c.registry, request, "", nil)
}
return corerequest.ResendTerminalRequestLog(ctx, c.registry, request, reason, nil)
reason, metadata := failure(result)
return corerequest.ResendTerminalRequestLog(ctx, c.registry, request, reason, metadata)
}

if entity.IsRequestStateHalted(request.State) {
Expand All @@ -139,7 +139,7 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
"request_id", request.ID,
"reason", result.Reason,
)
if err := c.failRequest(ctx, store, request, result.Reason); err != nil {
if err := c.failRequest(ctx, store, request, result); err != nil {
metrics.NamedCounter(c.metricsScope, opName, "fail_errors", 1, metrics.TagsFromContext(ctx)...)
return fmt.Errorf("failed to fail request %s: %w", request.ID, err)
}
Expand Down Expand Up @@ -169,11 +169,17 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er
return nil // Success - message will be acked
}

func (c *Controller) failRequest(ctx context.Context, store orchstorage.Storage, request entity.Request, reason string) error {
_, err := corerequest.TerminateRequest(ctx, store, c.registry, request.ID, entity.RequestStateError, reason, nil)
func (c *Controller) failRequest(ctx context.Context, store orchstorage.Storage, request entity.Request, result *runwaymq.MergeResult) error {
reason, metadata := failure(result)
_, err := corerequest.TerminateRequest(ctx, store, c.registry, request.ID, entity.RequestStateError, reason, metadata)
return err
}

// failure is the reason and request log metadata a failed check result gives its request.
func failure(result *runwaymq.MergeResult) (string, map[string]string) {
return result.Reason, entity.FailureCategoryMetadata(nil, entity.FailureCategoryLandFailed)
}

// publishRequestID publishes a request ID to the given topic key, stamped with
// and partitioned by the request's queue.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestProcess_NotLandableMarksRequestError(t *testing.T) {
assert.Equal(t, entity.RequestStatusError, logEntry.Status)
assert.Equal(t, int32(2), logEntry.RequestVersion)
assert.Equal(t, "conflict in foo.go", logEntry.LastError)
assert.Equal(t, string(entity.FailureCategoryLandFailed), logEntry.Metadata[entity.RequestLogMetadataKeyFailureCategory])
}

func TestFailRequest_UpdateFailureLeavesRequestUnchanged(t *testing.T) {
Expand All @@ -209,7 +210,7 @@ func TestFailRequest_UpdateFailureLeavesRequestUnchanged(t *testing.T) {
controller := NewController(zaptest.NewLogger(t).Sugar(), tally.NoopScope, storageFactory, consumer.TopicRegistry{},
runwaymq.TopicKeyMergeConflictCheckSignal, "orchestrator-landconflictsignal")

err := controller.failRequest(context.Background(), store, request, "conflict")
err := controller.failRequest(context.Background(), store, request, &runwaymq.MergeResult{Id: testRequestID, Outcome: runwaypb.Outcome_FAILED, Reason: "conflict"})
require.Error(t, err)
assert.Equal(t, entity.RequestStateStarted, request.State)
assert.Equal(t, int32(1), request.Version)
Expand Down Expand Up @@ -250,11 +251,13 @@ func TestProcess_ErrorRequestResendsTerminalLog(t *testing.T) {
name string
result runwaymq.MergeResult
wantLastError string
wantCategory entity.FailureCategory
}{
{
name: "a redelivered failure says why",
result: runwaymq.MergeResult{Id: testRequestID, Outcome: runwaypb.Outcome_FAILED, Reason: "conflict in foo.go"},
wantLastError: "conflict in foo.go",
wantCategory: entity.FailureCategoryLandFailed,
},
{
name: "a success cannot say why the request failed",
Expand Down Expand Up @@ -297,6 +300,7 @@ func TestProcess_ErrorRequestResendsTerminalLog(t *testing.T) {
assert.Equal(t, int32(2), logs[0].RequestVersion)
assert.Equal(t, tt.wantLastError, logs[0].LastError)
assert.Equal(t, "true", logs[0].Metadata[entity.RequestLogMetadataKeyResent])
assert.Equal(t, string(tt.wantCategory), logs[0].Metadata[entity.RequestLogMetadataKeyFailureCategory])
})
}
}
Loading
Loading