Repository navigation
fix(fault): make an injected fault targetable, bounded and indistinguishable (#480) - #511
Merged
Merged
Conversation
…ishable (#480) Four findings that compound into a fault fixture being silently wrong rather than merely limited. An S3 rule could not name a semantic operation. Faults evaluate at pipeline step 4.5, one step before the S3 plugin resolves the operation name, so req.Operation was still the bare HTTP verb: a rule on PutObject never fired, and a rule on PUT took out UploadPart with it. The parser now calls the already-pure parseS3Operation for s3 requests, so the operation is canonical from the start — which also fixes cost and consistency attribution for any request that errors before routing. A rule could not be bounded, so recovery was unobservable. FaultRule.Times bounds a rule to N occurrences, and zero means one rather than unlimited: fail twice then succeed is the outcome that distinguishes working retry from no retry, and reading a mistyped zero as unlimited consumes the whole retry budget. A negative value asks for unlimited explicitly. A rule that matched nothing looked exactly like a consumer's retry working. Per-rule Fired counts surface through GET /v1/fault/rules and FaultsFired(); the match, the probability roll and the increment now happen under one lock, so Times: 1 with N concurrent requests produces exactly one failure. An injected S3 error was distinguishable from a real one — the one property a fault injector must not have. marshalAWSError emitted the Query protocol's <ErrorResponse> wrapper where genuine S3 errors are a bare <Error> with an XML declaration and a <RequestId>, so an SDK could not read the code out and fell back to the HTTP status: a requested SlowDown arrived as ServiceUnavailable. errProtoS3XML delegates to s3ErrorResponseWith, keeping that function the single source of the byte shape. cloudfront and route53 are REST-XML too but their real documents are wrapped, so they stay on the Query arm; EC2 and SQS are unchanged. PathSuffix, QueryKey and HeaderPrefix target the wire request within an operation — QueryKey is what separates the multipart sub-operations, which makes #480's own "assert no orphaned upload" test writable. Closes #480
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #480
Four findings from #480, taken in the reporter's own priority order. They
compound: together they mean an armed S3 fault often fires on the wrong request,
or fires and cannot be told apart from a real error — and a test that arms one
and sees success has proven nothing.
Finding 1 — an S3 rule could not name a semantic operation
Faults evaluate at
server.go's step 4.5 againstreq.Operation; the S3 pluginassigns the semantic name at step 5, one step later. So the fault matcher saw the
bare HTTP verb: a rule on
PutObjectnever fired, and a rule onPUTtook outUploadParttoo.The reporter asked for both of their options, and both are right:
extractOperationnow calls the already-pureparseS3Operationwhenservice == "s3", soreq.Operationis canonical fromthe start. This also fixes cost and consistency attribution for any request
that errors before routing, which is wider than faults. The S3 plugin keeps its
parseS3Operationcall (it is howbucket/keyare derived) and drops themutation.
PathSuffix,QueryKeyandHeaderPrefixtarget the wirerequest within an operation, AND-ed with
Service/Operation.QueryKeyiswhat separates the multipart sub-operations (
uploadsvsuploadIdvspartNumber), which is what makes the reporter's own previously-unwritabletest — "Complete fails after all parts uploaded, assert no orphaned upload" —
writable. It is written.
Option 2 had to land with option 3, because
QueryKeyis only useful onceoperations are named correctly.
Finding 2 — no occurrence bound, and no way to know a rule fired
FaultRule.Timesbounds a rule to N occurrences. Zero means one, notunlimited: fail twice then succeed is the outcome that distinguishes working
retry from no retry, an unbounded rule can only ever produce failure, and reading
a mistyped zero as unlimited consumes the whole retry budget. A negative value
asks for unlimited explicitly.
Per-rule
Firedcounts surface through the existingGET /v1/fault/rules(afield, not a new endpoint) and a
FaultsFired()accessor. The reporter's point isthe one that matters: a rule matching nothing produces exactly the same passing
test as a consumer's retry working, and finding 1 would have been caught instantly
by any test asserting a non-zero count.
The match, the probability roll and the increment now happen under one lock —
InjectFaultpreviously tookRLockto snapshot the config and a separate writelock for the roll, which is a race for a counter. With
Times: 1, N concurrentrequests must produce exactly one failure, and that atomicity is what a
client-side counter cannot provide.
Findings 3 and 4 — an injected error was distinguishable from a real one
Finding 4 causes finding 3, and this is the one property a fault injector must
not have.
marshalAWSError's default arm emitted the Query protocol's<ErrorResponse><Error><Type>Sender</Type>…document, while genuine S3 errorscome from
s3ErrorResponseWithas a bare<Error>with an XML declaration and a<RequestId>. The SDK could not read the code out of the wrong shape, so it fellback to the HTTP status: a requested
SlowDownarrived asServiceUnavailable.Fixed at the marshaller.
errProtoS3XMLbuilds the document by callings3ErrorResponseWith, so that function stays the single source of truth for thebyte shape —
error_protocol.go's existing "plugins that need a byte-exactdocument build it themselves" pointer is now real rather than aspirational.
cloudfrontandroute53are REST-XML too and share the Query arm, but theirreal error documents are
<ErrorResponse>, so they are correct where they areand this PR does not sweep them along. The map says so, since the next reader
will wonder.
Also
FaultRule.Probability's PRNG is shared across every rule in a config, so a rollfor any rule advances it for all and a fixed seed reproduces a run only while the
sequence of requests is unchanged. Confirmed, documented, and filed as #510 —
per-rule PRNGs would change existing seeded behaviour, so it is not changed here.
Fixed along the way:
NewFaultControllerandUpdateConfigstored the caller'srule slice, so incrementing a count reached into the caller's own literal and a
config armed twice started its second arming already spent.
Tests
PutObjectfires onPutObjectand not onUploadPart; a ruleon
GETno longer matches an S3 request, which is the deliberate compatibilitybreak.
QueryKey: uploadshitsCreateMultipartUploadand notUploadPart; theorphaned-upload test the reporter could not write.
PathSuffixandHeaderPrefixeach select, and every matcher ANDs — assertedfrom both sides, so a matching wire matcher cannot rescue a wrong operation.
Times: 2→ two failures then success;Timesabsent → exactly one,asserted deliberately because it is a choice; negative → unlimited.
Times: 1with 10 parallel requests → exactly one failure, under-race.GET /v1/fault/rulesreportsfired; a rule that matched nothing reports0.error_code: SlowDownarrives at the client asSlowDown, and the raw body isbyte-identical to a genuine
NoSuchKeydocument modulo the code andmessage — asserted two ways, since the byte comparison is the only assertion
that proves indistinguishability.
fault-armed server with no plugins registered at all.
TestServer_PluginError_ReturnsAWSErrorwas asserting the wrapped shape for anS3 plugin error; it now asserts the bare
<Error>and its<RequestId>, whichis the fix's point.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0issues),
make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go test -C test/e2e ./...— allclean.
Mutation-tested at 32 mutants: 31 caught, 1 proven equivalent, 0 survived.
-raceis part of that harness's gate rather than an extra, because theatomicity mutants are only detectable as a reported race. Four mutants survived
the first run and produced four new tests (
ErrorDefaults,UpdateConfigDoesNotMutateTheCallersRules, and twoWireMatchersrows for anexplicitly-empty query value and for the AND asserted from the operation side).
The one equivalent mutant carries a written proof:
parseS3Operationreturns""only whenreq.Operationis already"", so the guard it removes can neversuppress a write that would change anything.
End to end through the AWS CLI against
substrate server:The injected document on the wire, beside a genuine one:
And the semantic-operation fix, both requests being
PUT: