Skip to content
Draft
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
2 changes: 2 additions & 0 deletions stovepipe/entity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
"project_issue_attribution.go",
"project_issues.go",
"project_status.go",
"project_summary.go",
"queue.go",
"queue_log.go",
"queue_state.go",
Expand Down Expand Up @@ -49,6 +50,7 @@ go_test(
"issue_tracking_state_test.go",
"project_fact_by_degree_test.go",
"project_issue_attribution_test.go",
"project_summary_test.go",
"queue_state_test.go",
"request_id_test.go",
"request_issue_summary_test.go",
Expand Down
77 changes: 77 additions & 0 deletions stovepipe/entity/project_summary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 entity

import (
"fmt"
"math"

"github.com/uber/submitqueue/platform/base/id"
)

// ProjectSummary retains a project's latest applied state and any active breakage within a queue.
// A green summary does not imply that every later request assessed the project.
type ProjectSummary struct {
// Project identifies the project within the queue.
Project string
// Degree is the observed breakage degree in [0, 1]; zero is green.
Degree float64
// RequestID identifies the latest applied request in queue ingest order.
RequestID string
// ChangedAtMs is when this state was first recorded or last changed, in Unix milliseconds.
ChangedAtMs int64
// FirstBrokenRequestID identifies the current broken period; empty when green.
FirstBrokenRequestID string
// BrokenSinceMs is when the current broken period was recorded, in Unix milliseconds; zero when green.
BrokenSinceMs int64
// Version is the positive optimistic-lock version of this projection.
Version int32
}

func (s ProjectSummary) Validate() error {
if s.Project == "" {
return fmt.Errorf("project summary requires a project")
}

if math.IsNaN(s.Degree) || s.Degree < DegreeGreen || s.Degree > DegreeBroken {
return fmt.Errorf("project summary degree must be in [0, 1]")
}

if err := id.Validate(s.RequestID); err != nil {
return fmt.Errorf("invalid project summary request ID: %w", err)
}

if s.ChangedAtMs <= 0 || s.Version <= 0 {
return fmt.Errorf("project summary requires a positive transition timestamp and version")
}

if s.Degree == DegreeGreen {
if s.FirstBrokenRequestID != "" || s.BrokenSinceMs != 0 {
return fmt.Errorf("green project summary must not retain an active broken period")
}
return nil
}

order, err := id.Compare(s.FirstBrokenRequestID, s.RequestID)
if err != nil {
return fmt.Errorf("invalid project summary broken-period request ID: %w", err)
}

if order > 0 || s.BrokenSinceMs <= 0 {
return fmt.Errorf("project summary requires a positive broken timestamp and an opening no newer than its latest request")
}

return nil
}
72 changes: 72 additions & 0 deletions stovepipe/entity/project_summary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 entity

import (
"math"
"testing"

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

func TestProjectSummaryValidate(t *testing.T) {
for _, tt := range []struct {
name string
change func(*ProjectSummary)
invalid bool
}{
{name: "broken"},
{name: "partial", change: func(s *ProjectSummary) { s.Degree = DegreePartial }},
{name: "green without a broken period", change: func(s *ProjectSummary) {
s.Degree = DegreeGreen
s.FirstBrokenRequestID = ""
s.BrokenSinceMs = 0
}},
{name: "opening request", change: func(s *ProjectSummary) { s.FirstBrokenRequestID = s.RequestID }},
{name: "empty project", change: func(s *ProjectSummary) { s.Project = "" }, invalid: true},
{name: "negative degree", change: func(s *ProjectSummary) { s.Degree = -0.1 }, invalid: true},
{name: "degree above one", change: func(s *ProjectSummary) { s.Degree = 1.1 }, invalid: true},
{name: "not a number", change: func(s *ProjectSummary) { s.Degree = math.NaN() }, invalid: true},
{name: "positive infinity", change: func(s *ProjectSummary) { s.Degree = math.Inf(1) }, invalid: true},
{name: "negative infinity", change: func(s *ProjectSummary) { s.Degree = math.Inf(-1) }, invalid: true},
{name: "invalid request ID", change: func(s *ProjectSummary) { s.RequestID = "02" }, invalid: true},
{name: "invalid timestamp", change: func(s *ProjectSummary) { s.ChangedAtMs = 0 }, invalid: true},
{name: "invalid version", change: func(s *ProjectSummary) { s.Version = 0 }, invalid: true},
{name: "missing broken period", change: func(s *ProjectSummary) { s.FirstBrokenRequestID = "" }, invalid: true},
{name: "future broken period", change: func(s *ProjectSummary) { s.FirstBrokenRequestID = "3" }, invalid: true},
{name: "missing broken timestamp", change: func(s *ProjectSummary) { s.BrokenSinceMs = 0 }, invalid: true},
{name: "green with broken reference", change: func(s *ProjectSummary) {
s.Degree = DegreeGreen
s.BrokenSinceMs = 0
}, invalid: true},
{name: "green with broken timestamp", change: func(s *ProjectSummary) {
s.Degree = DegreeGreen
s.FirstBrokenRequestID = ""
}, invalid: true},
} {
t.Run(tt.name, func(t *testing.T) {
summary := ProjectSummary{Project: "service", Degree: DegreeBroken, RequestID: "2", ChangedAtMs: 1000,
FirstBrokenRequestID: "1", BrokenSinceMs: 1000, Version: 1}
if tt.change != nil {
tt.change(&summary)
}
if tt.invalid {
require.Error(t, summary.Validate())
} else {
require.NoError(t, summary.Validate())
}
})
}
}
1 change: 1 addition & 0 deletions stovepipe/extension/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"issue_tracking_store.go",
"open_issue_store.go",
"project_fact_by_degree_store.go",
"project_summary_store.go",
"queue_log_store.go",
"queue_store.go",
"queue_summary_store.go",
Expand Down
10 changes: 10 additions & 0 deletions stovepipe/extension/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ This is a separate contract from `submitqueue/extension/storage` — same shape

Entities that support concurrent mutation (`Request`, `Build`, `IssueState`, `IssueTrackingState`, `IssueRepair`) carry an `int32 Version` field. `Update` methods take both `oldVersion` (the where-clause guard) and `newVersion` (the value to write) — the store performs a pure conditional write and never computes `oldVersion + 1` itself. Version arithmetic is owned by the controller: it computes `newVersion`, calls `Update`, and only assigns `entity.Version = newVersion` after the call succeeds. See [AGENTS.md](../../../AGENTS.md) and the [submitqueue storage README](../../../submitqueue/extension/storage/README.md#optimistic-locking-contract) for the full rationale and the caller pattern — the convention is identical here.

## Project summaries

`ProjectSummaryStore` retains the latest applied project state and any active
broken-period start under `(queue, project)`. Green results can create summaries
without a previous breakage. A missing result alone does not establish recovery,
and a green summary does not establish coverage by later requests.
Callers own ordering, transitions, and version advancement. The store provides
conditional snapshot writes only; it does not populate summaries or change
immutable validation facts.

## Read-after-write consistency

A `Get` immediately following a successful write (`Create`/`Update`) — by the same caller, or a causally-dependent one such as a queue consumer processing a message published after the write committed — must return that write. This is a requirement on every storage implementation, not a condition callers negotiate around.
Expand Down
1 change: 1 addition & 0 deletions stovepipe/extension/storage/mock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"issue_tracking_store_mock.go",
"open_issue_store_mock.go",
"project_fact_by_degree_store_mock.go",
"project_summary_store_mock.go",
"queue_log_store_mock.go",
"queue_store_mock.go",
"queue_summary_store_mock.go",
Expand Down
85 changes: 85 additions & 0 deletions stovepipe/extension/storage/mock/project_summary_store_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions stovepipe/extension/storage/mock/storage_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions stovepipe/extension/storage/mysql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"issue_tracking_store.go",
"open_issue_store.go",
"project_fact_by_degree_store.go",
"project_summary_store.go",
"queue_log_store.go",
"queue_store.go",
"queue_summary_store.go",
Expand Down Expand Up @@ -53,6 +54,7 @@ go_test(
"issue_tracking_store_test.go",
"open_issue_store_test.go",
"project_fact_by_degree_store_test.go",
"project_summary_store_test.go",
"queue_store_test.go",
"queue_summary_store_test.go",
"request_acceptance_store_test.go",
Expand Down
Loading