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]Optional workspaces params in repository #5949

Merged

Conversation

SuZhou-Joe
Copy link
Member

@SuZhou-Joe SuZhou-Joe commented Feb 26, 2024

Description

As workspace will be a new concept to organize saved objects, this PR add a new field workspaces to indicate which workspaces the objects belong to and consume the field in related methods.

  • Add workspaces field in saved objects mappings
  • Consume worksapces when create object
  • Consume workspaces when bulkCreate objects
  • Consume workspaces when checkConflicts

Issues Resolved

Partial #4944

Screenshot

As all of the changes happens in server side, currently do not have screenshot for this PR.

Testing the changes

As all of the changes happens in server side, can not test from browser, so we can run the integration_test in src/plugins/workspace/server/saved_objects/integration_tests/saved_objects_wrapper_for_check_workspace_conflict.test.ts. The test covers the cases:

  • Create object by calling /api/saved_objects/${type} with workspaces field, and the response of the created body contains workspaces field.
  • Overwrite a existing workspace(worksapce id: foo) with workspace id: bar, the API gives 409 error and the overwrite doesn't happen.
  • Call bulkCreate API to create two objects in different workspaces successfully.
  • Call bulkCreate API to overwrite a object existing in workspace foo with params workspace bar, and it returns the failed error.
  • Call import API to overwrite a object existing in workspace foo with params workspace bar, and it returns the failed error.
  • Call find API to get all the objects under a specific workspace successfully.

Check List

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

Copy link

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 67.04%. Comparing base (6d5560e) to head (e194b51).
Report is 10 commits behind head on main.

❗ Current head e194b51 differs from pull request most recent head 984d51a. Consider uploading reports for the commit 984d51a to get more accurate results

Files Patch % Lines
...ed_objects_wrapper_for_check_workspace_conflict.ts 88.00% 2 Missing and 7 partials ⚠️
...rc/core/server/saved_objects/routes/bulk_create.ts 0.00% 2 Missing ⚠️
src/core/server/saved_objects/routes/create.ts 0.00% 2 Missing ⚠️
...ved_objects/service/lib/search_dsl/query_params.ts 66.66% 1 Missing and 1 partial ⚠️
...ed_objects/export/get_sorted_objects_for_export.ts 0.00% 0 Missing and 1 partial ⚠️
src/core/server/saved_objects/routes/export.ts 0.00% 1 Missing ⚠️
...ore/server/saved_objects/service/lib/repository.ts 80.00% 0 Missing and 1 partial ⚠️
src/core/server/saved_objects/service/lib/utils.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5949      +/-   ##
==========================================
+ Coverage   67.01%   67.04%   +0.02%     
==========================================
  Files        3310     3311       +1     
  Lines       63647    63737      +90     
  Branches    10165    10194      +29     
==========================================
+ Hits        42656    42731      +75     
- Misses      18522    18526       +4     
- Partials     2469     2480      +11     
Flag Coverage Δ
Linux_1 31.65% <69.47%> (-3.57%) ⬇️
Linux_2 55.09% <50.00%> (+<0.01%) ⬆️
Linux_3 44.36% <0.00%> (-0.03%) ⬇️
Linux_4 35.18% <0.00%> (-0.02%) ⬇️
Windows_1 31.67% <69.47%> (-3.57%) ⬇️
Windows_2 55.06% <50.00%> (+<0.01%) ⬆️
Windows_3 44.38% <0.00%> (-0.03%) ⬇️
Windows_4 35.18% <0.00%> (-0.02%) ⬇️

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.

@SuZhou-Joe SuZhou-Joe force-pushed the feature/workspace-parameters branch 2 times, most recently from ed4126a to 720e5ba Compare February 29, 2024 09:02
@SuZhou-Joe SuZhou-Joe marked this pull request as ready for review February 29, 2024 09:02
@SuZhou-Joe SuZhou-Joe requested review from ruanyl and BionIT as code owners March 1, 2024 02:17
@SuZhou-Joe
Copy link
Member Author

@kavilla @Flyingliuhub @ashwin-pc , could you please take a look on this PR? This PR introduces many fundamental features for Workspace and are totally controlled behind a workspace.enabled feature flag.

Copy link
Member

@seraphjiang seraphjiang left a comment

Choose a reason for hiding this comment

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

@SuZhou-Joe would you add the new config to OSD.yaml file

With disable by default and comment out.

Also add a few words to describe the feature flag

@SuZhou-Joe
Copy link
Member Author

@SuZhou-Joe would you add the new config to OSD.yaml file

With disable by default and comment out.

Also add a few words to describe the feature flag

Thanks and done for that.

@SuZhou-Joe
Copy link
Member Author

LGTM for the initial iteration, would this feature need backporting to 2.x ?

We'd like to backport to 2.x until other down stream PRs get merged, thanks for the call out.

@@ -557,6 +564,7 @@ export class SavedObjectsService
this.logger,
migrationsRetryDelay
),
opensearchDashboardsRawConfig: this.opensearchDashboardsRawConfig as Config,
Copy link
Member

Choose a reason for hiding this comment

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

What about just passing a minimum set of config which is only required down to the functions instead of passing the entire config object? Similar to savedObjectsConfig

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to keep as it is because:

  1. If we do some filter here, once we introduce more config to control the mappings dynamically, we need to change two places, filter and the build_active_mapping
  2. For now the configService.atPath does not provide functionality to subscribe to multiple paths(even though it accepts string[], it is more like a lodash.get(obj, path)).

.map((object) => {
const { type, id } = object;
/**
* It requires a check when overwriting objects to target workspaces
Copy link
Member

Choose a reason for hiding this comment

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

Q: how this comment relates to the code next?

);
}
public wrapperFactory: SavedObjectsClientWrapperFactory = (wrapperOptions) => {
const createWithWorkspaceConflictCheck = async <T = unknown>(
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to leave a comment to explain from high level of why a wrapper is necessary for create and bulkCreate

@SuZhou-Joe
Copy link
Member Author

@ruanyl Will raise a following PR to address your comment.

@SuZhou-Joe SuZhou-Joe merged commit c6b4c34 into opensearch-project:main Mar 4, 2024
18 checks passed
SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Mar 4, 2024
…ct#5949)

* refact: move workspace specific logic to savedObjectWrapper

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

* fix: some error

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

* feat: fix test error

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

* feat: remove useless config in test

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

* feat: add CHANGELOG

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

* feat: add more unit test

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

* fix: unit test

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

* feat: revert test in repository.test.js

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

* feat: revert test in import_saved_objects.test.ts

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

* feat: revert test in repository.test.js

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

* feat: add type

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

* fix: bootstrap type error

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

* feat: optimize code and add comment

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

* fix: unit test error

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

* fix: integration test fail

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

* feat: add missing code

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

* feat: optimize code

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

* Add permissions field to the mapping only if the permission control is enabled

Signed-off-by: gaobinlong <[email protected]>

* Fix test failure

Signed-off-by: gaobinlong <[email protected]>

* feat: modify unit test

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

* fix: bulk create error

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

* fix: bulk create error

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

* feat: add new config in yml file

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

* feat: add new config in yml file

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

* feat: update yml file

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

* feat: fix unit test

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

* feat: do not skip migration when doing integration test

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

* feat: remove useless code

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

* feat: remove useless code

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

* feat: change flag variable

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

* feat: add test cases

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Mar 4, 2024
@SuZhou-Joe SuZhou-Joe mentioned this pull request Mar 4, 2024
8 tasks
SuZhou-Joe added a commit to ruanyl/OpenSearch-Dashboards that referenced this pull request Mar 4, 2024
* feat: cherry-pick pr opensearch-project#5949

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

* fix: bootstrap error

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

* fix: unit test error

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

* fix: unit test

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

* feat: remove useless CHANGELOG

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

* feat: update snapshot

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
SuZhou-Joe added a commit that referenced this pull request Mar 4, 2024
* feat: temp save

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

* fix: unit test

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

* feat: add some comment

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Mar 4, 2024
…ct#6012)

* feat: temp save

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

* fix: unit test

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

* feat: add some comment

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Mar 4, 2024
…ct#6012)

* feat: temp save

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

* fix: unit test

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

* feat: add some comment

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
SuZhou-Joe added a commit to ruanyl/OpenSearch-Dashboards that referenced this pull request Mar 5, 2024
…ct#6012) (#276)

* feat: temp save



* fix: unit test



* feat: add some comment



---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
SuZhou-Joe added a commit to ruanyl/OpenSearch-Dashboards that referenced this pull request Mar 5, 2024
…ct#6012) (#277)

* feat: temp save



* fix: unit test



* feat: add some comment



---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
@ruanyl ruanyl removed the v2.13.0 label Mar 12, 2024
@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-5949-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c6b4c34956d51c9fc60210ae9b0b3477d58eee5f
# Push it to GitHub
git push --set-upstream origin backport/backport-5949-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-5949-to-2.x.

SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Apr 10, 2024
…ct#5949)

* refact: move workspace specific logic to savedObjectWrapper

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

* fix: some error

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

* feat: fix test error

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

* feat: remove useless config in test

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

* feat: add CHANGELOG

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

* feat: add more unit test

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

* fix: unit test

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

* feat: revert test in repository.test.js

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

* feat: revert test in import_saved_objects.test.ts

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

* feat: revert test in repository.test.js

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

* feat: add type

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

* fix: bootstrap type error

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

* feat: optimize code and add comment

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

* fix: unit test error

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

* fix: integration test fail

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

* feat: add missing code

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

* feat: optimize code

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

* Add permissions field to the mapping only if the permission control is enabled

Signed-off-by: gaobinlong <[email protected]>

* Fix test failure

Signed-off-by: gaobinlong <[email protected]>

* feat: modify unit test

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

* fix: bulk create error

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

* fix: bulk create error

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

* feat: add new config in yml file

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

* feat: add new config in yml file

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

* feat: update yml file

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

* feat: fix unit test

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

* feat: do not skip migration when doing integration test

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

* feat: remove useless code

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

* feat: remove useless code

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

* feat: change flag variable

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

* feat: add test cases

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
(cherry picked from commit c6b4c34)
SuZhou-Joe added a commit to SuZhou-Joe/OpenSearch-Dashboards that referenced this pull request Apr 10, 2024
…ct#6012)

* feat: temp save

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

* fix: unit test

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

* feat: add some comment

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
SuZhou-Joe added a commit that referenced this pull request Apr 11, 2024
) (#6387)

* [Workspace]Optional workspaces params in repository (#5949)

* refact: move workspace specific logic to savedObjectWrapper

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

* fix: some error

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

* feat: fix test error

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

* feat: remove useless config in test

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

* feat: add CHANGELOG

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

* feat: add more unit test

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

* fix: unit test

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

* feat: revert test in repository.test.js

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

* feat: revert test in import_saved_objects.test.ts

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

* feat: revert test in repository.test.js

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

* feat: add type

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

* fix: bootstrap type error

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

* feat: optimize code and add comment

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

* fix: unit test error

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

* fix: integration test fail

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

* feat: add missing code

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

* feat: optimize code

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

* Add permissions field to the mapping only if the permission control is enabled

Signed-off-by: gaobinlong <[email protected]>

* Fix test failure

Signed-off-by: gaobinlong <[email protected]>

* feat: modify unit test

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

* fix: bulk create error

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

* fix: bulk create error

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

* feat: add new config in yml file

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

* feat: add new config in yml file

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

* feat: update yml file

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

* feat: fix unit test

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

* feat: do not skip migration when doing integration test

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

* feat: remove useless code

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

* feat: remove useless code

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

* feat: change flag variable

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

* feat: add test cases

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
(cherry picked from commit c6b4c34)

* [Workspace]Following pr for #5949 (#6012)

* feat: temp save

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

* fix: unit test

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

* feat: add some comment

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

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
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.

9 participants