-
Notifications
You must be signed in to change notification settings - Fork 89
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
Feature: MDS client enhancement #706
base: 2.x
Are you sure you want to change the base?
Conversation
f25c697
to
0defdf2
Compare
Codecov Report
@@ Coverage Diff @@
## 2.x #706 +/- ##
==========================================
- Coverage 63.37% 62.40% -0.98%
==========================================
Files 341 337 -4
Lines 11545 11435 -110
Branches 2108 2211 +103
==========================================
- Hits 7317 7136 -181
- Misses 3654 3737 +83
+ Partials 574 562 -12 |
RequestHandlerContext, | ||
} from "opensearch-dashboards/server"; | ||
|
||
export interface IRequestHandlerContentWithDataSource extends RequestHandlerContext { |
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.
data source plugin registered client objects at https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data_source/server/plugin.ts#L99 , not sure if that can be reused
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.
Good point and plugin should add dataSource plugin as requiredPlugins, add this change into this PR.
* it is not a good practice to rewrite the method like this | ||
* but JS does not provide a method to copy a class instance | ||
*/ | ||
props.client.asScoped = function (request: DashboardRequestEnhancedWithContext): ILegacyScopedClusterClient { |
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.
What do you think of using Proxy
instead of overwriting the original method? Something like this:
const proxy = new Proxy(legacyClient, {
get(target, prop) {
if (prop === 'asScoped') {
return (request) => {
if (/* data source id presents */) {
return {
callAsCurrentUser: async () => {/.../},
callAsInternalUser: async () => {/.../},
};
}
return target.asScoped(request);
};
}
return Reflect.get(...arguments);
},
});
// then use legacyClient proxy
const indexService = new IndexService(proxy);
context: RequestHandlerContext, | ||
request: OpenSearchDashboardsRequest | ||
) => { | ||
(request as DashboardRequestEnhancedWithContext)[`${props.pluginId}_context`] = context as IRequestHandlerContentWithDataSource; |
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 remember you mentioned the concern of putting _data_source_id_
in http headers and the challenge of moving it to url search parameters.
Since we modified the original request
here anyway(though it looks a bit hacky as registerRouteHandlerContext
is not intent for this). If we end up with modifying the request object, perhaps we can also do this to handle data source id in search parameters:
core.http.registerRouteHandlerContext(`${props.pluginId}_MDS_CTX_SUPPORT`, (ctx, req) => {
req[`${props.pluginId}_context`] = ctx;
if (req.url.searchParams.has('__data_source_id__')) {
// add data source id to request object so later access
req[`${props.pluginId}_data_source_id`] = req.url.searchParams.get('__data_source_id__');
// then we can remove it from search params so it won't bother router validators.
req.url.searchParams.delete('__data_source_id__');
}
return {};
});
9ea1a39
to
6386623
Compare
Signed-off-by: suzhou <[email protected]>
Signed-off-by: suzhou <[email protected]>
Signed-off-by: suzhou <[email protected]>
Signed-off-by: suzhou <[email protected]>
Signed-off-by: suzhou <[email protected]>
Signed-off-by: suzhou <[email protected]>
6386623
to
165b91c
Compare
Description
[Describe what this change achieves]
Issues Resolved
[List any issues this PR will resolve]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.