-
Notifications
You must be signed in to change notification settings - Fork 4
feat(stovepipe): add the build stage controller #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
36e420a
feat(stovepipe): add build controller
roychying 1323036
fix(stovepipe): match reversed BuildRunner.Trigger arg order
roychying 085b753
fix(stovepipe): give build-strategy-not-visible its own metric
roychying 9753124
fix(stovepipe): treat request/queue not-found as non-retryable, not a…
roychying 84102e1
docs(storage): document read-after-write consistency requirement for …
roychying d804a33
docs(stovepipe): update build/process RFCs to match non-retryable not…
roychying bf87943
fix(stovepipe): log triggered build at debug instead of info level
roychying File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["build.go"], | ||
| importpath = "github.com/uber/submitqueue/stovepipe/controller/build", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//platform/base/messagequeue:go_default_library", | ||
| "//platform/consumer:go_default_library", | ||
| "//platform/errs:go_default_library", | ||
| "//platform/metrics:go_default_library", | ||
| "//stovepipe/core/messagequeue:go_default_library", | ||
| "//stovepipe/entity:go_default_library", | ||
| "//stovepipe/extension/buildrunner:go_default_library", | ||
| "//stovepipe/extension/storage:go_default_library", | ||
| "@com_github_uber_go_tally//:go_default_library", | ||
| "@org_uber_go_zap//:go_default_library", | ||
| ], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = ["build_test.go"], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "//platform/base/messagequeue:go_default_library", | ||
| "//platform/consumer:go_default_library", | ||
| "//platform/errs:go_default_library", | ||
| "//platform/extension/messagequeue/mock:go_default_library", | ||
| "//stovepipe/core/messagequeue:go_default_library", | ||
| "//stovepipe/entity:go_default_library", | ||
| "//stovepipe/extension/buildrunner:go_default_library", | ||
| "//stovepipe/extension/buildrunner/mock: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", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| // 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 build holds the build-stage queue controller. It consumes BuildRequest | ||
| // messages (a request id), reloads the Request, triggers the build-runner for | ||
| // the scope process already decided, persists a Build row, and publishes the | ||
| // build id to buildsignal. | ||
| package build | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/uber-go/tally" | ||
| entityqueue "github.com/uber/submitqueue/platform/base/messagequeue" | ||
| "github.com/uber/submitqueue/platform/consumer" | ||
| "github.com/uber/submitqueue/platform/errs" | ||
| "github.com/uber/submitqueue/platform/metrics" | ||
| stovepipemq "github.com/uber/submitqueue/stovepipe/core/messagequeue" | ||
| "github.com/uber/submitqueue/stovepipe/entity" | ||
| "github.com/uber/submitqueue/stovepipe/extension/buildrunner" | ||
| "github.com/uber/submitqueue/stovepipe/extension/storage" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // Controller consumes BuildRequest messages, reloads the referenced Request, | ||
| // triggers a build for its already-decided scope, and publishes the resulting | ||
| // build id to buildsignal. Implements consumer.Controller. | ||
| type Controller struct { | ||
| logger *zap.SugaredLogger | ||
| metricsScope tally.Scope | ||
| store storage.Storage | ||
| buildRunners buildrunner.Factory | ||
| registry consumer.TopicRegistry | ||
| topicKey consumer.TopicKey | ||
| consumerGroup string | ||
| } | ||
|
|
||
| // Verify Controller implements consumer.Controller interface at compile time. | ||
| var _ consumer.Controller = (*Controller)(nil) | ||
|
|
||
| // _opName is the metric operation name shared by every emit in this file. | ||
| const _opName = "build" | ||
|
|
||
| // NewController creates a new build controller. | ||
| func NewController( | ||
| logger *zap.SugaredLogger, | ||
| scope tally.Scope, | ||
| store storage.Storage, | ||
| buildRunners buildrunner.Factory, | ||
| registry consumer.TopicRegistry, | ||
| topicKey consumer.TopicKey, | ||
| consumerGroup string, | ||
| ) *Controller { | ||
| return &Controller{ | ||
| logger: logger.Named("build_controller"), | ||
| metricsScope: scope.SubScope("build_controller"), | ||
| store: store, | ||
| buildRunners: buildRunners, | ||
| registry: registry, | ||
| topicKey: topicKey, | ||
| consumerGroup: consumerGroup, | ||
| } | ||
| } | ||
|
|
||
| // Process reloads the request referenced by the delivery, triggers a build for | ||
| // its decided scope, and publishes the build id to buildsignal. Returns nil to | ||
| // ack (success) or an error to nack (retry) / reject (DLQ). | ||
| func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) (retErr error) { | ||
| op := metrics.Begin(c.metricsScope, _opName) | ||
| defer func() { op.Complete(retErr) }() | ||
|
|
||
| msg := delivery.Message() | ||
|
|
||
| br := &stovepipemq.BuildRequest{} | ||
| if err := stovepipemq.Unmarshal(msg.Payload, br); err != nil { | ||
| metrics.NamedCounter(c.metricsScope, _opName, "deserialize_errors", 1) | ||
| // Non-retryable: a malformed message will never succeed regardless of retries. | ||
| return fmt.Errorf("failed to deserialize build request: %w", err) | ||
| } | ||
|
|
||
| request, err := c.loadRequest(ctx, br.Id) | ||
| if err != nil { | ||
| metrics.NamedCounter(c.metricsScope, _opName, "storage_errors", 1) | ||
| return err | ||
| } | ||
|
|
||
| // A redelivery after record already finished, or after process superseded | ||
| // the head, must not start a fresh build. | ||
| if request.State.IsTerminal() { | ||
| return nil | ||
| } | ||
|
|
||
| buildRunner, err := c.buildRunners.For(buildrunner.Config{QueueName: request.Queue}) | ||
| if err != nil { | ||
| // A queue with no registered builder is a config error. | ||
| return fmt.Errorf("BuildController failed to resolve build runner for queue %s: %w", request.Queue, err) | ||
| } | ||
|
|
||
| // process decided the scope; build never re-derives incremental-vs-full. | ||
| if request.BuildStrategy == entity.BuildStrategyUnknown { | ||
| metrics.NamedCounter(c.metricsScope, _opName, "strategy_not_visible", 1) | ||
| return errs.NewRetryableError(fmt.Errorf("request %s has no build strategy yet", request.ID)) | ||
| } | ||
| baseURI := "" | ||
| if request.BuildStrategy == entity.BuildStrategyIncrementalSinceGreen { | ||
| baseURI = request.BaseURI | ||
| } | ||
|
|
||
| buildID, err := buildRunner.Trigger(ctx, baseURI, request.URI, nil) | ||
| if err != nil { | ||
| return fmt.Errorf("BuildController failed to trigger build for request %s: %w", request.ID, err) | ||
| } | ||
|
|
||
| build := entity.Build{ | ||
| ID: buildID.ID, | ||
| RequestID: request.ID, | ||
| Status: entity.BuildStatusAccepted, | ||
| Version: 1, | ||
| } | ||
| if err := c.store.GetBuildStore().Create(ctx, build); err != nil && !errors.Is(err, storage.ErrAlreadyExists) { | ||
| return fmt.Errorf("BuildController failed to persist build %s: %w", build.ID, err) | ||
| } | ||
|
|
||
| if err := c.publishBuildSignal(ctx, build.ID); err != nil { | ||
| return fmt.Errorf("BuildController failed to publish build signal for %s: %w", build.ID, err) | ||
| } | ||
|
|
||
| c.logger.Debugw("triggered build", | ||
| "request_id", request.ID, | ||
| "build_id", build.ID, | ||
| "queue", request.Queue, | ||
| "base_uri", baseURI, | ||
| ) | ||
| return nil | ||
| } | ||
|
|
||
| // loadRequest returns the request for id. | ||
| func (c *Controller) loadRequest(ctx context.Context, id string) (entity.Request, error) { | ||
| got, err := c.store.GetRequestStore().Get(ctx, id) | ||
| if err != nil { | ||
| return entity.Request{}, fmt.Errorf("BuildController failed to load request %s: %w", id, err) | ||
| } | ||
| return got, nil | ||
| } | ||
|
|
||
| // publishBuildSignal publishes buildID to the buildsignal stage, partitioned by | ||
| // build id so each build's poll loop runs in its own partition. | ||
| func (c *Controller) publishBuildSignal(ctx context.Context, buildID string) error { | ||
| payload, err := stovepipemq.Marshal(&stovepipemq.BuildSignal{Id: buildID}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to serialize build signal: %w", err) | ||
| } | ||
|
|
||
| msg := entityqueue.NewMessage(buildID, payload, buildID, nil) | ||
|
|
||
| q, ok := c.registry.Queue(stovepipemq.TopicKeyBuildSignal) | ||
| if !ok { | ||
| return fmt.Errorf("no queue registered for topic key %s", stovepipemq.TopicKeyBuildSignal) | ||
| } | ||
| topicName, ok := c.registry.TopicName(stovepipemq.TopicKeyBuildSignal) | ||
| if !ok { | ||
| return fmt.Errorf("no topic name registered for topic key %s", stovepipemq.TopicKeyBuildSignal) | ||
| } | ||
| return q.Publisher().Publish(ctx, topicName, msg) | ||
| } | ||
|
|
||
| // Name returns the controller name for logging and metrics. | ||
| func (c *Controller) Name() string { | ||
| return "build" | ||
| } | ||
|
|
||
| // TopicKey returns the topic key this controller subscribes to. | ||
| func (c *Controller) TopicKey() consumer.TopicKey { | ||
| return c.topicKey | ||
| } | ||
|
|
||
| // ConsumerGroup returns the consumer group for offset tracking. | ||
| func (c *Controller) ConsumerGroup() string { | ||
| return c.consumerGroup | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.