Skip to content

Commit

Permalink
Add version decoupling meta for MDS (#338)
Browse files Browse the repository at this point in the history
* Add version decoupling meta for MDS

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

* Filter out not compatible data sources

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

* Fix in operator not work

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

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored Jul 11, 2024
1 parent 83b3a2d commit ab60678
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
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"]
}
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;
};

0 comments on commit ab60678

Please sign in to comment.