Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v14] [dynamoevents] fix pagination when limit is reached at the boun…
…dary of a day (#44273) * [dynamoevents] fix pagination when limit is reached at the boundary of a day DynamoDB stores events using the day as one of the search indexes. When querying, it splits the [from, to] window into the containing days, i.e., [date(from), date(from)+1 day, ..., date(to)], and iterates through them sequentially until there are no more events to consume or the limit is reached. Each day is requested individually and after the previous day (assuming ascending order). DynamoDB indicates that a client has consumed all events for a day by returning an empty iterator. According to the DynamoDB documentation: ``` // The primary key of the item where the operation stopped, inclusive of the // previous result set. Use this value to start a new operation, excluding this // value in the new request. // // If LastEvaluatedKey is empty, then the "last page" of results has been processed // and there is no more data to be retrieved. // // If LastEvaluatedKey is not empty, it does not necessarily mean that there // is more data in the result set. The only way to know when you have reached // the end of the result set is when LastEvaluatedKey is empty. ``` Given the current indexing, we need to take special consideration when the limit is reached exactly at the end of a day. In this case, the iterator must be moved to the next day. Otherwise, the client receives a reset cursor with only the date set, causing a dead loop since the cursor resets to the beginning of the day, which is a specific issue for the event-handler. This PR fixes the issue by advancing the cursor to the next day if the limit is reached at the end of a day, and the iterator is empty. I wrote a test but couldn't reproduce the issue using DynamoDB local, as it never returns an empty cursor. Instead, it returns a cursor that, when called, returns an empty cursor and no events. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * add tests * handle an edge case when iteration stops before page ends because maximum response size is reached * handle edge case where some events could have been skipped when the maximum message size was reached --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
- Loading branch information