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

fix bug: management section id not match the key defined in capabilities #6421

Conversation

ruanyl
Copy link
Member

@ruanyl ruanyl commented Apr 12, 2024

Description

The Dashboards management section id(opensearch-dashboards) of Management category doesn't match the id(opensearchDashboards) defined in capabilities, the consequence is the following code will never work for apps of Dashboards management. Even set the capability of the app to false, the nav link still displayed on the UI(it does redirect to home page when accessing the link).

    this.getAllSections().forEach((section) => {
      if (capabilities.management.hasOwnProperty(section.id)) {
        const sectionCapabilities = capabilities.management[section.id];
        section.apps.forEach((app) => {
          if (sectionCapabilities.hasOwnProperty(app.id) && sectionCapabilities[app.id] !== true) {
            app.disable();
          }
        });
      }
    });

The original PR introduced the id change is #260
@kavilla do you have more context of changing id from opensearchDashboards to opensearch-dashboards?

Changelog

  • fix: management section id not match the key defined in capabilities

Issues Resolved

Screenshot

Testing the changes

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

@ruanyl ruanyl added bug Something isn't working and removed bug Something isn't working labels Apr 12, 2024
@ruanyl ruanyl force-pushed the fix-management-section-id-not-match-capabilities branch from 81ce8d3 to ca218bb Compare April 12, 2024 10:14
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.96%. Comparing base (376ead0) to head (da608d3).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6421      +/-   ##
==========================================
- Coverage   67.72%   63.96%   -3.77%     
==========================================
  Files        3518     3598      +80     
  Lines       69638    78266    +8628     
  Branches    11365    12340     +975     
==========================================
+ Hits        47165    50061    +2896     
- Misses      19684    25185    +5501     
- Partials     2789     3020     +231     
Flag Coverage Δ
Linux_1 31.07% <ø> (-2.09%) ⬇️
Linux_2 55.53% <ø> (+0.06%) ⬆️
Linux_3 41.30% <ø> (-2.02%) ⬇️
Linux_4 31.54% <100.00%> (-3.15%) ⬇️
Windows_1 31.09% <ø> (-2.12%) ⬇️
Windows_2 55.48% <ø> (+0.06%) ⬆️
Windows_3 41.31% <ø> (-2.03%) ⬇️
Windows_4 31.54% <100.00%> (-3.15%) ⬇️

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.

@@ -94,8 +98,9 @@ export class ManagementSectionsService {

start({ capabilities }: SectionsServiceStartDeps) {
this.getAllSections().forEach((section) => {
if (capabilities.management.hasOwnProperty(section.id)) {
const sectionCapabilities = capabilities.management[section.id];
const capabilityId = MANAGEMENT_ID_TO_CAPABILITIES[section.id] || section.id;
Copy link
Member

Choose a reason for hiding this comment

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

@ruanyl Just curious to know why don't we instead update the Id in the Capabilities to opensearch-dashboards instead of mapping it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@manasvinibs Good question, that's for compatibility, opensearch-dashboards maybe deep linked, for example, in function test repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

@kavilla Is there a way to estimate the impact of changing capabilities key from opensearchDashboards to opensearch-dashboards in src/plugins/management/server/capabilities_provider.ts?

Copy link
Member Author

@ruanyl ruanyl Jul 21, 2024

Choose a reason for hiding this comment

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

I've seen some places in OSD core uses capabilities.management.opensearchDashboards, also there might other plugins are already using this capability key, changing this key would be a breaking change, so I think it would be better to do key mapping. What do you think? @manasvinibs

opensearch-changeset-bot bot added a commit to ruanyl/OpenSearch-Dashboards that referenced this pull request May 24, 2024
@@ -94,8 +98,9 @@ export class ManagementSectionsService {

start({ capabilities }: SectionsServiceStartDeps) {
this.getAllSections().forEach((section) => {
if (capabilities.management.hasOwnProperty(section.id)) {
const sectionCapabilities = capabilities.management[section.id];
const capabilityId = MANAGEMENT_ID_TO_CAPABILITIES[section.id] || section.id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an associated test to validate this is working correctly?

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

@virajsanghvi unit test added

@BionIT
Copy link
Collaborator

BionIT commented Jun 5, 2024

Hi @ruanyl , are we targeting this PR for 2.15 or 2.16?

@ruanyl
Copy link
Member Author

ruanyl commented Jun 5, 2024

Hi @ruanyl , are we targeting this PR for 2.15 or 2.16?

Maybe 2.16, haven't got a chance to add unit tests

@BionIT BionIT added the v2.16.0 label Jun 5, 2024
@ruanyl ruanyl force-pushed the fix-management-section-id-not-match-capabilities branch from 374a6dc to ea9f4ea Compare July 21, 2024 12:31
@ruanyl ruanyl requested a review from LDrago27 as a code owner July 21, 2024 12:31
@ruanyl
Copy link
Member Author

ruanyl commented Jul 21, 2024

@virajsanghvi @manasvinibs Could you please take another look at the PR?

Comment on lines +111 to +112
const originalDataSourcesCapability =
DEFAULT_MANAGEMENT_CAPABILITIES.management.opensearchDashboards.dataSources;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: ideally we could mock this over setting it globally, but you do clean it up so not blocking.

@@ -105,4 +106,29 @@ describe('ManagementService', () => {
]
`);
});

it('should disable apps register in opensearchDashboards section', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help explain how this is testing the "opensearch-dashboards" translation code?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the capability provider, the capability key is opensearchDashboards, when registering the default section opensearchDashboards: this.registerSection(OpenSearchDashboardsSection), the section id is defined as opensearch-dashboards and this id was used to retrieve the app status register with capability key opensearchDashboards.

So we need to do the mapping from opensearch-dashboards -> opensearchDashboards

@ruanyl ruanyl merged commit a65a8aa into opensearch-project:main Aug 7, 2024
70 of 71 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 7, 2024
…ies (#6421)

* fix management section id not match the key defined in capabilities

Signed-off-by: Yulong Ruan <[email protected]>

* add descriptions on how the PR solved the problme

Signed-off-by: Yulong Ruan <[email protected]>

---------

Signed-off-by: Yulong Ruan <[email protected]>
(cherry picked from commit a65a8aa)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
SuZhou-Joe pushed a commit that referenced this pull request Aug 19, 2024
…ies (#6421) (#7634)

* fix management section id not match the key defined in capabilities



* add descriptions on how the PR solved the problme



---------


(cherry picked from commit a65a8aa)

Signed-off-by: Yulong Ruan <[email protected]>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants