feat(controller): hooking up merge controller#105
Conversation
2cffebf to
e8b31bc
Compare
0815e08 to
ec6b0b5
Compare
e8b31bc to
bfbfc86
Compare
ec6b0b5 to
6c6c3e3
Compare
| // BatchStateLandFailed is the state of a batch that has failed to land. | ||
| BatchStateLandFailed BatchState = "land_failed" | ||
| // BatchStateLandSucceeded is the state of a batch that has successfully landed. | ||
| BatchStateLandSucceeded BatchState = "land_succeeded" |
There was a problem hiding this comment.
How does it differ from "succeeded" ?
There was a problem hiding this comment.
Removed land_failed and land_succeeded, they weren't necessary. Just artifacts from me trying to understand state transitions.
The merge controller now just updates the batch to the terminal states (succeeded and failed) for the "concluder" controller to pick up later.
| ) | ||
| c.metricsScope.Counter("idempotent_skip").Inc(1) | ||
| case entity.BatchStateLanding: | ||
| newState, err := c.land(ctx, batch) |
There was a problem hiding this comment.
It should also process the land error "already merged" for another idempotency check.
If it is for the future, add TODO comment.
There was a problem hiding this comment.
Added the IsAlreadyLanded error to the interface in a previous PR in the stack and hooked it up to the land function
bfbfc86 to
c78ac99
Compare
6c6c3e3 to
40bfe00
Compare
28f56d9 to
d9f72cd
Compare
b6bd849 to
bab9708
Compare
d511180 to
32190ca
Compare
bab9708 to
93bcc1f
Compare
| c.metricsScope.Counter("received").Inc(1) | ||
|
|
||
| msg := delivery.Message() | ||
| batchID := string(msg.Payload) |
There was a problem hiding this comment.
We need to define a serialization format for this. Using direct string-to-byte conversion is Golang-specific.
Probably a separate serializable structure.
| // previous attempt; skip straight to publish. | ||
| batch, err := c.storage.GetBatchStore().Get(ctx, batchID) | ||
| if err != nil { | ||
| c.logger.Errorw("failed to fetch batch", |
There was a problem hiding this comment.
as long as we return error to upstream, we do not have to log. Otherwise most likely we'll log twice.
Logging should happen at error chain termination (top-most) point.
| ) | ||
| c.metricsScope.Counter("publish_errors").Inc(1) | ||
| return errs.NewRetryableError(fmt.Errorf("failed to publish to merge-signal: %w", err)) | ||
| c.metricsScope.Counter("batch_fetch_errors").Inc(1) |
There was a problem hiding this comment.
plz rebase and integrate with new metrics infrastructure that processes errors automagically
| "error", err, | ||
| ) | ||
| c.metricsScope.Counter("batch_update_errors").Inc(1) | ||
| return errs.NewRetryableError(fmt.Errorf("failed to update batch state: %w", err)) |
There was a problem hiding this comment.
it should only be retryable if the error is expected type, like version mismatch, but we seem to retry on all of the errors? If the database is operational but "table does not exist" is the error, this is not retryable.
|
|
||
| batch.State = newState | ||
| } else { | ||
| c.logger.Infow("batch already in terminal state, skipping to publish", |
There was a problem hiding this comment.
may be a warning level, as this should only happen on infra errors
| err := c.landProvider.Land(ctx, batch.Queue, entries) | ||
|
|
||
| switch { | ||
| case err == nil, landprovider.IsAlreadyLanded(err): |
There was a problem hiding this comment.
may be at least log landprovider.IsAlreadyLanded, but better tally too?
this also should not happen for a normal workflow, so good to have some observability
also, comment here scenarios which could cause this
| "error", err, | ||
| ) | ||
| c.metricsScope.Counter("land_rejected").Inc(1) | ||
| return entity.BatchStateFailed, nil |
There was a problem hiding this comment.
we'll need to propagate the error information about why land was rejected. Can be done in another diff, but then needs a TODO comment.
Summary
feat(controller): hooking up merge controller
What?
Hooked up the merge controller with the land provider.
Also wired up the example server with the merge controller along with default github land provider.
Idempotency checks:
ErrIsAlreadyLanded, which is a happy path signal to set the batch to succeeded.ErrLandRejectedare retryable.Test Plan
Unit tests, CI
Issues
Stack