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

Add version decoupling meta for MDS #338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"dashboard",
"opensearchUiShared"
],
"optionalPlugins": ["dataSource", "dataSourceManagement"]
"optionalPlugins": ["dataSource", "dataSourceManagement"],
"supportedOSDataSourceVersions": ">=2.9.0",
"requiredOSDataSourcePlugins": ["opensearch-ml"]
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

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

Are these key names defined by each plugins? Is it standardized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. These key names were been introduced in these two PRs:
opensearch-project/OpenSearch-Dashboards#7146
opensearch-project/OpenSearch-Dashboards#7100
They are optional properties, all plugins should using the same key names.

}
2 changes: 2 additions & 0 deletions public/components/data_source_top_nav_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
DataSourceSelectableConfig,
} from '../../../../src/plugins/data_source_management/public';
import { DataSourceContext } from '../contexts/data_source_context';
import { isDataSourceCompatible } from '../utils/data_source';

export interface DataSourceTopNavMenuProps {
notifications: CoreStart['notifications'];
Expand Down Expand Up @@ -53,6 +54,7 @@ export const DataSourceTopNavMenu = ({
savedObjects: savedObjects.client,
onSelectedDataSources: handleDataSourcesSelected,
activeOption,
dataSourceFilter: isDataSourceCompatible,
}}
setMenuMountPoint={setActionMenu}
/>
Expand Down
68 changes: 67 additions & 1 deletion public/utils/__tests__/data_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DATA_SOURCE_FETCHING_ID, DATA_SOURCE_INVALID_ID, getDataSourceId } from '../data_source';
import {
DATA_SOURCE_FETCHING_ID,
DATA_SOURCE_INVALID_ID,
getDataSourceId,
isDataSourceCompatible,
} from '../data_source';

describe('getDataSourceId', () => {
it('should return undefined when data source not enabled', () => {
Expand All @@ -27,3 +32,64 @@ describe('getDataSourceId', () => {
expect(getDataSourceId(true, { id: 'foo' })).toBe('foo');
});
});

describe('isDataSourceCompatible', () => {
it('should return true for compatible data sources', () => {
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-ml'],
dataSourceVersion: '2.9.0',
},
})
).toBe(true);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-ml'],
dataSourceVersion: '2.11.0',
},
})
).toBe(true);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-ml'],
dataSourceVersion: '2.13.0',
},
})
).toBe(true);
});

it('should return false for un-compatible data sources', () => {
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: [],
dataSourceVersion: '2.13.0',
},
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-jetty'],
dataSourceVersion: '2.13.0',
},
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {},
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-ml'],
dataSourceVersion: '2.7.0',
},
})
).toBe(false);
});
});
27 changes: 27 additions & 0 deletions public/utils/data_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import semver from 'semver';

import { DataSourceOption } from '../contexts';
import pluginManifest from '../../opensearch_dashboards.json';
import type { SavedObject } from '../../../../src/core/public';
import type { DataSourceAttributes } from '../../../../src/plugins/data_source/common/data_sources';

export const DATA_SOURCE_FETCHING_ID = Symbol('DATA_SOURCE_FETCHING_ID');
export const DATA_SOURCE_INVALID_ID = Symbol('DATA_SOURCE_INVALID_ID');
Expand All @@ -29,3 +33,26 @@ export const getDataSourceId = (
};

export type DataSourceId = ReturnType<typeof getDataSourceId>;

export const isDataSourceCompatible = (dataSource: SavedObject<DataSourceAttributes>) => {
if (
'requiredOSDataSourcePlugins' in pluginManifest &&
!pluginManifest.requiredOSDataSourcePlugins.every((plugin) =>
dataSource.attributes.installedPlugins?.includes(plugin)
)
) {
return false;
}

// filter out data sources which is NOT in the support range of plugin
if (
'supportedOSDataSourceVersions' in pluginManifest &&
!semver.satisfies(
dataSource.attributes.dataSourceVersion,
pluginManifest.supportedOSDataSourceVersions
)
) {
return false;
}
return true;
};
Loading