Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v16] [dynamoevents] fix pagination when limit is reached at the boundary of a day #44275

Merged
merged 4 commits into from
Jul 16, 2024

Conversation

tigrato
Copy link
Contributor

@tigrato tigrato commented Jul 16, 2024

Backport #44246 to branch/v16

changelog: Prevented an inifinite loop in DynamoDB event querying by advancing the cursor to the next day when the limit is reached at the end of a day with an empty iterator. This ensures the cursor does not reset to the beginning of the day.

tigrato added 4 commits July 16, 2024 11:30
…f 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>
@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log backport size/sm labels Jul 16, 2024
@tigrato tigrato enabled auto-merge July 16, 2024 18:08
@tigrato tigrato added this pull request to the merge queue Jul 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 16, 2024
@tigrato tigrato added this pull request to the merge queue Jul 16, 2024
Merged via the queue into branch/v16 with commit 5ab0427 Jul 16, 2024
38 checks passed
@tigrato tigrato deleted the bot/backport-44246-branch/v16 branch July 16, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-log Issues related to Teleports Audit Log backport size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants