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: 2 additions & 2 deletions doc/rfc/stovepipe/steps/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Strategy and baseline are **immutable once processing**: a redelivery sees `proc

Validation is expensive and shares a baseline, so heads arriving while an earlier one runs `build → buildsignal → record` must not all start builds at once.

**Runtime state** lives on the Queue row; the **concurrency cap** does not — it is deployment configuration, resolved at gate-check time the same way SubmitQueue separates `storage` from `queueconfig` (see [submitqueue/extension/queueconfig/README.md](../../../../submitqueue/extension/queueconfig/README.md)): pipeline stages read mutable state from the store and read knobs like `max_concurrent` from a config `Store` (or a wiring default for MVP). Config is not written by ingest/process/record and does not need optimistic locking.
**Runtime state** lives on the Queue row; the **concurrency cap** does not — it is deployment configuration, resolved at gate-check time the same way SubmitQueue separates `storage` from `queueconfig` (see [submitqueue/extension/queueconfig/README.md](../../../../submitqueue/extension/queueconfig/README.md)): pipeline stages read mutable state from the store and read knobs like `max_concurrent` from a config `Store`. Config is not written by ingest/process/record and does not need optimistic locking.

| Source | Field | Meaning |
|---|---|---|
| Queue row | `last_green_uri` | Bookmark `buildsignal` advances on a successful build; empty until first green. |
| Queue row | `in_flight_count` | Requests past `process` and not yet terminal. `process` increments on admit; `record` (or DLQ reconciliation) decrements on terminal. |
| Queue config | `max_concurrent` | Cap on concurrent in-flight validations. **Default 1** (global wiring default for MVP; per-queue override when a Stovepipe `queueconfig` extension lands). |
| Queue config | `max_concurrent` | Cap on concurrent in-flight validations. **Default 1** in the shared stage configuration; optional shared and per-queue overrides live under the process stage configuration. |

A slot is held from admit until the build goes terminal (`process → build → buildsignal`), not just while `process` runs. It is released when the Request reaches **any** terminal state and `in_flight_count` is decremented — `buildsignal` recording the build's outcome, success *or* failure, or the DLQ reconciler forcing a terminal `failed` (see [integrity](#in_flight_count-integrity)). A build *failure* frees the slot just like a success; only a Request that never terminates keeps its slot.

Expand Down
9 changes: 9 additions & 0 deletions service/stovepipe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ The Stovepipe controllers live under [`stovepipe/controller/`](../../stovepipe/c
|---------------------|----------|------------------------------------------|----------------------|
| `STORAGE_MYSQL_DSN` | yes | Storage database DSN | — |
| `QUEUE_MYSQL_DSN` | yes | Queue database DSN | — |
| `MQ_TENANTS` | yes | Comma-separated queue names served by this instance | — |
| `QUEUE_LOG_LEVEL` | no | Message-queue logger level | `info` |
| `PORT` | no | gRPC listen address | `:8083` |
| `HOSTNAME` | no | Subscriber name for the queue consumers | `stovepipe-<unix_ts>` |

## Queue and stage configuration

`MQ_TENANTS` defines the queues served by this instance. Stage settings use built-in values unless overridden through a YAML file selected with `-config`.

The file supports shared settings under `stages` and optional per-queue overrides under `queues`. Omitted fields inherit shared settings or built-in values. Per-queue overrides must reference a registered queue.

Configuration is validated at startup; changes require a restart. See the [configuration provider](../../stovepipe/extension/queueconfig/README.md) for details.

## Running

### Docker Compose (recommended)
Expand Down
9 changes: 8 additions & 1 deletion service/stovepipe/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ go_library(
"//stovepipe/extension/fixer/noop:go_default_library",
"//stovepipe/extension/projectissues/noop:go_default_library",
"//stovepipe/extension/projectstatus/noop:go_default_library",
"//stovepipe/extension/queueconfig/default:go_default_library",
"//stovepipe/extension/queueconfig:go_default_library",
"//stovepipe/extension/queueconfig/yaml:go_default_library",
"//stovepipe/extension/sourcecontrol:go_default_library",
"//stovepipe/extension/sourcecontrol/fake:go_default_library",
"//stovepipe/extension/storage:go_default_library",
Expand Down Expand Up @@ -98,16 +99,22 @@ go_test(
"//platform/extension/messagequeue/mock:go_default_library",
"//stovepipe/controller/dlq:go_default_library",
"//stovepipe/core/messagequeue:go_default_library",
"//stovepipe/core/queueconfig:go_default_library",
"//stovepipe/core/requestlog:go_default_library",
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/buildissue/noop:go_default_library",
"//stovepipe/extension/queueconfig:go_default_library",
"//stovepipe/extension/queueconfig/mock:go_default_library",
"//stovepipe/extension/queueconfig/yaml:go_default_library",
"//stovepipe/extension/sourcecontrol:go_default_library",
"//stovepipe/extension/storage:go_default_library",
"//stovepipe/extension/storage/mock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
"@org_uber_go_zap//:go_default_library",
"@org_uber_go_zap//zaptest:go_default_library",
"@org_uber_go_zap//zaptest/observer:go_default_library",
],
)
60 changes: 50 additions & 10 deletions service/stovepipe/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"errors"
"flag"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -66,7 +67,8 @@ import (
fixernoop "github.com/uber/submitqueue/stovepipe/extension/fixer/noop"
projectissuesnoop "github.com/uber/submitqueue/stovepipe/extension/projectissues/noop"
projectstatusnoop "github.com/uber/submitqueue/stovepipe/extension/projectstatus/noop"
queueconfigdefault "github.com/uber/submitqueue/stovepipe/extension/queueconfig/default"
queueconfigprovider "github.com/uber/submitqueue/stovepipe/extension/queueconfig"
queueconfigyaml "github.com/uber/submitqueue/stovepipe/extension/queueconfig/yaml"
"github.com/uber/submitqueue/stovepipe/extension/sourcecontrol"
sourcecontrolfake "github.com/uber/submitqueue/stovepipe/extension/sourcecontrol/fake"
"github.com/uber/submitqueue/stovepipe/extension/storage"
Expand Down Expand Up @@ -122,8 +124,10 @@ func (hookResolver) For(*basehook.HookEvent) []hookext.Hook {
}

func main() {
configPath := flag.String("config", "", "optional path to Stovepipe stage settings and per-queue overrides")
flag.Parse()
code := 0
if err := run(); err != nil {
if err := run(*configPath); err != nil {
if errors.Is(err, context.Canceled) {
fmt.Println("Stovepipe server stopped by signal")

Expand All @@ -139,7 +143,7 @@ func main() {
os.Exit(code)
}

func run() error {
func run(configPath string) error {
// Set up signal handling early so retry loops can respond to SIGTERM
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
Expand All @@ -151,6 +155,18 @@ func run() error {
}
defer logger.Sync()

tenants, err := servicemq.ParseRequiredTenants(os.Getenv("MQ_TENANTS"))
if err != nil {
return fmt.Errorf("failed to configure queue subscribers: %w", err)
}

configs, err := queueconfigyaml.NewStore(configPath, tenants)
if err != nil {
return fmt.Errorf("load queue configurations: %w", err)
}

logEffectiveQueueConfigurations(ctx, logger, configs)

// Initialize metrics scope
scope := tally.NewTestScope("stovepipe", nil)
metricsStopCh := make(chan interface{}, 1)
Expand Down Expand Up @@ -213,11 +229,6 @@ func run() error {
return fmt.Errorf("failed to configure queue database pool: %w", err)
}

tenants, err := servicemq.ParseRequiredTenants(os.Getenv("MQ_TENANTS"))
if err != nil {
return fmt.Errorf("failed to configure queue subscribers: %w", err)
}

mysqlQueue, err := queueMySQL.NewQueue(queueMySQL.Params{
DB: queueDB,
Logger: logger,
Expand Down Expand Up @@ -271,7 +282,20 @@ func run() error {

storageFty := storageFactory{backend: store}
materializer := requestlog.NewMaterializer(scope)
primaryCount, err := registerPrimaryControllers(primaryConsumer, logger.Sugar(), scope, storageFty, materializer, registry, sourceControl, brf, hookResolver{}, detectorFactory, repairExecutors)
primaryCount, err := registerPrimaryControllers(
primaryConsumer,
logger.Sugar(),
scope,
storageFty,
materializer,
configs,
registry,
sourceControl,
brf,
hookResolver{},
detectorFactory,
repairExecutors,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -385,6 +409,21 @@ func run() error {
return err
}

func logEffectiveQueueConfigurations(ctx context.Context, logger *zap.Logger, configs queueconfigprovider.Store) {
resolved, err := configs.List(ctx)
if err != nil {
logger.Warn("failed to list effective queue configurations", zap.Error(err))
return
}

for _, cfg := range resolved {
logger.Info("queue configuration loaded",
zap.String("queue", cfg.Name),
zap.Any("stages", cfg.Stages),
)
}
}

// registerPrimaryControllers creates the primary-pipeline queue controllers and
// registers them with c, returning how many were registered.
func registerPrimaryControllers(
Expand All @@ -393,6 +432,7 @@ func registerPrimaryControllers(
scope tally.Scope,
store storage.Factory,
materializer requestlog.Materializer,
configs queueconfigprovider.Store,
registry consumer.TopicRegistry,
sourceControl sourcecontrol.Factory,
brf buildrunner.Factory,
Expand All @@ -407,7 +447,7 @@ func registerPrimaryControllers(
scope,
store,
materializer,
queueconfigdefault.NewStore(),
configs,
sourceControl,
registry,
stovepipemq.TopicKeyProcess,
Expand Down
93 changes: 88 additions & 5 deletions service/stovepipe/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ import (
queuemock "github.com/uber/submitqueue/platform/extension/messagequeue/mock"
"github.com/uber/submitqueue/stovepipe/controller/dlq"
stovepipemq "github.com/uber/submitqueue/stovepipe/core/messagequeue"
"github.com/uber/submitqueue/stovepipe/core/queueconfig"
"github.com/uber/submitqueue/stovepipe/core/requestlog"
"github.com/uber/submitqueue/stovepipe/entity"
buildissuenoop "github.com/uber/submitqueue/stovepipe/extension/buildissue/noop"
queueconfigprovider "github.com/uber/submitqueue/stovepipe/extension/queueconfig"
queueconfigmock "github.com/uber/submitqueue/stovepipe/extension/queueconfig/mock"
queueconfigyaml "github.com/uber/submitqueue/stovepipe/extension/queueconfig/yaml"
"github.com/uber/submitqueue/stovepipe/extension/sourcecontrol"
"github.com/uber/submitqueue/stovepipe/extension/storage"
storagemock "github.com/uber/submitqueue/stovepipe/extension/storage/mock"
"go.uber.org/mock/gomock"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"go.uber.org/zap/zaptest/observer"
)

// recordingConsumer captures what the host registers instead of subscribing.
Expand All @@ -54,11 +60,25 @@ func (c *recordingConsumer) Start(context.Context) error { return nil }

func (c *recordingConsumer) Stop(int64) error { return nil }

func testQueueConfigs(t *testing.T) queueconfigprovider.Store {
t.Helper()

configs, err := queueconfigyaml.NewStore("", []string{"monorepo/main"})
require.NoError(t, err)

return configs
}

// registeredControllers runs the host's registration exactly as run() does and
// returns the registry it registers against, the primary controllers, and the
// DLQ controllers.
func registeredControllers(t *testing.T) (consumer.TopicRegistry, []consumer.Controller, []consumer.Controller) {
t.Helper()
return registeredControllersWithConfig(t, testQueueConfigs(t))
}

func registeredControllersWithConfig(t *testing.T, configs queueconfigprovider.Store) (consumer.TopicRegistry, []consumer.Controller, []consumer.Controller) {
t.Helper()

registry, err := newTopicRegistry(nil, "subscriber")
require.NoError(t, err)
Expand All @@ -68,8 +88,20 @@ func registeredControllers(t *testing.T) (consumer.TopicRegistry, []consumer.Con
primary := &recordingConsumer{}
deadLetter := &recordingConsumer{}

_, err = registerPrimaryControllers(primary, logger, tally.NoopScope, store, requestlog.NewMaterializer(tally.NoopScope), registry,
&fakeSourceControlFactory{}, fakeBuildRunnerFactory{}, hookResolver{}, buildissuenoop.New(), noopRepairExecutorFactory{})
_, err = registerPrimaryControllers(
primary,
logger,
tally.NoopScope,
store,
requestlog.NewMaterializer(tally.NoopScope),
configs,
registry,
&fakeSourceControlFactory{},
fakeBuildRunnerFactory{},
hookResolver{},
buildissuenoop.New(),
noopRepairExecutorFactory{},
)
require.NoError(t, err)

_, err = registerDLQControllers(deadLetter, logger, tally.NoopScope, store, requestlog.NewMaterializer(tally.NoopScope), registry, noopRepairExecutorFactory{})
Expand Down Expand Up @@ -215,9 +247,20 @@ func TestRegisteredFixControllerRetainsPerExecutorDisposition(t *testing.T) {
registry, err := newTopicRegistry(queue, "subscriber")
require.NoError(t, err)
primary := &recordingConsumer{}
_, err = registerPrimaryControllers(primary, zaptest.NewLogger(t).Sugar(), tally.NoopScope, stores,
requestlog.NewMaterializer(tally.NoopScope), registry, &fakeSourceControlFactory{}, fakeBuildRunnerFactory{},
hookResolver{}, buildissuenoop.New(), noopRepairExecutorFactory{})
_, err = registerPrimaryControllers(
primary,
zaptest.NewLogger(t).Sugar(),
tally.NoopScope,
stores,
requestlog.NewMaterializer(tally.NoopScope),
testQueueConfigs(t),
registry,
&fakeSourceControlFactory{},
fakeBuildRunnerFactory{},
hookResolver{},
buildissuenoop.New(),
noopRepairExecutorFactory{},
)
require.NoError(t, err)
var fixController consumer.Controller
for _, controller := range primary.controllers {
Expand Down Expand Up @@ -348,3 +391,43 @@ func TestFakeSourceControlFactorySharesPromotionPerQueue(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, current)
}

func TestLogEffectiveQueueConfigurations(t *testing.T) {
for _, tt := range []struct {
name string
listError error
}{
{"resolved settings", nil},
{"lookup failure is a warning", assert.AnError},
} {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
provider := queueconfigmock.NewMockStore(ctrl)
configs := []queueconfig.QueueConfig{
{Name: "ordinary", Stages: queueconfig.DefaultStages()},
{Name: "fast", Stages: queueconfig.DefaultStages()},
}
configs[1].Stages.BuildAnalysis.PollDelayMs = 250
provider.EXPECT().List(gomock.Any()).Return(configs, tt.listError)
core, observed := observer.New(zap.InfoLevel)

logEffectiveQueueConfigurations(context.Background(), zap.New(core), provider)

entries := observed.All()
if tt.listError != nil {
require.Len(t, entries, 1)
assert.Equal(t, zap.WarnLevel, entries[0].Level)
assert.Contains(t, entries[0].ContextMap(), "error")
return
}

require.Len(t, entries, len(configs))
for i, cfg := range configs {
assert.Equal(t, zap.InfoLevel, entries[i].Level)
fields := entries[i].ContextMap()
assert.Equal(t, cfg.Name, fields["queue"])
assert.Equal(t, cfg.Stages, fields["stages"])
}
})
}
}
4 changes: 3 additions & 1 deletion stovepipe/controller/process/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"//stovepipe/core/hookevent:go_default_library",
"//stovepipe/core/loader:go_default_library",
"//stovepipe/core/messagequeue:go_default_library",
"//stovepipe/core/queueconfig:go_default_library",
"//stovepipe/core/requestlog:go_default_library",
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/queueconfig:go_default_library",
Expand Down Expand Up @@ -43,10 +44,11 @@ go_test(
"//platform/metrics:go_default_library",
"//stovepipe/core/hookevent:go_default_library",
"//stovepipe/core/messagequeue:go_default_library",
"//stovepipe/core/queueconfig:go_default_library",
"//stovepipe/core/requestlog:go_default_library",
"//stovepipe/core/requestlog/mock:go_default_library",
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/queueconfig/default:go_default_library",
"//stovepipe/extension/queueconfig/mock:go_default_library",
"//stovepipe/extension/sourcecontrol:go_default_library",
"//stovepipe/extension/sourcecontrol/mock:go_default_library",
"//stovepipe/extension/storage:go_default_library",
Expand Down
Loading
Loading