Skip to content
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

Datasource id is required if multiple datasource is enabled and no default cluster supported #5751

Conversation

xinruiba
Copy link
Member

@xinruiba xinruiba commented Jan 29, 2024

Description

When datasource_id is empty and default cluster not supported, the search returns 500 error which is unexpected since this is more of input error. This change is to check if multiple datasource enabled and default cluster not supported, when search with a empty datasource_id then the request is invalid and should return code 400.

Issues Resolved

#5754
#5699

Testing the changes

  1. Send empty datasource_id in the payload with datasource enabled and defaultCluster disabled in the yaml config returns 400 instead of 500

     Request:
     `curl 'localhost:5601/internal/search/opensearch' --data '{"params": {"index":"movies*","body":{},"preference":1697624613679}, "dataSourceId": ""}' -H 'x-amzn-aosd-app-id:random' -H 'osd-xsrf:osd-fetch' -H 'Content-Type:application/json'`
    
     Response:
     `{"statusCode":400,"error":"Bad Request","message":"Data Source Error: Data source id is required when no openseach hosts config provided","attributes":{"error":"Data Source Error: Data source id is required when no openseach hosts config provided"}}`
    
  2. Send payload with no datasource_id in the payload with datasource enabled and defaultCluster disabled in the yaml config returns 400 instead of 500

     Request:
     `curl 'localhost:5601/internal/search/opensearch' --data '{"params": {"index":"movies*","body":{},"preference":1697624613679}}' -H 'x-amzn-aosd-app-id:random' -H 'osd-xsrf:osd-fetch' -H 'Content-Type:application/json'`
    
     Response:
     `{"statusCode":400,"error":"Bad Request","message":"Data Source Error: Data source id is required when no openseach hosts config provided","attributes":{"error":"Data Source Error: Data source id is required when no openseach hosts config provided"}}`
    
  3. Send payload with invalid datasource_id

     Request:
     `curl 'localhost:5601/internal/search/opensearch' --data '{"params": {"index":"movies*","body":{},"preference":1697624613679}, "dataSourceId": "invalid"}' -H 'x-amzn-aosd-app-id:random' -H 'osd-xsrf:osd-fetch' -H 'Content-Type:application/json'`
    
     Response:
     `{"statusCode":404,"error":"Not Found","message":"Data Source Error: Data Source Error: Saved object [data-source/invalid] not found","attributes":{"error":"Data Source Error: Data Source Error: Saved object [data-source/invalid] not found"}}`
    

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

…fault cluster supported

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (8e93c54) 66.96% compared to head (9f5bb9a) 66.97%.

Files Patch % Lines
...a/server/search/opensearch_search/decide_client.ts 66.66% 0 Missing and 1 partial ⚠️
...ch/opensearch_search/opensearch_search_strategy.ts 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5751   +/-   ##
=======================================
  Coverage   66.96%   66.97%           
=======================================
  Files        3301     3301           
  Lines       63434    63437    +3     
  Branches    10104    10107    +3     
=======================================
+ Hits        42480    42487    +7     
+ Misses      18502    18498    -4     
  Partials     2452     2452           
Flag Coverage Δ
Linux_1 35.22% <0.00%> (-0.01%) ⬇️
Linux_2 55.11% <0.00%> (-0.01%) ⬇️
Linux_3 43.92% <75.00%> (+0.01%) ⬆️
Linux_4 35.27% <0.00%> (-0.01%) ⬇️
Windows_1 35.25% <0.00%> (-0.01%) ⬇️
Windows_2 55.08% <0.00%> (-0.01%) ⬇️
Windows_3 43.95% <75.00%> (+0.01%) ⬆️
Windows_4 35.27% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@BionIT BionIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments about the feature flag

@bandinib-amzn
Copy link
Member

I see this issue is introduced when config option added for hide/show local cluster option in data source picker.

  1. I would move the change of adding feature flag to PRs addressing [MD] Able to Hide "Local Cluster" option from datasource DropDown and Index Pattern creation page #5754
  2. Also I would like to merge this PR after [MD] Able to Hide "Local Cluster" option from datasource DropDown and Index Pattern creation page #5754 as this issue only happens when bothdata_source.enabled and 'defaultCluster` are disabled (value of both settings are false). If there is no hide/show local cluster change, then I don't see the issue as local cluster id will always gets passed.

@xinruiba
Copy link
Member Author

xinruiba commented Feb 1, 2024

I see this issue is introduced when config option added for hide/show local cluster option in data source picker.

  1. I would move the change of adding feature flag to PRs addressing Add a new feature flag under data_source to enable/disabled default cluster  #5754
  2. Also I would like to merge this PR after Add a new feature flag under data_source to enable/disabled default cluster  #5754 as this issue only happens when bothdata_source.enabled and 'defaultCluster` are disabled (value of both settings are false). If there is no hide/show local cluster change, then I don't see the issue as local cluster id will always gets passed.

Thanks for the comments, I create a quick one pager, let's review it first~

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
@Flyingliuhub Flyingliuhub added multiple datasource multiple datasource project v2.12.0 and removed first-time-contributor labels Feb 5, 2024
@xinruiba
Copy link
Member Author

xinruiba commented Feb 5, 2024

I see this issue is introduced when config option added for hide/show local cluster option in data source picker.

  1. I would move the change of adding feature flag to PRs addressing [MD] Able to Enabled/Disable "Local Cluster" option from datasource DropDown and Index Pattern creation page #5754
  2. Also I would like to merge this PR after [MD] Able to Enabled/Disable "Local Cluster" option from datasource DropDown and Index Pattern creation page #5754 as this issue only happens when bothdata_source.enabled and 'defaultCluster` are disabled (value of both settings are false). If there is no hide/show local cluster change, then I don't see the issue as local cluster id will always gets passed.

Based on the one pager, this change is for server error handling, and able to decoupled from other UX changes.
Synced with team offline, this PR should be able to merge in. Thanks

Also this change will in main branch, not target to 2.12.
I will send another PR to raise the UX changes and let's discuss the target release version after that.

Thanks

@Flyingliuhub Flyingliuhub merged commit bbd40e1 into opensearch-project:main Feb 6, 2024
68 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-5751-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 bbd40e105089f4efe75c7bd94ab9231dbbb93580
# Push it to GitHub
git push --set-upstream origin backport/backport-5751-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-5751-to-2.x.

@kavilla
Copy link
Member

kavilla commented Feb 7, 2024

Not required for 2.12 @xinruiba will you be able to create a manual backport PR?

opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 7, 2024
…fault cluster supported (#5751)

* datasource id is required if multiple datasource is enabled and no default cluster supported

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>

---------

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
(cherry picked from commit bbd40e1)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ZilongX pushed a commit that referenced this pull request Feb 20, 2024
…fault cluster supported (#5751) (#5842)

* datasource id is required if multiple datasource is enabled and no default cluster supported



---------


(cherry picked from commit bbd40e1)

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants