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]Fix maximum call stack error in use case service #7817

Conversation

wanglam
Copy link
Contributor

@wanglam wanglam commented Aug 23, 2024

Description

This PR is for fixing maximum call stack error in use case service, separate a function to compare features using sort instead of using Array.property.some.
The root cause of this bug should be error features compare result see below example:

// use case 1
{
    features:[{id:"1"},{id:"2"}]
}
// use case 2
{
    features:[{id:"1"},{id:"2"}]
}

The result should be true which means two use case should be equal. But the old compare logic will return false. We should change b.features.some to b.features.every, then the result would be correct. Using some and every to implement the compare logic would be a little bit complicated, it can't handle duplicate features. So we change to use sort to compare the use case.

Issues Resolved

#7820

Screenshot

No UI changes

Testing the changes

  • Clone branch code and run yarn osd bootstrap --single-version ignore
  • Add below configs in config/opensearch_dashboards.yml
workspace.enabled: true
uiSettings:
  overrides:
    'home:useNewHomePage': true
  • Run yarn start --no-base-path
  • Login and visit workspace detail page
  • Open devtools and should no Maximum call stack error in the console

Changelog

  • fix: [Workspace] maximum call stack error in use case service

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

Signed-off-by: Lin Wang <wonglam@amazon.com>
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.83%. Comparing base (3364d0c) to head (5508ff0).
Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7817   +/-   ##
=======================================
  Coverage   63.82%   63.83%           
=======================================
  Files        3658     3658           
  Lines       81286    81288    +2     
  Branches    12975    12974    -1     
=======================================
+ Hits        51884    51888    +4     
+ Misses      26217    26216    -1     
+ Partials     3185     3184    -1     
Flag Coverage Δ
Linux_1 30.16% <100.00%> (+<0.01%) ⬆️
Linux_2 55.87% <ø> (ø)
Linux_3 40.42% <ø> (+<0.01%) ⬆️
Linux_4 31.29% <ø> (ø)
Windows_1 30.18% <100.00%> (+<0.01%) ⬆️
Windows_2 55.82% <ø> (ø)
Windows_3 40.42% <ø> (ø)
Windows_4 31.29% <ø> (ø)

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.

Comment on lines 263 to 280
const compareFeatures = (
features1: WorkspaceUseCaseFeature[],
features2: WorkspaceUseCaseFeature[]
) => {
const featureSerialize = ({ id, title }: WorkspaceUseCaseFeature) => `${id}-${title}`;
const features1Set = new Set(features1.map(featureSerialize));
const features2Set = new Set(features2.map(featureSerialize));
if (features1Set.size !== features2Set.size) {
return false;
}
for (const feature of features1Set) {
if (!features2Set.has(feature)) {
return false;
}
}
return true;
};

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can simplify the compare by sorting the serialized array and see if JSON.stringify(sortArray) equals?

Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
@SuZhou-Joe SuZhou-Joe added backport 2.x v2.17.0 bug Something isn't working labels Aug 24, 2024
@SuZhou-Joe SuZhou-Joe merged commit 452b65d into opensearch-project:main Aug 24, 2024
76 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-7817-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 452b65dceff7c9a2f283f0dda0793d0a4a8f3aba
# Push it to GitHub
git push --set-upstream origin backport/backport-7817-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-7817-to-2.x.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 26, 2024
* Fix maximum call stack error in UseCaseService

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Changeset file for PR #7817 created/updated

* Improve UT coverage

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Refactor compare with sort

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Refactor compareFeatures

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Add ut for multi same features

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 452b65d)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ruanyl pushed a commit that referenced this pull request Aug 26, 2024
…7840)

* Fix maximum call stack error in UseCaseService



* Changeset file for PR #7817 created/updated

* Improve UT coverage



* Refactor compare with sort



* Refactor compareFeatures



* Add ut for multi same features



---------



(cherry picked from commit 452b65d)

Signed-off-by: Lin Wang <wonglam@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>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
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.

3 participants