Repository navigation
fix(sqs): warn on a stored attribute violation, still return the message (#491) - #513
Merged
Merged
Conversation
…age (#491) ReceiveMessage now logs at WARN when a stored message's attributes violate a rule sqsCheckMessageAttributes enforces on send, naming the queue, the message ID and the rule that was violated. The message is still returned, in full, exactly as stored. Returning it is the decision, not an omission. Substrate's core property is that replaying an event log reproduces the same observations, and a message written by an older substrate was accepted by the substrate that recorded it — so withholding or dropping it now would make a recorded run unreplayable, which is the one outcome #491 rules out. A receive-time rejection also has no AWS behaviour to imitate: real SQS never accepted the message, so there is no real response to copy. The warning gives an operator the signal that their fixture predates the rules without changing what any caller observes. Two scope choices are deliberate and tested. The whole stored attribute set is checked rather than the subset the request asked for, because the violation is a property of what is in state and #461's selection means a request naming no attribute names would otherwise hide it entirely. And it fires on every receive rather than once, because a message redelivered after its visibility timeout is a fixture being exercised again, and remembering which messages have already warned would be per-process state a replay could not reproduce. Send-time rejection is unchanged, so no new run can produce this state. Option 3 from the issue — a replay-time report of recorded data a current substrate would refuse — is the more principled home and is filed as #512.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
3 tasks
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 #491
ReceiveMessagenow logs atWARNwhen a stored message's attributes violate a rulesqsCheckMessageAttributesenforces on send, naming the queue, the message ID and the rule that was violated. The message is still returned, in full, exactly as stored.#491 is explicit that it is not a "validate on receive" bug report, and this PR is mostly the recorded decision it asks for.
The decision: warn, don't withhold
Returning the message is the decision, not an omission.
Substrate's core property is that replaying an event log reproduces the same observations, and a message written by an older substrate was accepted by the substrate that recorded it. Withholding or dropping it now would make a recorded run unreplayable, which is the one outcome #491 rules out.
A receive-time rejection also has no AWS behaviour to imitate: real SQS never accepted the message in the first place, so there is no real response to copy. Substrate would be inventing an observation.
Option 1 (do nothing) leaves an operator with a fixture that quietly predates the rules. The warning gives them the signal without changing what any caller observes.
Option 3 — a replay-time report of recorded data a current substrate would refuse — is the more principled home, because the violation is a property of the log rather than of any one request. It needs a surface in the replay machinery that does not exist today, so it is filed as #512 rather than dropped, and this PR says so in the CHANGELOG and in the code comment.
Two scope choices, both deliberate and both mutation-tested
The whole stored attribute set is checked, not the subset the request asked for. The violation is a property of what is in state. #461's selection rule means a request naming no attribute names gets no attributes back — so a subset check would hide the violation from exactly the caller most likely to be replaying an old log.
It fires on every receive, not once per message. A message redelivered after its visibility timeout is a fixture being exercised again, and remembering which messages have already warned would be per-process state that a replay could not reproduce.
Send is unchanged
No new run can produce this state — the send path still refuses an illegal attribute set with
InvalidParameterValue.TestSQS_MessageAttributes_SendTimeRejectionIsUnchangedpins that, including that the queue depth stays at zero.Tests
emulator/sqs_messageattrrules_test.go. Two helpers:storeIllegalAttributeswrites an illegal attribute set directly into state. Going around the API is the point rather than a shortcut: no send path stores an illegal attribute any more, so the only way this state exists is an event log recorded against a substrate that predates the rules.newSQSServerCapturingLogsbuilds a server whose logger writes into a buffer atWARN, so the warning is asserted rather than assumed.TestSQS_MessageAttributes_StoredAttributesAreReturnedNotWithheld— three violation families (a reservedAWS.tracename, an eleventh attribute,Age=Number/"abc"), each over both protocols, asserting the message ID, the body and that every stored attribute comes back with its stored value. This is the replay gate: it must fail if anyone later "fixes" receive to validate.TestSQS_MessageAttributes_StoredViolationWarns— the warning names the message, the queue and the rule; a request naming no attributes still warns (withEmpty(attributes)in the same subtest, since that is the case a subset check would miss); a legal message logs nothing; a message with no attributes logs nothing.TestSQS_MessageAttributes_SendTimeRejectionIsUnchanged— 400 /InvalidParameterValue/ the cast message / depth 0.The old
TestSQS_MessageAttributes_StoredAttributesAreNotRecheckedis replaced: it asserted the absence of a check, which is now the weaker half of what is asserted.Verification
From the repo root:
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race) → ok,make docs-reference docs-reference-check docs-versions→ no diff,npm --prefix docs run build→ complete,go vet -C test/e2e ./...andgo test -C test/e2e ./...→ ok.Mutation testing — 14 mutants over
sqs_messageattrrules.goandsqs_plugin.go: 13 caught, 1 proven equivalent, 0 survived.The four mutants #491 exists to forbid are all caught by the replay gate:
continue)…AreReturnedNotWithheldReceiveMessage…AreReturnedNotWithheld…AreReturnedNotWithheld…AreReturnedNotWithheldThe warning mutants — never warn, warn unconditionally, drop the message ID, drop the queue, drop which rule was violated, downgrade to
Debug— are all caught by…StoredViolationWarns. Both scope mutants (check only the requested subset; skip the check when nothing was requested) are caught by the "request naming no attributes still warns" subtest, which is why it exists. Softening the send path (sqsCheckMessageAttributes(nil)) is caught by…SendTimeRejectionIsUnchanged.The one equivalent mutant is removing the
len(msg.MessageAttributes) == 0fast path:sqsCheckMessageAttributesreturnsnilfor an empty or nil map, so no input distinguishes the two forms. It stays on cost grounds — most messages carry no attributes, and the guard skips a sort and an allocation per message in the receive loop — and the comment says that rather than implying correctness.A first run had one survivor: a
logger == nilguard. No otherlogger == nilguard exists in the package andreceiveMessagealready callsp.logger.Warnunguarded a few lines away, so it was inconsistent defensive code for an unreachable path. Resolved by deleting the guard, not by adding a test for it.End to end
Send still refuses, a legal message warns nothing, and the illegal-stored case is only reachable by writing state directly — which is exactly the fixture the unit tests build.
Docs
docs/services.md§"Message attributes" gains a### The rules apply on send, not on receivesubsection: the message is returned in full with aWARNnaming the queue, message ID and rule; the replay argument and the no-AWS-behaviour-to-imitate argument; that rejecting on receive is deliberately not done and the suite fails if anyone adds it; the whole-set-not-subset and every-receive rationales; and that send-time rejection is unchanged so no new run can produce this state.