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

[Workspace] Add base path when parsing url in http service #6233

Merged
merged 7 commits into from
Mar 22, 2024

Conversation

SuZhou-Joe
Copy link
Member

@SuZhou-Joe SuZhou-Joe commented Mar 21, 2024

Description

Make basePath required in getWorkspaceIdFromUrl method.

Issues Resolved

fixes #6015

Screenshot

Testing the changes

  • Using the branch to bootstrap
  • Enable workspace by adding workspace.enabled to opensearch_dashboards.yml file
  • Start OSD by using yarn start to enable basePath feature.
  • Navigate to devTools
  • Insert test workspaces by calling
PUT .kibana/_doc/workspace:foo
{
  "type": "workspace",
  "workspace": {
    "name": "foo"
  }
}
  • Visit the OpenSearch Dashboards under foo workspace: http://localhost:5603/{random_basePath}/w/foo/app/dev_tools
  • The page should be able to load.

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

@SuZhou-Joe SuZhou-Joe changed the title fix: add base path when parse url in http service [Workspace] Add base path when parse url in http service Mar 21, 2024
Signed-off-by: SuZhou-Joe <[email protected]>
@SuZhou-Joe SuZhou-Joe added workspace bug Something isn't working labels Mar 21, 2024
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.33%. Comparing base (4a8e3e8) to head (5f05b34).
Report is 574 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6233      +/-   ##
==========================================
+ Coverage   67.28%   67.33%   +0.04%     
==========================================
  Files        3351     3351              
  Lines       65038    65037       -1     
  Branches    10475    10475              
==========================================
+ Hits        43763    43793      +30     
+ Misses      18704    18700       -4     
+ Partials     2571     2544      -27     
Flag Coverage Δ
Linux_1 31.82% <66.66%> (-0.01%) ⬇️
Linux_2 55.57% <100.00%> (?)
Linux_3 44.68% <100.00%> (?)
Linux_4 35.03% <50.00%> (?)
Windows_1 31.84% <66.66%> (-0.01%) ⬇️
Windows_2 55.53% <100.00%> (ø)
Windows_3 44.68% <100.00%> (-0.02%) ⬇️
Windows_4 35.03% <50.00%> (ø)

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.

Signed-off-by: SuZhou-Joe <[email protected]>
@SuZhou-Joe SuZhou-Joe changed the title [Workspace] Add base path when parse url in http service [Workspace] Add base path when parsing url in http service Mar 21, 2024
@xinruiba
Copy link
Member

LGTM, ship

@@ -8,11 +8,11 @@ import { httpServiceMock } from '../public/mocks';

describe('#getWorkspaceIdFromUrl', () => {
it('return workspace when there is a match', () => {
expect(getWorkspaceIdFromUrl('http://localhost/w/foo')).toEqual('foo');
expect(getWorkspaceIdFromUrl('http://localhost/w/foo', '')).toEqual('foo');
Copy link
Member

Choose a reason for hiding this comment

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

Q: why it need to specify '' as the second parameter explicitly?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe my question is more about why we need to change the getWorkspaceIdFromUrl function signature?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. From the implementation perspective, the basePath parameter is required when constructing the regular expression to parse the workspace id from url.
  2. The bug comes from the loose function signature, I change it to a more strict signature so that others won't step into similar bug.

@SuZhou-Joe SuZhou-Joe merged commit 0dce00a into opensearch-project:main Mar 22, 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-6233-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 0dce00a806bf8815ca84802541010767b6b3a8bd
# Push it to GitHub
git push --set-upstream origin backport/backport-6233-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-6233-to-2.x.

SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Apr 15, 2024
…h-project#6233)

* fix: add base path when parse url in http service

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add CHANGELOG

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize unit test cases for parse clientBasePath from url when basePath enabled

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add empty line before getWorkspaceIdFromURL method

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize comment

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Xinrui Bai-amazon <[email protected]>
(cherry picked from commit 0dce00a)
SuZhou-Joe added a commit that referenced this pull request Apr 16, 2024
…6451)

* fix: add base path when parse url in http service

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add CHANGELOG

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize unit test cases for parse clientBasePath from url when basePath enabled

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add empty line before getWorkspaceIdFromURL method

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize comment

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Xinrui Bai-amazon <[email protected]>
(cherry picked from commit 0dce00a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Workspace] Make url stateful in url with workspace id
5 participants