diff --git a/stovepipe/core/queueconfig/BUILD.bazel b/stovepipe/core/queueconfig/BUILD.bazel new file mode 100644 index 000000000..da2802cee --- /dev/null +++ b/stovepipe/core/queueconfig/BUILD.bazel @@ -0,0 +1,34 @@ +load("@rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = [ + "build_analysis.go", + "build_signal.go", + "config.go", + "duration.go", + "issue_track.go", + "process.go", + ], + importpath = "github.com/uber/submitqueue/stovepipe/core/queueconfig", + visibility = ["//visibility:public"], + deps = ["//stovepipe/entity:go_default_library"], +) + +go_test( + name = "go_default_test", + srcs = [ + "build_analysis_test.go", + "build_signal_test.go", + "config_test.go", + "duration_test.go", + "issue_track_test.go", + "process_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//stovepipe/entity:go_default_library", + "@com_github_stretchr_testify//assert:go_default_library", + "@com_github_stretchr_testify//require:go_default_library", + ], +) diff --git a/stovepipe/core/queueconfig/build_analysis.go b/stovepipe/core/queueconfig/build_analysis.go new file mode 100644 index 000000000..834fbb0ae --- /dev/null +++ b/stovepipe/core/queueconfig/build_analysis.go @@ -0,0 +1,42 @@ +// 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 queueconfig + +import ( + "fmt" + "time" + + "github.com/uber/submitqueue/stovepipe/entity" +) + +// BuildAnalysisOverrides contains optional configuration for the build-analysis stage. +// Nil fields inherit their previous value; explicit values are retained for validation. +type BuildAnalysisOverrides struct { + // PollDelay overrides the interval between successful analysis passes using whole milliseconds. + PollDelay *time.Duration `yaml:"pollDelay"` +} + +// Apply copies base and replaces explicitly supplied settings. +// Durations that cannot be represented as whole milliseconds return an error. +func (o BuildAnalysisOverrides) Apply(base entity.BuildAnalysisConfig) (entity.BuildAnalysisConfig, error) { + pollDelayMs, err := durationMilliseconds(o.PollDelay, base.PollDelayMs) + if err != nil { + return entity.BuildAnalysisConfig{}, fmt.Errorf("pollDelay: %w", err) + } + + base.PollDelayMs = pollDelayMs + + return base, nil +} diff --git a/stovepipe/core/queueconfig/build_analysis_test.go b/stovepipe/core/queueconfig/build_analysis_test.go new file mode 100644 index 000000000..69670872b --- /dev/null +++ b/stovepipe/core/queueconfig/build_analysis_test.go @@ -0,0 +1,55 @@ +// 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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/stovepipe/entity" +) + +func TestBuildAnalysisOverridesApply(t *testing.T) { + base := entity.BuildAnalysisConfig{ + PollDelayMs: 10, + } + + inherited, err := (BuildAnalysisOverrides{}).Apply(base) + require.NoError(t, err) + assert.Equal(t, base, inherited) + + t.Run("PollDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := BuildAnalysisOverrides{PollDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.PollDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.PollDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.PollDelayMs) + }) +} diff --git a/stovepipe/core/queueconfig/build_signal.go b/stovepipe/core/queueconfig/build_signal.go new file mode 100644 index 000000000..826eb0acc --- /dev/null +++ b/stovepipe/core/queueconfig/build_signal.go @@ -0,0 +1,52 @@ +// 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 queueconfig + +import ( + "fmt" + "time" + + "github.com/uber/submitqueue/stovepipe/entity" +) + +// BuildSignalOverrides contains optional configuration for the build-signal stage. +// Nil fields inherit their previous value; explicit values are retained for validation. +type BuildSignalOverrides struct { + // AcceptedPollDelay overrides the polling interval for accepted builds using whole milliseconds. + AcceptedPollDelay *time.Duration `yaml:"acceptedPollDelay"` + + // RunningPollDelay overrides the polling interval for running builds using whole milliseconds. + RunningPollDelay *time.Duration `yaml:"runningPollDelay"` +} + +// Apply copies base and replaces explicitly supplied settings. +// Durations that cannot be represented as whole milliseconds return an error. +func (o BuildSignalOverrides) Apply(base entity.BuildSignalConfig) (entity.BuildSignalConfig, error) { + acceptedPollDelayMs, err := durationMilliseconds(o.AcceptedPollDelay, base.AcceptedPollDelayMs) + if err != nil { + return entity.BuildSignalConfig{}, fmt.Errorf("acceptedPollDelay: %w", err) + } + + base.AcceptedPollDelayMs = acceptedPollDelayMs + + runningPollDelayMs, err := durationMilliseconds(o.RunningPollDelay, base.RunningPollDelayMs) + if err != nil { + return entity.BuildSignalConfig{}, fmt.Errorf("runningPollDelay: %w", err) + } + + base.RunningPollDelayMs = runningPollDelayMs + + return base, nil +} diff --git a/stovepipe/core/queueconfig/build_signal_test.go b/stovepipe/core/queueconfig/build_signal_test.go new file mode 100644 index 000000000..8125ea24d --- /dev/null +++ b/stovepipe/core/queueconfig/build_signal_test.go @@ -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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/stovepipe/entity" +) + +func TestBuildSignalOverridesApply(t *testing.T) { + base := entity.BuildSignalConfig{ + AcceptedPollDelayMs: 10, + RunningPollDelayMs: 11, + } + + inherited, err := (BuildSignalOverrides{}).Apply(base) + require.NoError(t, err) + assert.Equal(t, base, inherited) + + t.Run("AcceptedPollDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := BuildSignalOverrides{AcceptedPollDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.AcceptedPollDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.AcceptedPollDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.AcceptedPollDelayMs) + }) + + t.Run("RunningPollDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := BuildSignalOverrides{RunningPollDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.RunningPollDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.RunningPollDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.RunningPollDelayMs) + }) +} diff --git a/stovepipe/core/queueconfig/config.go b/stovepipe/core/queueconfig/config.go new file mode 100644 index 000000000..3c3297bd7 --- /dev/null +++ b/stovepipe/core/queueconfig/config.go @@ -0,0 +1,68 @@ +// 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 queueconfig + +import ( + "fmt" + + "github.com/uber/submitqueue/stovepipe/entity" +) + +// Overrides contains optional configuration grouped by stage. +// Apply does not validate partial layers; validate the resolved result instead. +type Overrides struct { + // Process contains optional configuration for the process stage. + Process ProcessOverrides `yaml:"process"` + + // BuildSignal contains optional configuration for the build-signal stage. + BuildSignal BuildSignalOverrides `yaml:"buildSignal"` + + // BuildAnalysis contains optional configuration for the build-analysis stage. + BuildAnalysis BuildAnalysisOverrides `yaml:"buildAnalysis"` + + // IssueTrack contains optional configuration for the issue-tracking stage. + IssueTrack IssueTrackOverrides `yaml:"issueTrack"` +} + +// Apply copies base and applies each stage's overrides. +// Durations that cannot be represented as whole milliseconds return an error. +func (o Overrides) Apply(base entity.StageConfig) (entity.StageConfig, error) { + process, err := o.Process.Apply(base.Process) + if err != nil { + return entity.StageConfig{}, fmt.Errorf("process: %w", err) + } + + buildSignal, err := o.BuildSignal.Apply(base.BuildSignal) + if err != nil { + return entity.StageConfig{}, fmt.Errorf("buildSignal: %w", err) + } + + buildAnalysis, err := o.BuildAnalysis.Apply(base.BuildAnalysis) + if err != nil { + return entity.StageConfig{}, fmt.Errorf("buildAnalysis: %w", err) + } + + issueTrack, err := o.IssueTrack.Apply(base.IssueTrack) + if err != nil { + return entity.StageConfig{}, fmt.Errorf("issueTrack: %w", err) + } + + return entity.StageConfig{ + Process: process, + BuildSignal: buildSignal, + BuildAnalysis: buildAnalysis, + IssueTrack: issueTrack, + }, nil +} diff --git a/stovepipe/core/queueconfig/config_test.go b/stovepipe/core/queueconfig/config_test.go new file mode 100644 index 000000000..04639e71c --- /dev/null +++ b/stovepipe/core/queueconfig/config_test.go @@ -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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/stovepipe/entity" +) + +func TestOverridesComposeAllStages(t *testing.T) { + concurrency := int32(2) + admission, accepted, running := 11*time.Millisecond, 12*time.Millisecond, 13*time.Millisecond + analysis, refresh, recovery := 14*time.Millisecond, 15*time.Millisecond, 16*time.Millisecond + overrides := Overrides{ + Process: ProcessOverrides{MaxConcurrent: &concurrency, GateWaitDelay: &admission}, + BuildSignal: BuildSignalOverrides{AcceptedPollDelay: &accepted, RunningPollDelay: &running}, + BuildAnalysis: BuildAnalysisOverrides{PollDelay: &analysis}, + IssueTrack: IssueTrackOverrides{RefreshDelay: &refresh, RecoveryWaitDelay: &recovery}, + } + var base entity.StageConfig + + got, err := overrides.Apply(base) + require.NoError(t, err) + require.NoError(t, got.Validate()) + assert.Equal(t, entity.StageConfig{}, base) + assert.Equal(t, concurrency, got.Process.MaxConcurrent) + assert.Equal(t, admission.Milliseconds(), got.Process.GateWaitDelayMs) + assert.Equal(t, accepted.Milliseconds(), got.BuildSignal.AcceptedPollDelayMs) + assert.Equal(t, running.Milliseconds(), got.BuildSignal.RunningPollDelayMs) + assert.Equal(t, analysis.Milliseconds(), got.BuildAnalysis.PollDelayMs) + assert.Equal(t, refresh.Milliseconds(), got.IssueTrack.RefreshDelayMs) + assert.Equal(t, recovery.Milliseconds(), got.IssueTrack.RecoveryWaitDelayMs) + + inherited, err := (Overrides{}).Apply(got) + require.NoError(t, err) + assert.Equal(t, got, inherited) +} + +func TestOverridesRejectFractionalMilliseconds(t *testing.T) { + fractional := time.Microsecond + + for _, tt := range []struct { + name string + overrides Overrides + }{ + {"process", Overrides{Process: ProcessOverrides{GateWaitDelay: &fractional}}}, + {"build signal", Overrides{BuildSignal: BuildSignalOverrides{RunningPollDelay: &fractional}}}, + {"build analysis", Overrides{BuildAnalysis: BuildAnalysisOverrides{PollDelay: &fractional}}}, + {"issue tracking", Overrides{IssueTrack: IssueTrackOverrides{RecoveryWaitDelay: &fractional}}}, + } { + t.Run(tt.name, func(t *testing.T) { + _, err := tt.overrides.Apply(entity.StageConfig{}) + require.Error(t, err) + }) + } +} diff --git a/stovepipe/core/queueconfig/duration.go b/stovepipe/core/queueconfig/duration.go new file mode 100644 index 000000000..59b3806e6 --- /dev/null +++ b/stovepipe/core/queueconfig/duration.go @@ -0,0 +1,32 @@ +// 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 queueconfig + +import ( + "fmt" + "time" +) + +func durationMilliseconds(value *time.Duration, fallback int64) (int64, error) { + if value == nil { + return fallback, nil + } + + if *value%time.Millisecond != 0 { + return 0, fmt.Errorf("duration must use whole milliseconds") + } + + return value.Milliseconds(), nil +} diff --git a/stovepipe/core/queueconfig/duration_test.go b/stovepipe/core/queueconfig/duration_test.go new file mode 100644 index 000000000..174752fe3 --- /dev/null +++ b/stovepipe/core/queueconfig/duration_test.go @@ -0,0 +1,54 @@ +// 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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestDurationMilliseconds(t *testing.T) { + inherited, err := durationMilliseconds(nil, 123) + require.NoError(t, err) + assert.Equal(t, int64(123), inherited) + + for _, tt := range []struct { + name string + value time.Duration + want int64 + wantErr bool + }{ + {"milliseconds", 250 * time.Millisecond, 250, false}, + {"seconds", 2 * time.Second, 2000, false}, + {"zero is explicit", 0, 0, false}, + {"negative retained for validation", -time.Second, -1000, false}, + {"submillisecond", time.Microsecond, 0, true}, + {"fractional millisecond", time.Millisecond + time.Microsecond, 0, true}, + } { + t.Run(tt.name, func(t *testing.T) { + got, err := durationMilliseconds(&tt.value, 123) + if tt.wantErr { + require.Error(t, err) + return + } + + require.NoError(t, err) + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/stovepipe/core/queueconfig/issue_track.go b/stovepipe/core/queueconfig/issue_track.go new file mode 100644 index 000000000..bccfa95f0 --- /dev/null +++ b/stovepipe/core/queueconfig/issue_track.go @@ -0,0 +1,52 @@ +// 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 queueconfig + +import ( + "fmt" + "time" + + "github.com/uber/submitqueue/stovepipe/entity" +) + +// IssueTrackOverrides contains optional configuration for the issue-tracking stage. +// Nil fields inherit their previous value; explicit values are retained for validation. +type IssueTrackOverrides struct { + // RefreshDelay overrides the interval between refreshes using whole milliseconds. + RefreshDelay *time.Duration `yaml:"refreshDelay"` + + // RecoveryWaitDelay overrides the wait during recovery using whole milliseconds. + RecoveryWaitDelay *time.Duration `yaml:"recoveryWaitDelay"` +} + +// Apply copies base and replaces explicitly supplied settings. +// Durations that cannot be represented as whole milliseconds return an error. +func (o IssueTrackOverrides) Apply(base entity.IssueTrackConfig) (entity.IssueTrackConfig, error) { + refreshDelayMs, err := durationMilliseconds(o.RefreshDelay, base.RefreshDelayMs) + if err != nil { + return entity.IssueTrackConfig{}, fmt.Errorf("refreshDelay: %w", err) + } + + base.RefreshDelayMs = refreshDelayMs + + recoveryWaitDelayMs, err := durationMilliseconds(o.RecoveryWaitDelay, base.RecoveryWaitDelayMs) + if err != nil { + return entity.IssueTrackConfig{}, fmt.Errorf("recoveryWaitDelay: %w", err) + } + + base.RecoveryWaitDelayMs = recoveryWaitDelayMs + + return base, nil +} diff --git a/stovepipe/core/queueconfig/issue_track_test.go b/stovepipe/core/queueconfig/issue_track_test.go new file mode 100644 index 000000000..c162976ef --- /dev/null +++ b/stovepipe/core/queueconfig/issue_track_test.go @@ -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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/stovepipe/entity" +) + +func TestIssueTrackOverridesApply(t *testing.T) { + base := entity.IssueTrackConfig{ + RefreshDelayMs: 10, + RecoveryWaitDelayMs: 11, + } + + inherited, err := (IssueTrackOverrides{}).Apply(base) + require.NoError(t, err) + assert.Equal(t, base, inherited) + + t.Run("RefreshDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := IssueTrackOverrides{RefreshDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.RefreshDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.RefreshDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.RefreshDelayMs) + }) + + t.Run("RecoveryWaitDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := IssueTrackOverrides{RecoveryWaitDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.RecoveryWaitDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.RecoveryWaitDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.RecoveryWaitDelayMs) + }) +} diff --git a/stovepipe/core/queueconfig/process.go b/stovepipe/core/queueconfig/process.go new file mode 100644 index 000000000..0bf41a785 --- /dev/null +++ b/stovepipe/core/queueconfig/process.go @@ -0,0 +1,49 @@ +// 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 queueconfig + +import ( + "fmt" + "time" + + "github.com/uber/submitqueue/stovepipe/entity" +) + +// ProcessOverrides contains optional configuration for the process stage. +// Nil fields inherit their previous value; explicit values are retained for validation. +type ProcessOverrides struct { + // MaxConcurrent overrides the concurrent validation limit. + MaxConcurrent *int32 `yaml:"maxConcurrent"` + + // GateWaitDelay overrides the wait for admission using whole milliseconds. + GateWaitDelay *time.Duration `yaml:"gateWaitDelay"` +} + +// Apply copies base and replaces explicitly supplied settings. +// Durations that cannot be represented as whole milliseconds return an error. +func (o ProcessOverrides) Apply(base entity.ProcessConfig) (entity.ProcessConfig, error) { + if o.MaxConcurrent != nil { + base.MaxConcurrent = *o.MaxConcurrent + } + + gateWaitDelayMs, err := durationMilliseconds(o.GateWaitDelay, base.GateWaitDelayMs) + if err != nil { + return entity.ProcessConfig{}, fmt.Errorf("gateWaitDelay: %w", err) + } + + base.GateWaitDelayMs = gateWaitDelayMs + + return base, nil +} diff --git a/stovepipe/core/queueconfig/process_test.go b/stovepipe/core/queueconfig/process_test.go new file mode 100644 index 000000000..ab9e30404 --- /dev/null +++ b/stovepipe/core/queueconfig/process_test.go @@ -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 queueconfig + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/stovepipe/entity" +) + +func TestProcessOverridesApply(t *testing.T) { + base := entity.ProcessConfig{ + MaxConcurrent: 10, + GateWaitDelayMs: 11, + } + + inherited, err := (ProcessOverrides{}).Apply(base) + require.NoError(t, err) + assert.Equal(t, base, inherited) + + t.Run("MaxConcurrent", func(t *testing.T) { + value := int32(25) + original := base + override := ProcessOverrides{MaxConcurrent: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.MaxConcurrent = value + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int32(25), got.MaxConcurrent) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.MaxConcurrent) + }) + + t.Run("GateWaitDelay", func(t *testing.T) { + value := 25 * time.Millisecond + original := base + override := ProcessOverrides{GateWaitDelay: &value} + + got, err := override.Apply(base) + require.NoError(t, err) + want := base + want.GateWaitDelayMs = value.Milliseconds() + + assert.Equal(t, want, got) + assert.Equal(t, original, base) + + value = 0 + assert.Equal(t, int64(25), got.GateWaitDelayMs) + + zero, err := override.Apply(base) + require.NoError(t, err) + assert.Zero(t, zero.GateWaitDelayMs) + }) +} diff --git a/stovepipe/entity/BUILD.bazel b/stovepipe/entity/BUILD.bazel index 1dad63104..90c504523 100644 --- a/stovepipe/entity/BUILD.bazel +++ b/stovepipe/entity/BUILD.bazel @@ -4,17 +4,21 @@ go_library( name = "go_default_library", srcs = [ "build.go", + "build_analysis_config.go", "build_issue.go", + "build_signal_config.go", "get_issues_by_request_id.go", "ingest.go", "issue_log.go", "issue_repair.go", "issue_state.go", "issue_summary.go", + "issue_track_config.go", "issue_tracking_state.go", "list.go", "list_open_issues.go", "open_issue.go", + "process_config.go", "project_fact_by_degree.go", "project_issue_attribution.go", "project_issues.go", @@ -32,6 +36,7 @@ go_library( "request_issue_summary.go", "request_log.go", "request_summary.go", + "stage_config.go", "validation_fact.go", ], importpath = "github.com/uber/submitqueue/stovepipe/entity", @@ -42,11 +47,15 @@ go_library( go_test( name = "go_default_test", srcs = [ + "build_analysis_config_test.go", + "build_signal_config_test.go", "build_test.go", "issue_log_test.go", "issue_state_test.go", "issue_summary_test.go", + "issue_track_config_test.go", "issue_tracking_state_test.go", + "process_config_test.go", "project_fact_by_degree_test.go", "project_issue_attribution_test.go", "queue_state_test.go", @@ -54,6 +63,7 @@ go_test( "request_issue_summary_test.go", "request_log_test.go", "request_test.go", + "stage_config_test.go", "validation_fact_test.go", ], embed = [":go_default_library"], diff --git a/stovepipe/entity/build_analysis_config.go b/stovepipe/entity/build_analysis_config.go new file mode 100644 index 000000000..ccc2ed054 --- /dev/null +++ b/stovepipe/entity/build_analysis_config.go @@ -0,0 +1,32 @@ +// 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" + +// BuildAnalysisConfig contains configuration for the build-analysis stage. +type BuildAnalysisConfig struct { + // PollDelayMs is the positive interval between successful analysis passes, in milliseconds. + PollDelayMs int64 `json:"poll_delay_ms" yaml:"poll_delay_ms"` +} + +// Validate checks the build-analysis stage's configuration constraints. +func (c BuildAnalysisConfig) Validate() error { + if c.PollDelayMs <= 0 { + return fmt.Errorf("PollDelayMs must be positive, got %d", c.PollDelayMs) + } + + return nil +} diff --git a/stovepipe/entity/build_analysis_config_test.go b/stovepipe/entity/build_analysis_config_test.go new file mode 100644 index 000000000..6c2fdad9b --- /dev/null +++ b/stovepipe/entity/build_analysis_config_test.go @@ -0,0 +1,39 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBuildAnalysisConfigValidate(t *testing.T) { + valid := BuildAnalysisConfig{ + PollDelayMs: 10, + } + + require.NoError(t, valid.Validate()) + + t.Run("PollDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.PollDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + +} diff --git a/stovepipe/entity/build_signal_config.go b/stovepipe/entity/build_signal_config.go new file mode 100644 index 000000000..dd632d962 --- /dev/null +++ b/stovepipe/entity/build_signal_config.go @@ -0,0 +1,39 @@ +// 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" + +// BuildSignalConfig contains configuration for the build-signal stage. +type BuildSignalConfig struct { + // AcceptedPollDelayMs is the positive polling interval for accepted builds, in milliseconds. + AcceptedPollDelayMs int64 `json:"accepted_poll_delay_ms" yaml:"accepted_poll_delay_ms"` + + // RunningPollDelayMs is the positive polling interval for running builds, in milliseconds. + RunningPollDelayMs int64 `json:"running_poll_delay_ms" yaml:"running_poll_delay_ms"` +} + +// Validate checks the build-signal stage's configuration constraints. +func (c BuildSignalConfig) Validate() error { + if c.AcceptedPollDelayMs <= 0 { + return fmt.Errorf("AcceptedPollDelayMs must be positive, got %d", c.AcceptedPollDelayMs) + } + + if c.RunningPollDelayMs <= 0 { + return fmt.Errorf("RunningPollDelayMs must be positive, got %d", c.RunningPollDelayMs) + } + + return nil +} diff --git a/stovepipe/entity/build_signal_config_test.go b/stovepipe/entity/build_signal_config_test.go new file mode 100644 index 000000000..8b4df54cc --- /dev/null +++ b/stovepipe/entity/build_signal_config_test.go @@ -0,0 +1,49 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBuildSignalConfigValidate(t *testing.T) { + valid := BuildSignalConfig{ + AcceptedPollDelayMs: 10, + RunningPollDelayMs: 11, + } + + require.NoError(t, valid.Validate()) + + t.Run("AcceptedPollDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.AcceptedPollDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + + t.Run("RunningPollDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.RunningPollDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + +} diff --git a/stovepipe/entity/issue_track_config.go b/stovepipe/entity/issue_track_config.go new file mode 100644 index 000000000..a78b37faa --- /dev/null +++ b/stovepipe/entity/issue_track_config.go @@ -0,0 +1,39 @@ +// 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" + +// IssueTrackConfig contains configuration for the issue-tracking stage. +type IssueTrackConfig struct { + // RefreshDelayMs is the positive interval between refreshes, in milliseconds. + RefreshDelayMs int64 `json:"refresh_delay_ms" yaml:"refresh_delay_ms"` + + // RecoveryWaitDelayMs is the positive wait during recovery, in milliseconds. + RecoveryWaitDelayMs int64 `json:"recovery_wait_delay_ms" yaml:"recovery_wait_delay_ms"` +} + +// Validate checks the issue-tracking stage's configuration constraints. +func (c IssueTrackConfig) Validate() error { + if c.RefreshDelayMs <= 0 { + return fmt.Errorf("RefreshDelayMs must be positive, got %d", c.RefreshDelayMs) + } + + if c.RecoveryWaitDelayMs <= 0 { + return fmt.Errorf("RecoveryWaitDelayMs must be positive, got %d", c.RecoveryWaitDelayMs) + } + + return nil +} diff --git a/stovepipe/entity/issue_track_config_test.go b/stovepipe/entity/issue_track_config_test.go new file mode 100644 index 000000000..063bf7fe1 --- /dev/null +++ b/stovepipe/entity/issue_track_config_test.go @@ -0,0 +1,49 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIssueTrackConfigValidate(t *testing.T) { + valid := IssueTrackConfig{ + RefreshDelayMs: 10, + RecoveryWaitDelayMs: 11, + } + + require.NoError(t, valid.Validate()) + + t.Run("RefreshDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.RefreshDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + + t.Run("RecoveryWaitDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.RecoveryWaitDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + +} diff --git a/stovepipe/entity/process_config.go b/stovepipe/entity/process_config.go new file mode 100644 index 000000000..f45783312 --- /dev/null +++ b/stovepipe/entity/process_config.go @@ -0,0 +1,39 @@ +// 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" + +// ProcessConfig contains configuration for the process stage. +type ProcessConfig struct { + // MaxConcurrent is the positive concurrent validation limit. + MaxConcurrent int32 `json:"max_concurrent" yaml:"max_concurrent"` + + // GateWaitDelayMs is the positive wait for admission, in milliseconds. + GateWaitDelayMs int64 `json:"gate_wait_delay_ms" yaml:"gate_wait_delay_ms"` +} + +// Validate checks the process stage's configuration constraints. +func (c ProcessConfig) Validate() error { + if c.MaxConcurrent <= 0 { + return fmt.Errorf("MaxConcurrent must be positive, got %d", c.MaxConcurrent) + } + + if c.GateWaitDelayMs <= 0 { + return fmt.Errorf("GateWaitDelayMs must be positive, got %d", c.GateWaitDelayMs) + } + + return nil +} diff --git a/stovepipe/entity/process_config_test.go b/stovepipe/entity/process_config_test.go new file mode 100644 index 000000000..06899c41d --- /dev/null +++ b/stovepipe/entity/process_config_test.go @@ -0,0 +1,49 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestProcessConfigValidate(t *testing.T) { + valid := ProcessConfig{ + MaxConcurrent: 10, + GateWaitDelayMs: 11, + } + + require.NoError(t, valid.Validate()) + + t.Run("MaxConcurrent", func(t *testing.T) { + for _, value := range []int32{0, -1} { + cfg := valid + cfg.MaxConcurrent = value + + require.Error(t, cfg.Validate()) + } + }) + + t.Run("GateWaitDelayMs", func(t *testing.T) { + for _, value := range []int64{0, -1} { + cfg := valid + cfg.GateWaitDelayMs = value + + require.Error(t, cfg.Validate()) + } + }) + +} diff --git a/stovepipe/entity/stage_config.go b/stovepipe/entity/stage_config.go new file mode 100644 index 000000000..0e8cfa4f6 --- /dev/null +++ b/stovepipe/entity/stage_config.go @@ -0,0 +1,53 @@ +// 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" + +// StageConfig contains configuration for the validation pipeline stages. +type StageConfig struct { + // Process contains configuration for the process stage. + Process ProcessConfig `json:"process" yaml:"process"` + + // BuildSignal contains configuration for the build-signal stage. + BuildSignal BuildSignalConfig `json:"build_signal" yaml:"build_signal"` + + // BuildAnalysis contains configuration for the build-analysis stage. + BuildAnalysis BuildAnalysisConfig `json:"build_analysis" yaml:"build_analysis"` + + // IssueTrack contains configuration for the issue-tracking stage. + IssueTrack IssueTrackConfig `json:"issue_track" yaml:"issue_track"` +} + +// Validate checks each stage after all configuration layers have been applied. +func (c StageConfig) Validate() error { + if err := c.Process.Validate(); err != nil { + return fmt.Errorf("process: %w", err) + } + + if err := c.BuildSignal.Validate(); err != nil { + return fmt.Errorf("buildSignal: %w", err) + } + + if err := c.BuildAnalysis.Validate(); err != nil { + return fmt.Errorf("buildAnalysis: %w", err) + } + + if err := c.IssueTrack.Validate(); err != nil { + return fmt.Errorf("issueTrack: %w", err) + } + + return nil +} diff --git a/stovepipe/entity/stage_config_test.go b/stovepipe/entity/stage_config_test.go new file mode 100644 index 000000000..0125e27c1 --- /dev/null +++ b/stovepipe/entity/stage_config_test.go @@ -0,0 +1,52 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/require" +) + +func testStageConfig() StageConfig { + return StageConfig{ + Process: ProcessConfig{MaxConcurrent: 2, GateWaitDelayMs: 11}, + BuildSignal: BuildSignalConfig{AcceptedPollDelayMs: 12, RunningPollDelayMs: 13}, + BuildAnalysis: BuildAnalysisConfig{PollDelayMs: 14}, + IssueTrack: IssueTrackConfig{RefreshDelayMs: 15, RecoveryWaitDelayMs: 16}, + } +} + +func TestStageConfigValidatesEveryStage(t *testing.T) { + valid := testStageConfig() + require.NoError(t, valid.Validate()) + + for _, tt := range []struct { + name string + invalidate func(*StageConfig) + }{ + {"process", func(c *StageConfig) { c.Process = ProcessConfig{} }}, + {"build signal", func(c *StageConfig) { c.BuildSignal = BuildSignalConfig{} }}, + {"build analysis", func(c *StageConfig) { c.BuildAnalysis = BuildAnalysisConfig{} }}, + {"issue tracking", func(c *StageConfig) { c.IssueTrack = IssueTrackConfig{} }}, + } { + t.Run(tt.name, func(t *testing.T) { + cfg := valid + tt.invalidate(&cfg) + + require.Error(t, cfg.Validate()) + }) + } +}