-
Notifications
You must be signed in to change notification settings - Fork 916
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
[MD] Support legacy client for data source #2204
Conversation
bc8fc37
to
f337d6c
Compare
@@ -65,7 +65,7 @@ const noop = () => undefined; | |||
* OpenSearch JS client. | |||
* @param options Options that affect the way we call the API and process the result. | |||
*/ | |||
const callAPI = async ( | |||
export const callAPI = async ( |
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.
do we have to export it
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.
Have to export it, or otherwise copy the entire thing to datasource. Becuase we are trying to re-use it in the legacy client wrapper for datasource.
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.
Add more context. callAPI
is not only the interface, but it wraps some validation, parsing logic for user input. To make sure the data_source.legacy.client
has the exact same behavior as default legacy client, and doesn't break backwards compatibility for consumer plugins. We have to re-use it.
const callAPI = async ( | |
client: Client, | |
endpoint: string, | |
clientParams: Record<string, any> = {}, | |
options: LegacyCallAPIOptions = { wrap401Errors: true } | |
) => { | |
const clientPath = endpoint.split('.'); | |
const api: any = get(client, clientPath); | |
if (!api) { | |
throw new Error(`called with an invalid endpoint: ${endpoint}`); | |
} | |
const apiContext = clientPath.length === 1 ? client : get(client, clientPath.slice(0, -1)); | |
try { | |
return await new Promise((resolve, reject) => { | |
const request = api.call(apiContext, clientParams); |
cc @noCharger
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.
With the new request from #2386, I think it worth to make a copy of callAPI and wire the wrap401Error
there
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.
Agreed, we can create a new callAPI
for now, while exploring other options.
f337d6c
to
145ec29
Compare
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.
Overall looks good. Also curious if export callAPI
is the best practice here.
index pattern related migration lgtm |
ced5a2d
to
09d133f
Compare
@zengyan-amazon Yan can you help take another look?I updated the PR based on our recent refactor and code changes |
Can I get an update? @zengyan-amazon ?? |
re-posted this PR to |
82a8d3a
to
3a1ce44
Compare
src/plugins/data_source/server/legacy/configure_legacy_client.ts
Outdated
Show resolved
Hide resolved
export interface OpenSearchClientPoolSetup { | ||
getClientFromPool: (id: string) => Client | undefined; | ||
addClientToPool: (endpoint: string, client: Client) => void; | ||
getClientFromPool: (id: string) => Client | LegacyClient | undefined; | ||
addClientToPool: (endpoint: string, client: Client | LegacyClient) => void; | ||
} |
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.
we have this pool includes a LRU of <endpoint, root_client> . since now we support Legacy client, shall we have one pool for legacy client, and another pool for new client? otherwise, it will cause runtime error when when a use case need a legacy client while getting a new client root client from the pool, and verse versa.
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.
There are in fact 2 pool instances being initiated in the constructor of DataSourceService
here. One only stores new client, the other one for legacy client.
Since the only different of pool impl for legacy or new client is the "value" type of the LRU, I didn't make a copy of client_pool
to avoid having too much duplicate code. Instead I defined the LRU type as multiple type.
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'd prefer to have 2 cache in the pool to avoid misuse the pool. but the current implementation makes sense to me.
Signed-off-by: Su <[email protected]>
Signed-off-by: Su <[email protected]>
3a1ce44
to
d26ac47
Compare
6244daf
Codecov Report
@@ Coverage Diff @@
## main #2204 +/- ##
=======================================
Coverage 66.74% 66.75%
=======================================
Files 3197 3200 +3
Lines 60828 60886 +58
Branches 9243 9250 +7
=======================================
+ Hits 40601 40642 +41
- Misses 18019 18032 +13
- Partials 2208 2212 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-2204-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 746b9df179f9f095befe5a2ec9df841fc287baf7
# Push it to GitHub
git push --set-upstream origin backport/backport-2204-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
* support legacy client for data source * not wrap 401 error for data source client Signed-off-by: Su <[email protected]> (cherry picked from commit 746b9df)
* support legacy client for data source * not wrap 401 error for data source client Signed-off-by: Su <[email protected]> (cherry picked from commit 746b9df)
…search-project#2484) * support legacy client for data source * not wrap 401 error for data source client Signed-off-by: Su <[email protected]> (cherry picked from commit 746b9df)
…search-project#2484) * support legacy client for data source * not wrap 401 error for data source client Signed-off-by: Su <[email protected]> (cherry picked from commit 746b9df)
* support legacy client for data source * not wrap 401 error for data source client Signed-off-by: Su <[email protected]> Signed-off-by: Sergey V. Osipov <[email protected]>
Signed-off-by: Su [email protected]
Description
Legacy clients are using
elasticsearch.js
new clients are using
openearch.js
data-source service
setup stage, specifically for legacy clientsLegacyAPICaller
as required by elasticsearch.js clientsdata_source.legacy.getClient
Issues Resolved
#2133
#2386
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr