-
Notifications
You must be signed in to change notification settings - Fork 11
feat(stovepipe): add request logs for outcomes and lifecycle events #666
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import ( | |
| "github.com/uber/submitqueue/platform/publish" | ||
| "github.com/uber/submitqueue/stovepipe/core/loader" | ||
| stovepipemq "github.com/uber/submitqueue/stovepipe/core/messagequeue" | ||
| "github.com/uber/submitqueue/stovepipe/core/requestlog" | ||
| "github.com/uber/submitqueue/stovepipe/entity" | ||
| "github.com/uber/submitqueue/stovepipe/extension/buildrunner" | ||
| "github.com/uber/submitqueue/stovepipe/extension/storage" | ||
|
|
@@ -43,6 +44,7 @@ type Controller struct { | |
| logger *zap.SugaredLogger | ||
| metricsScope tally.Scope | ||
| stores storage.Factory | ||
| materializer requestlog.Materializer | ||
| buildRunners buildrunner.Factory | ||
| registry consumer.TopicRegistry | ||
| topicKey consumer.TopicKey | ||
|
|
@@ -60,6 +62,7 @@ func NewController( | |
| logger *zap.SugaredLogger, | ||
| scope tally.Scope, | ||
| stores storage.Factory, | ||
| materializer requestlog.Materializer, | ||
| buildRunners buildrunner.Factory, | ||
| registry consumer.TopicRegistry, | ||
| topicKey consumer.TopicKey, | ||
|
|
@@ -69,6 +72,7 @@ func NewController( | |
| logger: logger.Named("build_controller"), | ||
| metricsScope: scope.SubScope("build_controller"), | ||
| stores: stores, | ||
| materializer: materializer, | ||
| buildRunners: buildRunners, | ||
| registry: registry, | ||
| topicKey: topicKey, | ||
|
|
@@ -141,8 +145,11 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er | |
| Status: entity.BuildStatusAccepted, | ||
| Version: 1, | ||
| } | ||
| if err := store.GetBuildStore().Create(ctx, build); err != nil && !errors.Is(err, storage.ErrAlreadyExists) { | ||
| return fmt.Errorf("failed to persist build %s: %w", build.ID, err) | ||
| if err := c.persistBuild(ctx, store, build); err != nil { | ||
| return err | ||
| } | ||
| if err := c.persistBuildTriggered(ctx, store, request, build.ID); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := c.publishBuildSignal(ctx, build.ID, request.Queue); err != nil { | ||
|
|
@@ -158,6 +165,37 @@ func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) er | |
| return nil | ||
| } | ||
|
|
||
| func (c *Controller) persistBuild(ctx context.Context, store storage.Storage, build entity.Build) error { | ||
| buildStore := store.GetBuildStore() | ||
| if err := buildStore.Create(ctx, build); err == nil { | ||
| return nil | ||
| } else if !errors.Is(err, storage.ErrAlreadyExists) { | ||
| return fmt.Errorf("failed to persist build %s: %w", build.ID, err) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole workflow after this line deserves a quick explanation why we are doing it and what is a potential use case it is trying to validate |
||
| stored, err := buildStore.Get(ctx, build.ID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load existing build %s: %w", build.ID, err) | ||
| } | ||
| if stored.RequestID != build.RequestID { | ||
| return fmt.Errorf("build %s belongs to request %s, not %s", build.ID, stored.RequestID, build.RequestID) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Controller) persistBuildTriggered(ctx context.Context, store storage.Storage, request entity.Request, buildID string) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name of the function suggests it is somewhat similar to |
||
| log := requestlog.NewRequestEventLog( | ||
| request, | ||
| entity.RequestEventBuildTriggered, | ||
| buildID, | ||
| map[string]string{requestlog.MetadataKeyBuildID: buildID}, | ||
| ) | ||
| if err := c.materializer.PersistLog(ctx, store, log); err != nil { | ||
| return fmt.Errorf("failed to record build %s trigger for request %s: %w", buildID, request.ID, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // loadRequest returns the request for id. | ||
| func (c *Controller) loadRequest(ctx context.Context, store storage.Storage, id string) (entity.Request, error) { | ||
| return loader.ByID(ctx, id, store.GetRequestStore().Get, "request") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for else after return