-
Notifications
You must be signed in to change notification settings - Fork 906
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] Refactor data source server side error handling #2661
[MD] Refactor data source server side error handling #2661
Conversation
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 cast all search error against data source to 400 bad request, while maintaining the original error message from OS.
This worries me a lil because it is the root of a similar issue we face in other places in Dashboards where we incorrectly assign the wrong error code for a response. 4xx errors are auth errors.
- Is there really no way to assign the right error response code for an error?
- If not, why did you choose to use a 4xx error instead of a generic 5xx error?
src/plugins/data/server/search/opensearch_search/opensearch_search_strategy.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Su <szhongna@amazon.com>
Signed-off-by: Su <szhongna@amazon.com>
5c57559
to
6734e89
Compare
src/plugins/data/server/search/opensearch_search/opensearch_search_strategy.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Su <szhongna@amazon.com>
@ashwin-pc , thanks for the comments, really helpful. I re-worked on this PR. basically doing a refactor of existing error handling logic in data source feature. Now it will keep original status code. But for 401, we choose to cast to 400, due to the limitation of security dashboards plugin. For 5xx error, we cast to 400. Because it doesn't make sense to use 5xx, e.g user's data source domain is down, while trying to connect to it, we get 5xx. But there's nothing wrong with local OSD. Security review also mentioned it's not good to return 5xx for such cases |
@zhongnansu Thanks for that explanation! That logic makes sense to me. |
Signed-off-by: Su <szhongna@amazon.com>
const isDataSourceConfigError = (error: any) => { | ||
return error.constructor.name === 'DataSourceConfigError' && error.statusCode === 400; | ||
const isDataSourceError = (error: any) => { | ||
return error.constructor.name === 'DataSourceError' && error.statusCode === 400; |
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 use instanceof
instead of error.constructor.name
?
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.
importing DataSourceError
from plugin module to here(core module) doesn't sound like a good practice. But anyway, I did some refactor to move data source error response logic from router.ts
to resolve_index.ts
(/internal/index-pattern-manage/resolve-index).
I checked the codebase, only the route handler defined resolve_index is missing error handling. All other internal/xxx/xxx
API has err handling. E.g internal/search/
, /internal/_msearch
, /internal/index-pattern-manage/preview-script
```
catch (err) {
return res.customError({
statusCode: err.statusCode,
body: {
message: err.message,
attributes: {
error: err.body.error,
},
},
});
```
@zengyan-amazon could you review again
Signed-off-by: Su <szhongna@amazon.com>
c820a1e
to
0d8f5e3
Compare
Signed-off-by: Su <szhongna@amazon.com>
- Rename DataSourceConfigError to DataSourceError - Add helper createDataSourceError() to create data source error from, and replace usage of new DataSourceError(e) with createDataSourceError(e) - import createDataSourceError() from data source plugin setup interface, refactor to move data source error response logic from router.ts to resolve_index.ts. Signed-off-by: Su <szhongna@amazon.com> (cherry picked from commit 9a0bb30)
- Rename DataSourceConfigError to DataSourceError - Add helper createDataSourceError() to create data source error from, and replace usage of new DataSourceError(e) with createDataSourceError(e) - import createDataSourceError() from data source plugin setup interface, refactor to move data source error response logic from router.ts to resolve_index.ts. Signed-off-by: Su <szhongna@amazon.com> (cherry picked from commit 9a0bb30) Co-authored-by: Zhongnan Su <szhongna@amazon.com>
…ect#2661) - Rename DataSourceConfigError to DataSourceError - Add helper createDataSourceError() to create data source error from, and replace usage of new DataSourceError(e) with createDataSourceError(e) - import createDataSourceError() from data source plugin setup interface, refactor to move data source error response logic from router.ts to resolve_index.ts. Signed-off-by: Su <szhongna@amazon.com> Signed-off-by: Ajay Gupta <ajyg@amazon.com>
…ect#2661) - Rename DataSourceConfigError to DataSourceError - Add helper createDataSourceError() to create data source error from, and replace usage of new DataSourceError(e) with createDataSourceError(e) - import createDataSourceError() from data source plugin setup interface, refactor to move data source error response logic from router.ts to resolve_index.ts. Signed-off-by: Su <szhongna@amazon.com> Signed-off-by: Sergey V. Osipov <sipopo@yandex.ru>
…ect#2661) - Rename DataSourceConfigError to DataSourceError - Add helper createDataSourceError() to create data source error from, and replace usage of new DataSourceError(e) with createDataSourceError(e) - import createDataSourceError() from data source plugin setup interface, refactor to move data source error response logic from router.ts to resolve_index.ts. Signed-off-by: Su <szhongna@amazon.com> Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Signed-off-by: Su szhongna@amazon.com
Description
Refactor data source server side error handling
DataSourceConfigError
toDataSourceError
createDataSourceError()
to create data source error from:new DataSourceError(e)
withcreateDataSourceError(e)
createDataSourceError()
todata
plugin, have to import from data source plugin setup interface, otherwise, some other UTs in other modules failrouter.ts
toresolve_index.ts
. I check all our codebase, only the route handler defined resolve_index is missing error handling. All otherinternal/xxx/xxx
API has err handling. E.ginternal/search/
,/internal/_msearch
,/internal/index-pattern-manage/preview-script
Error statusCode casting logic
Issues Resolved
#2591
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr