-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ResponseOps][MaintenanceWindow] Introduce pagination for MW find API #197172
Merged
guskovaue
merged 22 commits into
elastic:main
from
guskovaue:MX-193076-MX-pagination-backend
Oct 30, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
be73cbb
introduce pagination for MW find API
guskovaue 8a84cc2
add transmorm function
guskovaue 815bfe4
Merge branch 'main' into MX-193076-MX-pagination-backend
guskovaue 3e40644
add integration test for pagination
guskovaue 1995414
fix types and unit tests after changes
guskovaue 6009cd0
nit
guskovaue 32f87a6
fix eslint
guskovaue a6d02f0
Merge branch 'main' into MX-193076-MX-pagination-backend
guskovaue cbb3185
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine f1e2e49
fixes after code review
guskovaue 9d4850b
Merge branch 'MX-193076-MX-pagination-backend' of github.com:guskovau…
guskovaue 1d20bee
more fixes after code review
guskovaue 2698ca5
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 7427123
fix integration test
guskovaue 8b83618
Merge branch 'MX-193076-MX-pagination-backend' of github.com:guskovau…
guskovaue d53050b
new integration test for validation max docs number
guskovaue f06b777
fix linter
guskovaue 4efdc44
Merge branch 'main' into MX-193076-MX-pagination-backend
guskovaue f522466
remove fake timer
guskovaue d18c5c6
Merge branch 'main' into MX-193076-MX-pagination-backend
guskovaue 84bddd0
Merge branch 'main' into MX-193076-MX-pagination-backend
guskovaue c2cd520
remove ts expect error block
guskovaue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
guskovaue marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: Could you please move all the numbers of
min, max and defaultValue
to const same asMAX_DOCS_PER_PAGE
for consistency?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing. I renamed
MAX_DOCS_PER_PAGE
toMAX_DOCS
, because it make more sense.I thought about your suggestion and decided to keep as it is. Because for this one constant it make sense to be assign to variable, because we reuse it. But others are not reusable and it's a lot of them.