Repository navigation
Match requested message attribute names exactly or by prefix in ReceiveMessage - #1268
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
micossow
left a comment
There was a problem hiding this comment.
Thanks for the clear write-up and the before/after table. Looks good to me.
Correctness
- The old filter
k.r.findFirstIn(s)has been there since #97 (2017). It treated each stored attribute name as a regex and searched for it inside the requested name, so the matching ran the wrong way round. The new logic (exact match, ors.endsWith(".*") && k.startsWith(s.dropRight(1))) matches what the SQS docs describe forMessageAttributeNames.Alland.*still short-circuit before the filter, so they behave as before. - Because
s.dropRight(1)keeps the trailing.,foo.*matchesfoo.barbut notfooorfoobar. That is the right reading of "starting with a prefix, for examplebar.*". MD5OfMessageAttributesis computed from the filtered map, so it stays consistent with the attributes that are returned.- I checked the existing helpers in
IntegrationTestsBase(filterBasedOnRequestedAttributes). They already assume exact-name matching, so no existing test depended on the old substring behaviour.
Nits (non-blocking)
s.stripSuffix("*")might read a little more clearly thans.dropRight(1)next to theendsWith(".*")guard. Up to you.- In the test,
byName.headandbyPrefix.headthrow a bareNoSuchElementExceptionif nothing is received. AddingbyName should have size 1first would give a clearer failure message.
Note
- No CI checks have run on this branch yet. Workflows for fork PRs probably need a maintainer to approve them before they run, so we should get a green run before merging.
|
Thanks for the review. Both nits are in 99aba8a: On CI: the failing job on the merge commit is |
ReceiveMessage picks the message attributes to return with
k.r.findFirstIn(s). That treats each attribute namekas a regular expression and searches for it inside the requested names. Two things go wrong:fooreturnsfoo,foando, and asking forxayreturnsx.y, because the.matches any character.foo.*doesn't returnfoo.barorfoo.baz, since a name that is longer than the request can't be found inside it. Instead it returnsfoo,foando.The SQS docs for
MessageAttributeNamessay you can ask for attributes by name, useAllor.*for all of them, or "use all message attributes starting with a prefix, for examplebar.*".With attributes
foo,foo.bar,foo.baz,foandoon one message:foofoo.*MD5OfMessageAttributesis computed from the filtered map, so it changes with it.The fix keeps an attribute when its name equals a requested name, or when a requested name ends in
.*and the attribute name starts with what comes before the*.Alland.*work as before.Test: a new case in
MessageAttributesTestsreceives the same message once by exact name and once by prefix. It runs in both the SDK v1 and v2 suites, fails before the fix (Set("foo", "fo", "o") was not equal to Set("foo")) and passes after.scalafmtCheckAll,restSqs/test(28 tests) andrestSqsTestingAmazonJavaSdk/test(162 tests) pass on Scala 2.13.