-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [ResponseOps][MaintenanceWindow] Introduce pagination for MW fi…
…nd API (#197172) (#198325) # Backport This will backport the following commits from `main` to `8.x`: - [[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API (#197172)](#197172) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-30T12:54:58Z","message":"[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API (#197172)\n\nFixes: https://github.com/elastic/kibana/issues/193076\r\n\r\nThis PR introduce pagination for our MW find API.\r\n\r\nHow to test:\r\n\r\nUse postman/insomnia/curl.\r\nDo not forget to add this header: `x-elastic-internal-origin: Kibana`,\r\nbecause this endpoint in internal.\r\n\r\nBasically you need to do something like this:\r\n```\r\nGET http://localhost:5601/top/internal/alerting/rules/maintenance_window/_find?page=3&per_page=3\r\n```\r\n\r\nTry different page and per_page combination. Try without them.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"6645e747070e1b7bf687227776acda2ae136fc75","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesManagement","backport:prev-major","v8.16.0","v8.17.0"],"title":"[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API","number":197172,"url":"https://github.com/elastic/kibana/pull/197172","mergeCommit":{"message":"[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API (#197172)\n\nFixes: https://github.com/elastic/kibana/issues/193076\r\n\r\nThis PR introduce pagination for our MW find API.\r\n\r\nHow to test:\r\n\r\nUse postman/insomnia/curl.\r\nDo not forget to add this header: `x-elastic-internal-origin: Kibana`,\r\nbecause this endpoint in internal.\r\n\r\nBasically you need to do something like this:\r\n```\r\nGET http://localhost:5601/top/internal/alerting/rules/maintenance_window/_find?page=3&per_page=3\r\n```\r\n\r\nTry different page and per_page combination. Try without them.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"6645e747070e1b7bf687227776acda2ae136fc75"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197172","number":197172,"mergeCommit":{"message":"[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API (#197172)\n\nFixes: https://github.com/elastic/kibana/issues/193076\r\n\r\nThis PR introduce pagination for our MW find API.\r\n\r\nHow to test:\r\n\r\nUse postman/insomnia/curl.\r\nDo not forget to add this header: `x-elastic-internal-origin: Kibana`,\r\nbecause this endpoint in internal.\r\n\r\nBasically you need to do something like this:\r\n```\r\nGET http://localhost:5601/top/internal/alerting/rules/maintenance_window/_find?page=3&per_page=3\r\n```\r\n\r\nTry different page and per_page combination. Try without them.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"6645e747070e1b7bf687227776acda2ae136fc75"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Julia <[email protected]>
- Loading branch information
1 parent
adf6b7d
commit b78ca2b
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.