tektoncd / results

Long term storage of execution results.
Apache License 2.0
78 stars 74 forks source link

`--limit` flag in `tkn-results` should return a pageToken if total resources > limit #584

Open avinal opened 1 year ago

avinal commented 1 year ago

Feature request

When tkn-results is used with --limit n flag, no pageToken is returned, see the example below

$ tkn-results records list default/results/- --filter="data_type==PIPELINE_RUN&&data.metadata.name.startsWith('he')" --limit 5 
Name                                                                                               Type                                    Start                                   Update
default/results/e7f67564-7fac-492d-b071-8046ea69801a/records/e7f67564-7fac-492d-b071-8046ea69801a  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:24 +0530 IST           2023-08-28 15:07:19 +0530 IST
default/results/d700eabd-85cf-4e72-9200-656191af3700/records/d700eabd-85cf-4e72-9200-656191af3700  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:55:57 +0530 IST           2023-08-28 15:06:40 +0530 IST
default/results/518aa6f3-ce55-41b1-a09f-d8f738b7242d/records/518aa6f3-ce55-41b1-a09f-d8f738b7242d  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:01 +0530 IST           2023-08-28 14:56:42 +0530 IST
default/results/e97441d9-d54b-479a-bdae-4c5a669225a8/records/e97441d9-d54b-479a-bdae-4c5a669225a8  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:18 +0530 IST           2023-08-28 15:07:05 +0530 IST
default/results/959a4f6a-fcd2-4c77-b17e-9aaebabc5e1d/records/959a4f6a-fcd2-4c77-b17e-9aaebabc5e1d  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:55:37 +0530 IST           2023-08-28 14:55:49 +0530 IST

The only way of getting nextPageToken through CLI is to output as JSON or proto. IMO, the token must be displayed in the tab format as well.

Use case

If the total number of resources is less than n in --limit n a pagetoken should be returned along with the output in tab format. This allows the user to directly copy and query the next page.

Example

$ tkn-results records list default/results/- --filter="data_type==PIPELINE_RUN&&data.metadata.name.startsWith('he')" --limit 5
Name                                                                                               Type                                    Start                                   Update
default/results/e7f67564-7fac-492d-b071-8046ea69801a/records/e7f67564-7fac-492d-b071-8046ea69801a  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:24 +0530 IST           2023-08-28 15:07:19 +0530 IST
default/results/d700eabd-85cf-4e72-9200-656191af3700/records/d700eabd-85cf-4e72-9200-656191af3700  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:55:57 +0530 IST           2023-08-28 15:06:40 +0530 IST
default/results/518aa6f3-ce55-41b1-a09f-d8f738b7242d/records/518aa6f3-ce55-41b1-a09f-d8f738b7242d  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:01 +0530 IST           2023-08-28 14:56:42 +0530 IST
default/results/e97441d9-d54b-479a-bdae-4c5a669225a8/records/e97441d9-d54b-479a-bdae-4c5a669225a8  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:56:18 +0530 IST           2023-08-28 15:07:05 +0530 IST
default/results/959a4f6a-fcd2-4c77-b17e-9aaebabc5e1d/records/959a4f6a-fcd2-4c77-b17e-9aaebabc5e1d  tekton.dev/v1beta1.PipelineRun          2023-08-28 14:55:37 +0530 IST           2023-08-28 14:55:49 +0530 IST

NextPageToken: ChFkZWZhdWx0L3Jlc3VsdHMvLRI8ZGF0YV90eXBlPT1QSVBFTElORV9SVU4mJmRhdGEubWV0YWRhdGEubmFtZS5zdGFydHNXaXRoKCdoZScpGiYKJDJjMTE4MDJjLWIxNzgtNDM0MC04NWM2LWE4MDcyNzVjNWFiNw
avinal commented 1 year ago

This should be a simple change. If the community agrees, I will open a PR.