[UII] Support searchAfter and PIT (point-in-time) parameters for get agents list API#213486
[UII] Support searchAfter and PIT (point-in-time) parameters for get agents list API#213486jen-huang merged 16 commits intoelastic:mainfrom
searchAfter and PIT (point-in-time) parameters for get agents list API#213486Conversation
…in get agents response
|
Pinging @elastic/fleet (Team:Fleet) |
| getStatusSummary: schema.boolean({ defaultValue: false }), | ||
| sortField: schema.maybe(schema.string()), | ||
| sortOrder: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])), | ||
| searchAfter: schema.maybe(schema.string()), |
There was a problem hiding this comment.
reposting from PR description:
@elastic/fleet I couldn't get the Kibana request schema to accept a multi-part query param and convert it to an array... I think this would be better, please let me know if you know how to get that to work 🙏
changing this to schema.maybe(schema.arrayOf(schema.any())) and passing params like &searchAfter=123&searchAfter=test or even &searchAfter[]=123&searchAfter[]=test didn't work. it only returned error about searchAfter not matching expected schema
There was a problem hiding this comment.
it seems when using an array of any it do not parse correctly number or string, (it seems expected as there not really way to get that), so I guess it's okay to use a string here I am wondering if it will make the API easier to use if we add a meta to agent list response something like nextSearchAfter: "[stringified...]" so user will not have to know about getting the last sort field of the agents, WDYT?
There was a problem hiding this comment.
I think this is a good idea, I will take a look
|
/ci test this |
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/fleet --include-path /api/dashboards --update'
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/fleet --include-path /api/dashboards --update'
nchaulet
left a comment
There was a problem hiding this comment.
code LGTM 🚀 should we add some doc for that? having a recipe in the doc on how to query for more than 10k agents could be a good idea
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
History
cc @jen-huang |
I filed elastic/ingest-docs#1726. Thanks for quick re-review! |
…t agents list API (elastic#213486) ## Summary Resolves elastic#206924. This PR adds the following query parameters to the agent list API (`GET /api/fleet/agents`) in order to enable fetching beyond the first 10,000 hits: ``` searchAfter?: string; openPit?: boolean; pitId?: string; pitKeepAlive?: string; ``` The list agent API response can now include the following properties ``` // the PIT ID used pit?: string; // stringified version of the last agent's `sort` field, // can be passed as `searchAfter` in the next request nextSearchAfter? string; ``` * `searchAfter` can be used with or without a `pitId`. If using `searchAfter`, `page` parameter is not accepted. * `searchAfter` expects a stringified array. (Reviewers: I couldn't get the Kibana request schema to accept a multi-part query param and convert it to an array... I think this would be better, please let me know if you know how to get that to work 🙏) * `pitKeepAlive` duration (i.e. `30s`, `1m`, etc) must be present when opening a PIT or retrieving results using a PIT ID. * These can be used with the existing `sortField` and `sortOrder` params. They default to `enrolled_at` and `desc` respectively. ### Example using only `searchAfter`: ``` # Retrieve the first 10k hits curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000' # Grab the `nextSearchAfter` param from the response # Pass it to the new request to retrieve the next page of 10k hits curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&searchAfter=<nextSearchAfter>' ``` ### Example using `searchAfter` with point-in-time parameters: ``` # Retrieve the first 10k hits and open a PIT curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&openPit=true&pitKeepAlive=5m' # Grab the `pit` ID from the response # Grab the `nextSearchAfter` param from the response # Pass both to the new request to retrieve the next page of 10k hits curl -X GET 'http://<user>:<pass>@<kibana url>/api/fleet/agents?perPage=10000&searchAfter=<nextSearchAfter>&pitId=<pit id>&pitKeepAlive=5m' ``` ## Testing I recommend using `scripts/create_agents` to generate bulk agents and testing the above requests. You can generate new agents between PIT requests to test that using a PIT ID retains the original state. (An API functional test was added for this) Note: you may need to add `&showInactive=true` to all requests if your fake agents become inactive. TBD ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Summary
Resolves #206924.
This PR adds the following query parameters to the agent list API (
GET /api/fleet/agents) in order to enable fetching beyond the first 10,000 hits:The list agent API response can now include the following properties
searchAftercan be used with or without apitId. If usingsearchAfter,pageparameter is not accepted.searchAfterexpects a stringified array. (Reviewers: I couldn't get the Kibana request schema to accept a multi-part query param and convert it to an array... I think this would be better, please let me know if you know how to get that to work 🙏)pitKeepAliveduration (i.e.30s,1m, etc) must be present when opening a PIT or retrieving results using a PIT ID.These can be used with the existing
sortFieldandsortOrderparams. They default toenrolled_atanddescrespectively.Example using only
searchAfter:Example using
searchAfterwith point-in-time parameters:Testing
I recommend using
scripts/create_agentsto generate bulk agents and testing the above requests. You can generate new agents between PIT requests to test that using a PIT ID retains the original state. (An API functional test was added for this)Note: you may need to add
&showInactive=trueto all requests if your fake agents become inactive.TBD
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:*label is applied per the guidelines