forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bug/update follower index validation cr #24
Open
sebelga
wants to merge
5
commits into
cjcenizal:bug/update-follower-index-validation
Choose a base branch
from
sebelga:bug/update-follower-index-validation-cr
base: bug/update-follower-index-validation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4b1fb3d
Move body schema out of route declaration
sebelga 7c411f8
Add API integration test to make sure follower index is updated
sebelga 3e273e9
Add test coverage with single source of truth for api endpoint
sebelga 59337a6
Create reusable lib to create endoint getter
sebelga 06143cd
Fix
sebelga 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
58 changes: 58 additions & 0 deletions
58
x-pack/legacy/plugins/cross_cluster_replication/common/routes_endpoints.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,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/** | ||
* -------------------------------------------------------- | ||
* Single source of truth for the CCR routes endpoints | ||
* To be used in server, client and api integration tests | ||
* -------------------------------------------------------- | ||
*/ | ||
|
||
import { API_BASE_PATH } from './constants'; | ||
|
||
type Section = 'followerIndex'; | ||
type Method = 'get' | 'post' | 'put' | 'delete' | 'head'; | ||
|
||
interface EndpointDefinition { | ||
method: Method; | ||
path: string; | ||
} | ||
|
||
// Follower indices | ||
const followerIndexEndpoints = { | ||
edit: { | ||
method: 'put', | ||
path: `${API_BASE_PATH}/follower_indices/{id}`, | ||
} as EndpointDefinition, | ||
}; | ||
|
||
// TODO: Add autoFollowPatternEndpoints & ccrEndpoints | ||
|
||
const ccrRoutesEndpoints = { | ||
followerIndex: followerIndexEndpoints, | ||
}; | ||
|
||
type CcrRoutesEndPoints = typeof ccrRoutesEndpoints; | ||
|
||
const replacePlaceholders = (path: string, data: { [key: string]: any }): string => | ||
Object.entries(data).reduce((updatedPath, [key, value]) => { | ||
const regEx = new RegExp(`{${key}}`); | ||
return updatedPath.replace(regEx, value); | ||
}, path); | ||
|
||
export const getEndpoint = <S extends Section, E extends keyof CcrRoutesEndPoints[S]>( | ||
section: S, | ||
endpoint: E, | ||
data?: { [key: string]: any } | ||
): EndpointDefinition => { | ||
const endpointDefinition = (ccrRoutesEndpoints[section][ | ||
endpoint | ||
] as unknown) as EndpointDefinition; | ||
|
||
return data | ||
? { ...endpointDefinition, path: replacePlaceholders(endpointDefinition.path, data) } // Replace placeholders with data | ||
: endpointDefinition; | ||
}; |
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
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.
I'm not sure I see the benefit of the added
getEndpoint
machinery.It seems like another thing we need to build out (
replacePlaceholders
👀) and share properly across apps and without a clear benefit over statically declaring these values (at least the path pattern, not convinced about the method) and importing them from a common folder.If we issue a request (in tests or in app code) against a server on a path that does not exist we should be met with a 404 and so the server is already the source of truth, so this does not seem like a major current pain point.
My understanding of the bug we had here was that we required a body but the logic inside the route handler accepted a body with all
undefined
values - combined with NP route validation the oversight snuck in because body without route validation is{}
(i.e., an acceptable value!).The best way, in my view, to cover this specific case would be the addition of an API integration test that issues a request against elastic with a value set and checking the response (like what you have added here
x-pack/test/api_integration/apis/management/cross_cluster_replication/follower_indices.js
)The major take away for me, from this bug, besides the added tests is that we need to be more thorough in our route validations and explicitly testing sending unexpected values to routes.