-
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] Improved error handling for the search API when a null value is passed for the dataSourceId. #5882
[MD] Improved error handling for the search API when a null value is passed for the dataSourceId. #5882
Conversation
…is empty, make error code to 400 Signed-off-by: Xinrui Bai <[email protected]>
Signed-off-by: Xinrui Bai <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5882 +/- ##
==========================================
- Coverage 67.01% 67.01% -0.01%
==========================================
Files 3310 3307 -3
Lines 63647 63616 -31
Branches 10165 10164 -1
==========================================
- Hits 42656 42633 -23
+ Misses 18522 18514 -8
Partials 2469 2469
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…binations of scenario Signed-off-by: Xinrui Bai <[email protected]>
…ed_WithNoHostConfig
Signed-off-by: Xinrui Bai <[email protected]>
? context.core.opensearch.client.asCurrentUserWithLongNumeralsSupport | ||
: context.core.opensearch.client.asCurrentUser; | ||
|
||
return withDataSourceEnabled && request.dataSourceId && context.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.
can we assume when data source is enabled, then context.dataSource is never undefined or vice 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.
+1 @xinruiba Do you have scenario where withDataSourceEnabled is true but context.dataSource is undefined?
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 the comments~
Yes, we can assume when data source is enabled, then context.dataSource is never undefined or vice versa because:
- "dataSource" will always been registered as "registerRouteHandlerContext" in dataSource plugin setup which means once dataSource plugin's setup function get called,
context.dataSource
will never be undefined. - If dataSource.enabled turns on, dataSource plugin's setup function will always get called.
In that case, withDataSourceEnabled
is not needed in this decide client function. I will remove it.
Thanks
src/plugins/data/server/search/opensearch_search/opensearch_search_strategy.ts
Outdated
Show resolved
Hide resolved
src/plugins/data/server/search/opensearch_search/opensearch_search_strategy.ts
Show resolved
Hide resolved
Signed-off-by: Xinrui Bai <[email protected]>
await opensearchSearch.search( | ||
(mockDataSourceEnabledContext as unknown) as RequestHandlerContext, | ||
{ | ||
dataSourceId: 'Some dataSourceId', | ||
} | ||
); | ||
|
||
expect(mockDataSourceApiCaller).toBeCalled(); | ||
expect(mockOpenSearchApiCaller).not.toBeCalled(); |
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.
Can you correct this according to test description?
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.
callAsInternalUser: jest.fn(), | ||
asScoped: jest.fn(), | ||
config: { | ||
hosts: [], |
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.
You are passing host empty. Can you correct test case description? Also do we have test case when host is not defined, means it is commented? In that case it should take default value and call opensearch client
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.
Both updated in the test case:
https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5882/files#diff-96950b20277c55c90d7592913fcc77ed6bac02a71701c784f2ac3b03c31d25d6R242
Thanks for the comment.
{ | ||
dataSourceId: '', | ||
} | ||
); |
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 pass empty? What if we don't pass at all? Can we cover both case pass empty or undefined value and doesn't pass at all
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.
Test case updated and handled here:
https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5882/files#diff-96950b20277c55c90d7592913fcc77ed6bac02a71701c784f2ac3b03c31d25d6R237
Thanks
await opensearchSearch.search( | ||
(mockDataSourceEnabledContext as unknown) as RequestHandlerContext, | ||
{ | ||
dataSourceId: 'Some dataSourceId', |
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 thought that you are testing send request without dataSourceid
, but pass dataSourceId: 'Some dataSourceId'
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.
Test cases updated, thanks for the comment.
src/plugins/data/server/search/opensearch_search/opensearch_search_strategy.test.ts
Show resolved
Hide resolved
Signed-off-by: Xinrui Bai <[email protected]>
…ed_WithNoHostConfig
Signed-off-by: Xinrui Bai <[email protected]>
…passed for the dataSourceId. (#5882) * [MD] Using legacy client cofig instead of globle config Signed-off-by: Xinrui Bai <[email protected]> * [UT] add test cases to test different hostconfig and datasourceId combinations of scenario Signed-off-by: Xinrui Bai <[email protected]> * Update changelog file Signed-off-by: Xinrui Bai <[email protected]> * Resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] update test cases and resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] Update unit test Signed-off-by: Xinrui Bai <[email protected]> --------- Signed-off-by: Xinrui Bai <[email protected]> (cherry picked from commit 7d77b9e) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…passed for the dataSourceId. (#5882) (#5969) * [MD] Using legacy client cofig instead of globle config * [UT] add test cases to test different hostconfig and datasourceId combinations of scenario * Update changelog file * Resolve comments * [UT] update test cases and resolve comments * [UT] Update unit test --------- (cherry picked from commit 7d77b9e) Signed-off-by: Xinrui Bai <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…passed for the dataSourceId. (opensearch-project#5882) * [MD] Using legacy client cofig instead of globle config Signed-off-by: Xinrui Bai <[email protected]> * [UT] add test cases to test different hostconfig and datasourceId combinations of scenario Signed-off-by: Xinrui Bai <[email protected]> * Update changelog file Signed-off-by: Xinrui Bai <[email protected]> * Resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] update test cases and resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] Update unit test Signed-off-by: Xinrui Bai <[email protected]> --------- Signed-off-by: Xinrui Bai <[email protected]>
…passed for the dataSourceId. (opensearch-project#5882) * [MD] Using legacy client cofig instead of globle config Signed-off-by: Xinrui Bai <[email protected]> * [UT] add test cases to test different hostconfig and datasourceId combinations of scenario Signed-off-by: Xinrui Bai <[email protected]> * Update changelog file Signed-off-by: Xinrui Bai <[email protected]> * Resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] update test cases and resolve comments Signed-off-by: Xinrui Bai <[email protected]> * [UT] Update unit test Signed-off-by: Xinrui Bai <[email protected]> --------- Signed-off-by: Xinrui Bai <[email protected]>
Description
#5880
Good error handling is important to help our customer understand our production's expected behavior.
This is the PR to improve the error handling process by providing
for the following scenario:
When MD is enabled, opensearch hosts not exist and search request send an empty datasource id. We should treat that request as a bad request with error code 400 instead of 500 along with a more descriptive error message.
Issues Resolved
Screenshot
N/A
Testing the changes
New test cases added
Check List
yarn test:jest
yarn test:jest_integration