fix(aws-dynamodb): paginate Query to avoid undercounting large result sets - #7912
Open
vidigoat wants to merge 2 commits into
Open
fix(aws-dynamodb): paginate Query to avoid undercounting large result sets#7912vidigoat wants to merge 2 commits into
vidigoat wants to merge 2 commits into
Conversation
… sets A DynamoDB Query returns at most 1 MB of data per call and the response can span multiple pages via LastEvaluatedKey. GetQueryMetrics only issued a single Query and returned that page's Count, so for result sets larger than one page the scaler undercounted the matching items and under-scaled the workload. Follow the pagination token with dynamodb.NewQueryPaginator and sum Count across all pages. Single-page results are unaffected. Adds a regression test that returns two pages and asserts the counts are summed. Signed-off-by: Vidit Patankar <vidit.patankar16@gmail.com>
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Signed-off-by: Vidit Patankar <vidit.patankar16@gmail.com>
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.
Description
The AWS DynamoDB scaler's
GetQueryMetricsissued a singledynamodb.Querycall and returned that response'sCount:A DynamoDB
Queryreturns at most 1 MB of data per call and the result set can span multiple pages, signalled by a non-nilLastEvaluatedKeyon the response. Because the scaler never followed that token, for any query whose matching items exceed a single page it only counted the first page and reported aCountfar lower than the real number of matching items. This undercounts the metric and causes the workload to be under-scaled (the more items match, the worse the gap).This is the same pagination pattern the AWS DynamoDB Streams scaler already uses (
LastEvaluatedShardId).Fix
Use
dynamodb.NewQueryPaginator(which accepts the existingdynamodb.QueryAPIClient) to walk every page viaLastEvaluatedKeyand sumCountacross all pages. Single-page results are unaffected, so this is non-breaking.Tests
Added
TestDynamoGetQueryMetricsPaginated: the mock returns two pages (4 items with aLastEvaluatedKey, then 3 items). It fails before the fix (returns 4) and passes after (returns 7). All existing DynamoDB scaler tests continue to pass.Checklist
Fixes #