Skip to content

Commit d0b6be4

Browse files
opensearch-trigger-bot[bot]github-actions[bot]opensearch-changeset-bot[bot]
authored
[Multiple Datasource][Version Decoupling] Add data source engine type to data source saved object (#7026) (#7033)
* [Multiple Datasource][Version Decoupling] Add data source engine type to data source saved object * Changeset file for PR #7026 created/updated --------- (cherry picked from commit 190dab0) Signed-off-by: Zilong Xia <[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> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 7674d3c commit d0b6be4

File tree

8 files changed

+73
-21
lines changed

8 files changed

+73
-21
lines changed

changelogs/fragments/7026.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- [MDS] Add data source engine type to data source saved object ([#7026](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7026))

src/plugins/data_source/common/data_sources/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface DataSourceAttributes extends SavedObjectAttributes {
1010
description?: string;
1111
endpoint: string;
1212
dataSourceVersion?: string;
13+
dataSourceEngineType?: DataSourceEngineType;
1314
installedPlugins?: string[];
1415
auth: {
1516
type: AuthType | string;
@@ -52,3 +53,10 @@ export enum SigV4ServiceName {
5253
}
5354

5455
export { DataSourceError } from './error';
56+
57+
export enum DataSourceEngineType {
58+
OpenSearch = 'OpenSearch',
59+
OpenSearchServerless = 'OpenSearch Serverless',
60+
Elasticsearch = 'Elasticsearch',
61+
NA = 'No Engine Type Available',
62+
}

src/plugins/data_source/server/routes/data_source_connection_validator.test.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
2424
expect(validateDataSourcesResponse.statusCode).toBe(200);
2525
});
2626

27-
test('fetchDataSourceVersion - Success: opensearch client response code is 200 and response body have version number', async () => {
27+
test('fetchDataSourceInfo - Success: opensearch client response code is 200 and response body have version number and distribution', async () => {
2828
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
2929
opensearchClient.info.mockResolvedValue(
3030
opensearchServiceMock.createApiResponse({
3131
statusCode: 200,
3232
body: {
3333
version: {
3434
number: '2.11.0',
35+
distribution: 'opensearch',
3536
},
3637
},
3738
})
3839
);
3940
const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, {});
40-
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceVersion();
41-
expect(fetchDataSourcesVersionResponse).toBe('2.11.0');
41+
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceInfo();
42+
expect(fetchDataSourcesVersionResponse.dataSourceVersion).toBe('2.11.0');
43+
expect(fetchDataSourcesVersionResponse.dataSourceEngineType).toBe('OpenSearch');
4244
});
4345

4446
test('fetchInstalledPlugins - Success: opensearch client response code is 200 and response body have installed plugin list', async () => {
@@ -92,8 +94,8 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
9294
}
9395
});
9496

95-
// In case fetchDataSourceVersion call succeeded yet did not return version number, return an empty version instead of raising exceptions
96-
test('fetchDataSourceVersion - Success:opensearch client response code is 200 but response body does not have version number', async () => {
97+
// In case fetchDataSourceInfo call succeeded yet did not return version number and distribution, return an empty info instead of raising exceptions
98+
test('fetchDataSourceInfo - Success:opensearch client response code is 200 but response body does not have version number', async () => {
9799
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
98100
opensearchClient.info.mockResolvedValue(
99101
opensearchServiceMock.createApiResponse({
@@ -104,8 +106,9 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
104106
})
105107
);
106108
const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, {});
107-
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceVersion();
108-
expect(fetchDataSourcesVersionResponse).toBe('');
109+
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceInfo();
110+
expect(fetchDataSourcesVersionResponse.dataSourceVersion).toBe('');
111+
expect(fetchDataSourcesVersionResponse.dataSourceEngineType).toBe('No Engine Type Available');
109112
});
110113

111114
test('failure: opensearch client response code is other than 200', async () => {
@@ -130,8 +133,8 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
130133
});
131134
});
132135

133-
// In case fetchDataSourceVersion call failed, return an empty version instead of raising exceptions
134-
test('fetchDataSourceVersion - Failure: opensearch client response code is other than 200', async () => {
136+
// In case fetchDataSourceInfo call failed, return an empty info instead of raising exceptions
137+
test('fetchDataSourceInfo - Failure: opensearch client response code is other than 200', async () => {
135138
const statusCodeList = [100, 202, 300, 400, 500];
136139
statusCodeList.forEach(async function (code) {
137140
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
@@ -144,8 +147,11 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => {
144147
})
145148
);
146149
const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, {});
147-
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceVersion();
148-
expect(fetchDataSourcesVersionResponse).toBe('');
150+
const fetchDataSourcesVersionResponse = await dataSourceValidator.fetchDataSourceInfo();
151+
expect(fetchDataSourcesVersionResponse.dataSourceVersion).toBe('');
152+
expect(fetchDataSourcesVersionResponse.dataSourceEngineType).toBe(
153+
'No Engine Type Available'
154+
);
149155
});
150156
});
151157
});

src/plugins/data_source/server/routes/data_source_connection_validator.ts

+26-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import { OpenSearchClient } from 'opensearch-dashboards/server';
77
import { createDataSourceError } from '../lib/error';
8-
import { SigV4ServiceName } from '../../common/data_sources';
8+
import { DataSourceEngineType, SigV4ServiceName } from '../../common/data_sources';
9+
import { DataSourceInfo } from '../types';
10+
911
export class DataSourceConnectionValidator {
1012
constructor(
1113
private readonly callDataCluster: OpenSearchClient,
@@ -36,26 +38,42 @@ export class DataSourceConnectionValidator {
3638
}
3739
}
3840

39-
async fetchDataSourceVersion() {
40-
let dataSourceVersion = '';
41+
async fetchDataSourceInfo() {
42+
const dataSourceInfo: DataSourceInfo = {
43+
dataSourceVersion: '',
44+
dataSourceEngineType: DataSourceEngineType.NA,
45+
};
46+
4147
try {
4248
// OpenSearch Serverless does not have version concept
4349
if (
4450
this.dataSourceAttr.auth?.credentials?.service === SigV4ServiceName.OpenSearchServerless
4551
) {
46-
return dataSourceVersion;
52+
dataSourceInfo.dataSourceEngineType = DataSourceEngineType.OpenSearchServerless;
53+
return dataSourceInfo;
4754
}
55+
4856
await this.callDataCluster
4957
.info()
5058
.then((response) => response.body)
5159
.then((body) => {
52-
dataSourceVersion = body.version.number;
60+
dataSourceInfo.dataSourceVersion = body.version.number;
61+
62+
if (
63+
body.version.distribution !== null &&
64+
body.version.distribution !== undefined &&
65+
body.version.distribution === 'opensearch'
66+
) {
67+
dataSourceInfo.dataSourceEngineType = DataSourceEngineType.OpenSearch;
68+
} else {
69+
dataSourceInfo.dataSourceEngineType = DataSourceEngineType.Elasticsearch;
70+
}
5371
});
5472

55-
return dataSourceVersion;
73+
return dataSourceInfo;
5674
} catch (e) {
57-
// return empty dataSource version instead of throwing exception in case info() api call fails
58-
return dataSourceVersion;
75+
// return default dataSourceInfo instead of throwing exception in case info() api call fails
76+
return dataSourceInfo;
5977
}
6078
}
6179

src/plugins/data_source/server/routes/fetch_data_source_metadata.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
165165

166166
const router = httpSetup.createRouter('');
167167
dataSourceClient.info.mockImplementationOnce(() =>
168-
opensearchClientMock.createSuccessTransportRequestPromise({ version: { number: '2.11.0' } })
168+
opensearchClientMock.createSuccessTransportRequestPromise({
169+
version: { number: '2.11.0', distribution: 'opensearch' },
170+
})
169171
);
170172

171173
const installedPlugins = [
@@ -201,6 +203,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
201203
.expect(200);
202204
expect(result.body).toEqual({
203205
dataSourceVersion: '2.11.0',
206+
dataSourceEngineType: 'OpenSearch',
204207
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
205208
});
206209
expect(dataSourceServiceSetupMock.getDataSourceClient).toHaveBeenCalledWith(
@@ -224,6 +227,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
224227
.expect(200);
225228
expect(result.body).toEqual({
226229
dataSourceVersion: '2.11.0',
230+
dataSourceEngineType: 'OpenSearch',
227231
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
228232
});
229233
});
@@ -324,6 +328,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
324328
.expect(200);
325329
expect(result.body).toEqual({
326330
dataSourceVersion: '2.11.0',
331+
dataSourceEngineType: 'OpenSearch',
327332
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
328333
});
329334
});
@@ -338,6 +343,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
338343
.expect(200);
339344
expect(result.body).toEqual({
340345
dataSourceVersion: '2.11.0',
346+
dataSourceEngineType: 'OpenSearch',
341347
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
342348
});
343349
});
@@ -352,6 +358,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
352358
.expect(200);
353359
expect(result.body).toEqual({
354360
dataSourceVersion: '2.11.0',
361+
dataSourceEngineType: 'OpenSearch',
355362
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
356363
});
357364
});
@@ -366,6 +373,7 @@ describe(`Fetch DataSource MetaData ${URL}`, () => {
366373
.expect(200);
367374
expect(result.body).toEqual({
368375
dataSourceVersion: '2.11.0',
376+
dataSourceEngineType: 'OpenSearch',
369377
installedPlugins: ['opensearch-ml', 'opensearch-sql'],
370378
});
371379
});

src/plugins/data_source/server/routes/fetch_data_source_metadata.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ export const registerFetchDataSourceMetaDataRoute = async (
9494
dataSourceAttr
9595
);
9696

97-
const dataSourceVersion = await dataSourceValidator.fetchDataSourceVersion();
97+
const dataSourceInfo = await dataSourceValidator.fetchDataSourceInfo();
98+
const dataSourceVersion = dataSourceInfo.dataSourceVersion;
99+
const dataSourceEngineType = dataSourceInfo.dataSourceEngineType;
98100
const installedPlugins = Array.from(await dataSourceValidator.fetchInstalledPlugins());
99101

100102
return response.ok({
101103
body: {
102104
dataSourceVersion,
105+
dataSourceEngineType,
103106
installedPlugins,
104107
},
105108
});

src/plugins/data_source/server/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'src/core/server';
1212
import {
1313
DataSourceAttributes,
14+
DataSourceEngineType,
1415
AuthType,
1516
UsernamePasswordTypedContent,
1617
SigV4Content,
@@ -98,3 +99,8 @@ export interface DataSourcePluginStart {
9899
getAuthenticationMethodRegistry: () => IAuthenticationMethodRegistry;
99100
getCustomApiSchemaRegistry: () => CustomApiSchemaRegistry;
100101
}
102+
103+
export interface DataSourceInfo {
104+
dataSourceVersion?: string;
105+
dataSourceEngineType?: DataSourceEngineType;
106+
}

src/plugins/data_source_management/public/components/create_data_source_wizard/create_data_source_wizard.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const CreateDataSourceWizard: React.FunctionComponent<CreateDataSourceWiz
7878
// Fetch data source metadata from added OS/ES domain/cluster
7979
const metadata = await fetchDataSourceMetaData(http, attributes);
8080
attributes.dataSourceVersion = metadata.dataSourceVersion;
81+
attributes.dataSourceEngineType = metadata.dataSourceEngineType;
8182
attributes.installedPlugins = metadata.installedPlugins;
8283
await createSingleDataSource(savedObjects.client, attributes);
8384
// Set the first create data source as default data source.

0 commit comments

Comments
 (0)