-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API (…
…#197172) Fixes: #193076 This PR introduce pagination for our MW find API. How to test: Use postman/insomnia/curl. Do not forget to add this header: `x-elastic-internal-origin: Kibana`, because this endpoint in internal. Basically you need to do something like this: ``` GET http://localhost:5601/top/internal/alerting/rules/maintenance_window/_find?page=3&per_page=3 ``` Try different page and per_page combination. Try without them. ### Checklist - [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] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
fd615c7
commit 6645e74
Showing
24 changed files
with
455 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/maintenance_window/apis/find/schemas/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/alerting/common/routes/maintenance_window/apis/find/schemas/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { maintenanceWindowResponseSchemaV1 } from '../../../response'; | ||
|
||
const MAX_DOCS = 10000; | ||
|
||
export const findMaintenanceWindowsRequestQuerySchema = schema.object( | ||
{ | ||
page: schema.maybe( | ||
schema.number({ | ||
defaultValue: 1, | ||
min: 1, | ||
max: MAX_DOCS, | ||
meta: { | ||
description: 'The page number to return.', | ||
}, | ||
}) | ||
), | ||
per_page: schema.maybe( | ||
schema.number({ | ||
defaultValue: 20, | ||
min: 0, | ||
max: 100, | ||
meta: { | ||
description: 'The number of maintenance windows to return per page.', | ||
}, | ||
}) | ||
), | ||
}, | ||
{ | ||
validate: (params) => { | ||
const pageAsNumber = params.page ?? 0; | ||
const perPageAsNumber = params.per_page ?? 0; | ||
|
||
if (Math.max(pageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS) { | ||
return `The number of documents is too high. Paginating through more than ${MAX_DOCS} documents is not possible.`; | ||
} | ||
}, | ||
} | ||
); | ||
|
||
export const findMaintenanceWindowsResponseBodySchema = schema.object({ | ||
page: schema.number(), | ||
per_page: schema.number(), | ||
total: schema.number(), | ||
data: schema.arrayOf(maintenanceWindowResponseSchemaV1), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
* 2.0. | ||
*/ | ||
|
||
export type { FindMaintenanceWindowsResponse } from './v1'; | ||
export * from './v1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...lication/maintenance_window/methods/find/schemas/find_maintenance_window_params_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const findMaintenanceWindowsParamsSchema = schema.object({ | ||
perPage: schema.maybe(schema.number()), | ||
page: schema.maybe(schema.number()), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...erver/application/maintenance_window/methods/find/types/find_maintenance_window_params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { TypeOf } from '@kbn/config-schema'; | ||
import { findMaintenanceWindowsParamsSchema } from '../schemas'; | ||
|
||
export type FindMaintenanceWindowsParams = TypeOf<typeof findMaintenanceWindowsParamsSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.