botocore icon indicating copy to clipboard operation
botocore copied to clipboard

Make GetLogEvents pagination API consistent with others

Open frosforever opened this issue 3 years ago • 3 comments

To paginate responses from GetLogEvents api currently requires either nextForwardToken or nextBackwardToken depending on is startFromHead is true. This means it does not seem to neatly fit into the pagination model and adding

"GetLogEvents": {
      "input_token": "nextForwardToken",
      "output_token": "nextToken",
      "limit_key": "limit",
      "result_key": "events"
}      

to https://github.com/frosforever/botocore/blob/develop/botocore/data/logs/2014-03-28/paginators-1.json would not work to automatically paginate results.

Describe the solution you'd like Ideally, API would be return a single nextToken in the response that would either go forward or backward based on the original starting request.

Thanks very much for reviewing my issue. I'm not sure if this belongs in this repo or if this something that's controlled by the internal AWS Cloudwatch logs team. Feel free to close if this doesn't belong here.

frosforever avatar Jun 16 '21 22:06 frosforever

Hi @frosforever,

Thanks for your comment. You assume correctly - the internal AWS Cloudwatch team controls the naming of the parameters here. But it looks like here you're just requesting that this operation be paginated!

The name of that parameter is an implementation detail, as the AWS CLI, Python SDK (boto3) and other AWS SDKs abstract over this and provide paginator functionality:

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html

I can certainly request that a paginator be added for this operation by the AWS Cloudwatch team - paginator models are used by other AWS SDKs so are added upstream.

kdaily avatar Jun 17 '21 14:06 kdaily

@kdaily Yes pagination is the goal!

Perhaps my issue is based on a misunderstanding of how the paginator works. The complexity with GetLogEvents is not so much the name of the next token but more that a different field is used as the next token depending on if you're going forward or backward in time.

From https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_GetLogEvents.html#API_GetLogEvents_RequestSyntax:

startFromHead

If the value is true, the earliest log events are returned first. If the value is false, the latest log events are returned first. The default value is false. If you are using a previous nextForwardToken value as the nextToken in this operation, you must specify true for startFromHead.

If there's a way to support pagination even with that complexity I am all for it! Thanks for taking the time to triage and notify upstream.

frosforever avatar Jun 17 '21 15:06 frosforever

Linking related issue: https://github.com/boto/botocore/issues/1474

tim-finnigan avatar Apr 06 '22 18:04 tim-finnigan