From b337bea2d13cc6c8330ba6f0326c51b53baad7f3 Mon Sep 17 00:00:00 2001 From: Kristen Tian <105667444+kristenTian@users.noreply.github.com> Date: Tue, 20 Jun 2023 16:37:43 -0700 Subject: [PATCH 1/4] Enable data client with sample data server side (#4268) * Enable data client with sample data server side * Add dataSourceId into savedObject Signed-off-by: Kristen Tian * Functional list, install uninstall Signed-off-by: Kristen Tian * add change log Signed-off-by: Kristen Tian * address comments Signed-off-by: Kristen Tian * add ut Signed-off-by: Kristen Tian --------- Signed-off-by: Kristen Tian --- .lycheeexclude | 1 + CHANGELOG.md | 1 + .../server/client/configure_client.ts | 2 +- .../server/legacy/configure_legacy_client.ts | 2 +- src/plugins/home/opensearch_dashboards.json | 2 +- .../public/application/sample_data_client.js | 25 ++- .../sample_data/data_sets/ecommerce/index.ts | 11 +- .../sample_data/data_sets/flights/index.ts | 11 +- .../sample_data/data_sets/logs/index.ts | 11 +- .../services/sample_data/data_sets/util.ts | 84 +++++++++ .../lib/sample_dataset_registry_types.ts | 6 +- .../sample_data/routes/install.test.ts | 160 ++++++++++++++++++ .../services/sample_data/routes/install.ts | 60 +++++-- .../services/sample_data/routes/list.test.ts | 122 +++++++++++++ .../services/sample_data/routes/list.ts | 116 +++++++------ .../sample_data/routes/uninstall.test.ts | 101 +++++++++++ .../services/sample_data/routes/uninstall.ts | 31 ++-- .../sample_data/sample_data_registry.ts | 8 +- 18 files changed, 648 insertions(+), 106 deletions(-) create mode 100644 src/plugins/home/server/services/sample_data/data_sets/util.ts create mode 100644 src/plugins/home/server/services/sample_data/routes/install.test.ts create mode 100644 src/plugins/home/server/services/sample_data/routes/list.test.ts create mode 100644 src/plugins/home/server/services/sample_data/routes/uninstall.test.ts diff --git a/.lycheeexclude b/.lycheeexclude index 35ae861e8f91..bb378e308868 100644 --- a/.lycheeexclude +++ b/.lycheeexclude @@ -121,3 +121,4 @@ https://yarnpkg.com/latest.msi https://forum.opensearch.org/ https://facebook.github.io/jest/ https://facebook.github.io/jest/docs/cli.html +http://helpmenow.com/problem2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5afb7ee4b8a8..081b56f4f6c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Replace re2 with RegExp in timeline and add unit tests ([#3908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3908)) - Add category option within groups for context menus ([#4144](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4144)) - [Saved Object Service] Add Repository Factory Provider ([#4149](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4149)) +- [Multiple DataSource] Backend support for adding sample data ([#4268](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4268)) ### 🐛 Bug Fixes diff --git a/src/plugins/data_source/server/client/configure_client.ts b/src/plugins/data_source/server/client/configure_client.ts index 77a0e067bbc0..acbdfddb3fc4 100644 --- a/src/plugins/data_source/server/client/configure_client.ts +++ b/src/plugins/data_source/server/client/configure_client.ts @@ -74,7 +74,7 @@ export const configureClient = async ( requireDecryption ); } catch (error: any) { - logger.error( + logger.debug( `Failed to get data source client for dataSourceId: [${dataSourceId}]. ${error}: ${error.stack}` ); // Re-throw as DataSourceError diff --git a/src/plugins/data_source/server/legacy/configure_legacy_client.ts b/src/plugins/data_source/server/legacy/configure_legacy_client.ts index 0d074cf77d4a..8341e844edc8 100644 --- a/src/plugins/data_source/server/legacy/configure_legacy_client.ts +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.ts @@ -60,7 +60,7 @@ export const configureLegacyClient = async ( dataSourceId ); } catch (error: any) { - logger.error( + logger.debug( `Failed to get data source client for dataSourceId: [${dataSourceId}]. ${error}: ${error.stack}` ); // Re-throw as DataSourceError diff --git a/src/plugins/home/opensearch_dashboards.json b/src/plugins/home/opensearch_dashboards.json index 3cb42faaeec2..35a81bc7adb9 100644 --- a/src/plugins/home/opensearch_dashboards.json +++ b/src/plugins/home/opensearch_dashboards.json @@ -4,7 +4,7 @@ "server": true, "ui": true, "requiredPlugins": ["data", "urlForwarding"], - "optionalPlugins": ["usageCollection", "telemetry"], + "optionalPlugins": ["usageCollection", "telemetry", "dataSource"], "requiredBundles": [ "opensearchDashboardsReact" ] diff --git a/src/plugins/home/public/application/sample_data_client.js b/src/plugins/home/public/application/sample_data_client.js index bf30f516dfc7..045736c428f6 100644 --- a/src/plugins/home/public/application/sample_data_client.js +++ b/src/plugins/home/public/application/sample_data_client.js @@ -36,12 +36,14 @@ function clearIndexPatternsCache() { getServices().indexPatternService.clearCache(); } -export async function listSampleDataSets() { - return await getServices().http.get(sampleDataUrl); +export async function listSampleDataSets(dataSourceId) { + const query = buildQuery(dataSourceId); + return await getServices().http.get(sampleDataUrl, { query }); } -export async function installSampleDataSet(id, sampleDataDefaultIndex) { - await getServices().http.post(`${sampleDataUrl}/${id}`); +export async function installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId) { + const query = buildQuery(dataSourceId); + await getServices().http.post(`${sampleDataUrl}/${id}`, { query }); if (getServices().uiSettings.isDefault('defaultIndex')) { getServices().uiSettings.set('defaultIndex', sampleDataDefaultIndex); @@ -50,8 +52,9 @@ export async function installSampleDataSet(id, sampleDataDefaultIndex) { clearIndexPatternsCache(); } -export async function uninstallSampleDataSet(id, sampleDataDefaultIndex) { - await getServices().http.delete(`${sampleDataUrl}/${id}`); +export async function uninstallSampleDataSet(id, sampleDataDefaultIndex, dataSourceId) { + const query = buildQuery(dataSourceId); + await getServices().http.delete(`${sampleDataUrl}/${id}`, { query }); const uiSettings = getServices().uiSettings; @@ -64,3 +67,13 @@ export async function uninstallSampleDataSet(id, sampleDataDefaultIndex) { clearIndexPatternsCache(); } + +function buildQuery(dataSourceId) { + const query = {}; + + if (dataSourceId) { + query.data_source_id = dataSourceId; + } + + return query; +} diff --git a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts index 43cf0925a8b4..0321c428cf68 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/index.ts @@ -33,6 +33,7 @@ import { i18n } from '@osd/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; +import { getSavedObjectsWithDataSource, appendDataSourceId } from '../util'; const ecommerceName = i18n.translate('home.sampleData.ecommerceSpecTitle', { defaultMessage: 'Sample eCommerce orders', @@ -42,6 +43,9 @@ const ecommerceDescription = i18n.translate('home.sampleData.ecommerceSpecDescri }); const initialAppLinks = [] as AppLinkSchema[]; +const DEFAULT_INDEX = 'ff959d40-b880-11e8-a6d9-e546fe2bba5f'; +const DASHBOARD_ID = '722b74f0-b882-11e8-a6d9-e546fe2bba5f'; + export const ecommerceSpecProvider = function (): SampleDatasetSchema { return { id: 'ecommerce', @@ -49,10 +53,11 @@ export const ecommerceSpecProvider = function (): SampleDatasetSchema { description: ecommerceDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/ecommerce/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/ecommerce/dashboard_dark.png', - overviewDashboard: '722b74f0-b882-11e8-a6d9-e546fe2bba5f', + overviewDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', - savedObjects: getSavedObjects(), + defaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { id: 'ecommerce', diff --git a/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts index e90cdaea3b8a..038744419f3e 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/flights/index.ts @@ -33,6 +33,7 @@ import { i18n } from '@osd/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; +import { getSavedObjectsWithDataSource, appendDataSourceId } from '../util'; const flightsName = i18n.translate('home.sampleData.flightsSpecTitle', { defaultMessage: 'Sample flight data', @@ -42,6 +43,9 @@ const flightsDescription = i18n.translate('home.sampleData.flightsSpecDescriptio }); const initialAppLinks = [] as AppLinkSchema[]; +const DEFAULT_INDEX = 'd3d7af60-4c81-11e8-b3d7-01146121b73d'; +const DASHBOARD_ID = '7adfa750-4c81-11e8-b3d7-01146121b73d'; + export const flightsSpecProvider = function (): SampleDatasetSchema { return { id: 'flights', @@ -49,10 +53,11 @@ export const flightsSpecProvider = function (): SampleDatasetSchema { description: flightsDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/flights/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/flights/dashboard_dark.png', - overviewDashboard: '7adfa750-4c81-11e8-b3d7-01146121b73d', + overviewDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', - savedObjects: getSavedObjects(), + defaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { id: 'flights', diff --git a/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts index 1438de8ad64f..e4afabcdd212 100644 --- a/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts +++ b/src/plugins/home/server/services/sample_data/data_sets/logs/index.ts @@ -33,6 +33,7 @@ import { i18n } from '@osd/i18n'; import { getSavedObjects } from './saved_objects'; import { fieldMappings } from './field_mappings'; import { SampleDatasetSchema, AppLinkSchema } from '../../lib/sample_dataset_registry_types'; +import { appendDataSourceId, getSavedObjectsWithDataSource } from '../util'; const logsName = i18n.translate('home.sampleData.logsSpecTitle', { defaultMessage: 'Sample web logs', @@ -42,6 +43,9 @@ const logsDescription = i18n.translate('home.sampleData.logsSpecDescription', { }); const initialAppLinks = [] as AppLinkSchema[]; +const DEFAULT_INDEX = '90943e30-9a47-11e8-b64d-95841ca0b247'; +const DASHBOARD_ID = 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b'; + export const logsSpecProvider = function (): SampleDatasetSchema { return { id: 'logs', @@ -49,10 +53,11 @@ export const logsSpecProvider = function (): SampleDatasetSchema { description: logsDescription, previewImagePath: '/plugins/home/assets/sample_data_resources/logs/dashboard.png', darkPreviewImagePath: '/plugins/home/assets/sample_data_resources/logs/dashboard_dark.png', - overviewDashboard: 'edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b', + overviewDashboard: appendDataSourceId(DASHBOARD_ID), appLinks: initialAppLinks, - defaultIndex: '90943e30-9a47-11e8-b64d-95841ca0b247', - savedObjects: getSavedObjects(), + defaultIndex: appendDataSourceId(DEFAULT_INDEX), + savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => + getSavedObjectsWithDataSource(getSavedObjects(), dataSourceId, dataSourceTitle), dataIndices: [ { id: 'logs', diff --git a/src/plugins/home/server/services/sample_data/data_sets/util.ts b/src/plugins/home/server/services/sample_data/data_sets/util.ts new file mode 100644 index 000000000000..46022f1c22d3 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/data_sets/util.ts @@ -0,0 +1,84 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { SavedObject } from 'opensearch-dashboards/server'; + +export const appendDataSourceId = (id: string) => { + return (dataSourceId?: string) => (dataSourceId ? `${dataSourceId}_` + id : id); +}; + +export const getSavedObjectsWithDataSource = ( + saveObjectList: SavedObject[], + dataSourceId?: string, + dataSourceTitle?: string +): SavedObject[] => { + if (dataSourceId) { + return saveObjectList.map((saveObject) => { + saveObject.id = `${dataSourceId}_` + saveObject.id; + // update reference + if (saveObject.type === 'dashboard') { + saveObject.references.map((reference) => { + if (reference.id) { + reference.id = `${dataSourceId}_` + reference.id; + } + }); + } + + // update reference + if (saveObject.type === 'visualization' || saveObject.type === 'search') { + const searchSourceString = saveObject.attributes?.kibanaSavedObjectMeta?.searchSourceJSON; + const visStateString = saveObject.attributes?.visState; + + if (searchSourceString) { + const searchSource = JSON.parse(searchSourceString); + if (searchSource.index) { + searchSource.index = `${dataSourceId}_` + searchSource.index; + saveObject.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify( + searchSource + ); + } + } + + if (visStateString) { + const visState = JSON.parse(visStateString); + const controlList = visState.params?.controls; + if (controlList) { + controlList.map((control) => { + if (control.indexPattern) { + control.indexPattern = `${dataSourceId}_` + control.indexPattern; + } + }); + } + saveObject.attributes.visState = JSON.stringify(visState); + } + } + + // update reference + if (saveObject.type === 'index-pattern') { + saveObject.references = [ + { + id: `${dataSourceId}`, + type: 'data-source', + name: 'dataSource', + }, + ]; + } + + if (dataSourceTitle) { + if ( + saveObject.type === 'dashboard' || + saveObject.type === 'visualization' || + saveObject.type === 'search' + ) { + saveObject.attributes.title = saveObject.attributes.title + `_${dataSourceTitle}`; + } + } + + return saveObject; + }); + } + + return saveObjectList; +}; diff --git a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts index 86ac5bcc5779..76632ee4489d 100644 --- a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts +++ b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts @@ -87,15 +87,15 @@ export interface SampleDatasetSchema { darkPreviewImagePath: string; // saved object id of main dashboard for sample data set - overviewDashboard: string; + overviewDashboard: (dataSourceId?: string) => string; appLinks: AppLinkSchema[]; // saved object id of default index-pattern for sample data set - defaultIndex: string; + defaultIndex: (dataSourceId?: string) => string; // OpenSearch Dashboards saved objects (index patter, visualizations, dashboard, ...) // Should provide a nice demo of OpenSearch Dashboards's functionality with the sample data set - savedObjects: Array>; + savedObjects: (dataSourceId?: string, dataSourceTitle?: string) => Array>; dataIndices: DataIndexSchema[]; status?: string | undefined; statusMsg?: unknown; diff --git a/src/plugins/home/server/services/sample_data/routes/install.test.ts b/src/plugins/home/server/services/sample_data/routes/install.test.ts new file mode 100644 index 000000000000..ad7b421c23d5 --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/install.test.ts @@ -0,0 +1,160 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { CoreSetup, RequestHandlerContext } from 'src/core/server'; +import { coreMock, httpServerMock } from '../../../../../../core/server/mocks'; +import { flightsSpecProvider } from '../data_sets'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; +import { createInstallRoute } from './install'; + +const flightsSampleDataset = flightsSpecProvider(); + +const sampleDatasets: SampleDatasetSchema[] = [flightsSampleDataset]; + +describe('sample data install route', () => { + let mockCoreSetup: MockedKeys; + let mockLogger; + let mockUsageTracker; + + beforeEach(() => { + mockCoreSetup = coreMock.createSetup(); + mockLogger = { + warn: jest.fn(), + }; + + mockUsageTracker = { + addInstall: jest.fn(), + addUninstall: jest.fn(), + }; + }); + + it('handler calls expected api with the given request', async () => { + const mockClient = jest.fn().mockResolvedValue(true); + + const mockSOClientGetResponse = { + saved_objects: [ + { + type: 'dashboard', + id: '12345', + namespaces: ['default'], + attributes: { title: 'dashboard' }, + }, + ], + }; + const mockSOClient = { bulkCreate: jest.fn().mockResolvedValue(mockSOClientGetResponse) }; + + const mockContext = { + core: { + opensearch: { + legacy: { + client: { callAsCurrentUser: mockClient }, + }, + }, + savedObjects: { client: mockSOClient }, + }, + }; + const mockBody = { id: 'flights' }; + const mockQuery = {}; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + params: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createInstallRoute( + mockCoreSetup.http.createRouter(), + sampleDatasets, + mockLogger, + mockUsageTracker + ); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.post.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient.mock.calls[1][1].body.settings).toMatchObject({ + index: { number_of_shards: 1, auto_expand_replicas: '0-1' }, + }); + + // expect(mockClient).toBeCalledTimes(2); + expect(mockResponse.ok).toBeCalled(); + expect(mockResponse.ok.mock.calls[0][0]).toMatchObject({ + body: { + opensearchIndicesCreated: { opensearch_dashboards_sample_data_flights: 13059 }, + opensearchDashboardsSavedObjectsLoaded: 20, + }, + }); + }); + + it('handler calls expected api with the given request with data source', async () => { + const mockDataSourceId = 'dataSource'; + + const mockClient = jest.fn().mockResolvedValue(true); + + const mockSOClientGetResponse = { + saved_objects: [ + { + type: 'dashboard', + id: '12345', + namespaces: ['default'], + attributes: { title: 'dashboard' }, + }, + ], + }; + const mockSOClient = { + bulkCreate: jest.fn().mockResolvedValue(mockSOClientGetResponse), + get: jest.fn().mockResolvedValue(mockSOClientGetResponse), + }; + + const mockContext = { + dataSource: { + opensearch: { + legacy: { + getClient: (id) => { + return { + callAPI: mockClient, + }; + }, + }, + }, + }, + core: { + savedObjects: { client: mockSOClient }, + }, + }; + const mockBody = { id: 'flights' }; + const mockQuery = { data_source_id: mockDataSourceId }; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + params: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createInstallRoute( + mockCoreSetup.http.createRouter(), + sampleDatasets, + mockLogger, + mockUsageTracker + ); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.post.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient.mock.calls[1][1].body.settings).toMatchObject({ + index: { number_of_shards: 1 }, + }); + + expect(mockResponse.ok).toBeCalled(); + expect(mockResponse.ok.mock.calls[0][0]).toMatchObject({ + body: { + opensearchIndicesCreated: { opensearch_dashboards_sample_data_flights: 13059 }, + opensearchDashboardsSavedObjectsLoaded: 20, + }, + }); + }); +}); diff --git a/src/plugins/home/server/services/sample_data/routes/install.ts b/src/plugins/home/server/services/sample_data/routes/install.ts index eec5f0d5bc86..3a321c3bdf0a 100644 --- a/src/plugins/home/server/services/sample_data/routes/install.ts +++ b/src/plugins/home/server/services/sample_data/routes/install.ts @@ -29,7 +29,7 @@ */ import { schema } from '@osd/config-schema'; -import { IRouter, Logger, RequestHandlerContext } from 'src/core/server'; +import { IRouter, LegacyCallAPIOptions, Logger } from 'src/core/server'; import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; import { createIndexName } from '../lib/create_index_name'; import { @@ -44,7 +44,11 @@ const insertDataIntoIndex = ( dataIndexConfig: any, index: string, nowReference: string, - context: RequestHandlerContext, + caller: ( + endpoint: string, + clientParams?: Record, + options?: LegacyCallAPIOptions + ) => Promise, logger: Logger ) => { function updateTimestamps(doc: any) { @@ -73,7 +77,8 @@ const insertDataIntoIndex = ( bulk.push(insertCmd); bulk.push(updateTimestamps(doc)); }); - const resp = await context.core.opensearch.legacy.client.callAsCurrentUser('bulk', { + + const resp = await caller('bulk', { body: bulk, }); if (resp.errors) { @@ -105,11 +110,16 @@ export function createInstallRoute( validate: { params: schema.object({ id: schema.string() }), // TODO validate now as date - query: schema.object({ now: schema.maybe(schema.string()) }), + query: schema.object({ + now: schema.maybe(schema.string()), + data_source_id: schema.maybe(schema.string()), + }), }, }, async (context, req, res) => { const { params, query } = req; + const dataSourceId = query.data_source_id; + const sampleDataset = sampleDatasets.find(({ id }) => id === params.id); if (!sampleDataset) { return res.notFound(); @@ -118,13 +128,36 @@ export function createInstallRoute( const now = query.now ? new Date(query.now) : new Date(); const nowReference = dateToIso8601IgnoringTime(now); const counts = {}; + const caller = dataSourceId + ? context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI + : context.core.opensearch.legacy.client.callAsCurrentUser; + + let dataSourceTitle; + try { + if (dataSourceId) { + const dataSource = await context.core.savedObjects.client + .get('data-source', dataSourceId) + .then((response) => { + const attributes: any = response?.attributes || {}; + return { + id: response.id, + title: attributes.title, + }; + }); + + dataSourceTitle = dataSource.title; + } + } catch (err) { + return res.internalError({ body: err }); + } + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { const dataIndexConfig = sampleDataset.dataIndices[i]; const index = createIndexName(sampleDataset.id, dataIndexConfig.id); // clean up any old installation of dataset try { - await context.core.opensearch.legacy.client.callAsCurrentUser('indices.delete', { + await caller('indices.delete', { index, }); } catch (err) { @@ -135,14 +168,13 @@ export function createInstallRoute( const createIndexParams = { index, body: { - settings: { index: { number_of_shards: 1, auto_expand_replicas: '0-1' } }, + settings: dataSourceId + ? { index: { number_of_shards: 1 } } + : { index: { number_of_shards: 1, auto_expand_replicas: '0-1' } }, mappings: { properties: dataIndexConfig.fields }, }, }; - await context.core.opensearch.legacy.client.callAsCurrentUser( - 'indices.create', - createIndexParams - ); + await caller('indices.create', createIndexParams); } catch (err) { const errMsg = `Unable to create sample data index "${index}", error: ${err.message}`; logger.warn(errMsg); @@ -154,7 +186,7 @@ export function createInstallRoute( dataIndexConfig, index, nowReference, - context, + caller, logger ); (counts as any)[index] = count; @@ -166,9 +198,11 @@ export function createInstallRoute( } let createResults; + const savedObjectsList = sampleDataset.savedObjects(dataSourceId, dataSourceTitle); + try { createResults = await context.core.savedObjects.client.bulkCreate( - sampleDataset.savedObjects.map(({ version, ...savedObject }) => savedObject), + savedObjectsList.map(({ version, ...savedObject }) => savedObject), { overwrite: true } ); } catch (err) { @@ -192,7 +226,7 @@ export function createInstallRoute( return res.ok({ body: { opensearchIndicesCreated: counts, - opensearchDashboardsSavedObjectsLoaded: sampleDataset.savedObjects.length, + opensearchDashboardsSavedObjectsLoaded: savedObjectsList.length, }, }); } diff --git a/src/plugins/home/server/services/sample_data/routes/list.test.ts b/src/plugins/home/server/services/sample_data/routes/list.test.ts new file mode 100644 index 000000000000..70201fafd06b --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/list.test.ts @@ -0,0 +1,122 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { CoreSetup, RequestHandlerContext } from 'src/core/server'; +import { coreMock, httpServerMock } from '../../../../../../core/server/mocks'; +import { createListRoute } from './list'; +import { flightsSpecProvider } from '../data_sets'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; + +const flightsSampleDataset = flightsSpecProvider(); + +const sampleDatasets: SampleDatasetSchema[] = [flightsSampleDataset]; + +describe('sample data list route', () => { + let mockCoreSetup: MockedKeys; + + beforeEach(() => { + mockCoreSetup = coreMock.createSetup(); + }); + + it('handler calls expected api with the given request', async () => { + const mockClient = jest.fn().mockResolvedValueOnce(true).mockResolvedValueOnce({ count: 1 }); + + const mockSOClientGetResponse = { + saved_objects: [ + { + type: 'dashboard', + id: '7adfa750-4c81-11e8-b3d7-01146121b73d', + namespaces: ['default'], + attributes: { title: 'dashboard' }, + }, + ], + }; + const mockSOClient = { get: jest.fn().mockResolvedValue(mockSOClientGetResponse) }; + + const mockContext = { + core: { + opensearch: { + legacy: { + client: { callAsCurrentUser: mockClient }, + }, + }, + savedObjects: { client: mockSOClient }, + }, + }; + const mockBody = {}; + const mockQuery = {}; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + body: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createListRoute(mockCoreSetup.http.createRouter(), sampleDatasets); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.get.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient).toBeCalledTimes(2); + expect(mockResponse.ok).toBeCalled(); + expect(mockSOClient.get.mock.calls[0][1]).toMatch('7adfa750-4c81-11e8-b3d7-01146121b73d'); + }); + + it('handler calls expected api with the given request with data source', async () => { + const mockDataSourceId = 'dataSource'; + const mockClient = jest.fn().mockResolvedValueOnce(true).mockResolvedValueOnce({ count: 1 }); + + const mockSOClientGetResponse = { + saved_objects: [ + { + type: 'dashboard', + id: `${mockDataSourceId}_7adfa750-4c81-11e8-b3d7-01146121b73d`, + namespaces: ['default'], + attributes: { title: 'dashboard' }, + }, + ], + }; + const mockSOClient = { get: jest.fn().mockResolvedValue(mockSOClientGetResponse) }; + + const mockContext = { + dataSource: { + opensearch: { + legacy: { + getClient: (id) => { + return { + callAPI: mockClient, + }; + }, + }, + }, + }, + core: { + savedObjects: { client: mockSOClient }, + }, + }; + + const mockBody = {}; + const mockQuery = { data_source_id: mockDataSourceId }; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + body: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createListRoute(mockCoreSetup.http.createRouter(), sampleDatasets); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.get.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient).toBeCalledTimes(2); + expect(mockResponse.ok).toBeCalled(); + expect(mockSOClient.get.mock.calls[0][1]).toMatch( + `${mockDataSourceId}_7adfa750-4c81-11e8-b3d7-01146121b73d` + ); + }); +}); diff --git a/src/plugins/home/server/services/sample_data/routes/list.ts b/src/plugins/home/server/services/sample_data/routes/list.ts index a0665132dd10..bc6fac2b76f3 100644 --- a/src/plugins/home/server/services/sample_data/routes/list.ts +++ b/src/plugins/home/server/services/sample_data/routes/list.ts @@ -29,6 +29,7 @@ */ import { IRouter } from 'src/core/server'; +import { schema } from '@osd/config-schema'; import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; import { createIndexName } from '../lib/create_index_name'; @@ -37,66 +38,79 @@ const INSTALLED = 'installed'; const UNKNOWN = 'unknown'; export const createListRoute = (router: IRouter, sampleDatasets: SampleDatasetSchema[]) => { - router.get({ path: '/api/sample_data', validate: false }, async (context, req, res) => { - const registeredSampleDatasets = sampleDatasets.map((sampleDataset) => { - return { - id: sampleDataset.id, - name: sampleDataset.name, - description: sampleDataset.description, - previewImagePath: sampleDataset.previewImagePath, - darkPreviewImagePath: sampleDataset.darkPreviewImagePath, - overviewDashboard: sampleDataset.overviewDashboard, - appLinks: sampleDataset.appLinks, - defaultIndex: sampleDataset.defaultIndex, - dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), - status: sampleDataset.status, - statusMsg: sampleDataset.statusMsg, - }; - }); - const isInstalledPromises = registeredSampleDatasets.map(async (sampleDataset) => { - for (let i = 0; i < sampleDataset.dataIndices.length; i++) { - const dataIndexConfig = sampleDataset.dataIndices[i]; - const index = createIndexName(sampleDataset.id, dataIndexConfig.id); - try { - const indexExists = await context.core.opensearch.legacy.client.callAsCurrentUser( - 'indices.exists', - { index } - ); - if (!indexExists) { - sampleDataset.status = NOT_INSTALLED; + router.get( + { + path: '/api/sample_data', + validate: { + query: schema.object({ data_source_id: schema.maybe(schema.string()) }), + }, + }, + async (context, req, res) => { + const dataSourceId = req.query.data_source_id; + + const registeredSampleDatasets = sampleDatasets.map((sampleDataset) => { + return { + id: sampleDataset.id, + name: sampleDataset.name, + description: sampleDataset.description, + previewImagePath: sampleDataset.previewImagePath, + darkPreviewImagePath: sampleDataset.darkPreviewImagePath, + overviewDashboard: sampleDataset.overviewDashboard(dataSourceId), + appLinks: sampleDataset.appLinks, + defaultIndex: sampleDataset.defaultIndex(dataSourceId), + dataIndices: sampleDataset.dataIndices.map(({ id }) => ({ id })), + status: sampleDataset.status, + statusMsg: sampleDataset.statusMsg, + }; + }); + const isInstalledPromises = registeredSampleDatasets.map(async (sampleDataset) => { + const caller = dataSourceId + ? context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI + : context.core.opensearch.legacy.client.callAsCurrentUser; + + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { + const dataIndexConfig = sampleDataset.dataIndices[i]; + const index = createIndexName(sampleDataset.id, dataIndexConfig.id); + try { + const indexExists = await caller('indices.exists', { index }); + + if (!indexExists) { + sampleDataset.status = NOT_INSTALLED; + return; + } + + const { count } = await caller('count', { + index, + }); + + if (count === 0) { + sampleDataset.status = NOT_INSTALLED; + return; + } + } catch (err) { + sampleDataset.status = UNKNOWN; + sampleDataset.statusMsg = err.message; return; } - - const { count } = await context.core.opensearch.legacy.client.callAsCurrentUser('count', { - index, - }); - if (count === 0) { + } + try { + await context.core.savedObjects.client.get('dashboard', sampleDataset.overviewDashboard); + } catch (err) { + if (context.core.savedObjects.client.errors.isNotFoundError(err)) { sampleDataset.status = NOT_INSTALLED; return; } - } catch (err) { + sampleDataset.status = UNKNOWN; sampleDataset.statusMsg = err.message; return; } - } - try { - await context.core.savedObjects.client.get('dashboard', sampleDataset.overviewDashboard); - } catch (err) { - if (context.core.savedObjects.client.errors.isNotFoundError(err)) { - sampleDataset.status = NOT_INSTALLED; - return; - } - - sampleDataset.status = UNKNOWN; - sampleDataset.statusMsg = err.message; - return; - } - sampleDataset.status = INSTALLED; - }); + sampleDataset.status = INSTALLED; + }); - await Promise.all(isInstalledPromises); - return res.ok({ body: registeredSampleDatasets }); - }); + await Promise.all(isInstalledPromises); + return res.ok({ body: registeredSampleDatasets }); + } + ); }; diff --git a/src/plugins/home/server/services/sample_data/routes/uninstall.test.ts b/src/plugins/home/server/services/sample_data/routes/uninstall.test.ts new file mode 100644 index 000000000000..7d9797d752cb --- /dev/null +++ b/src/plugins/home/server/services/sample_data/routes/uninstall.test.ts @@ -0,0 +1,101 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { CoreSetup, RequestHandlerContext } from 'src/core/server'; +import { coreMock, httpServerMock } from '../../../../../../core/server/mocks'; +import { flightsSpecProvider } from '../data_sets'; +import { SampleDatasetSchema } from '../lib/sample_dataset_registry_types'; +import { createUninstallRoute } from './uninstall'; + +const flightsSampleDataset = flightsSpecProvider(); + +const sampleDatasets: SampleDatasetSchema[] = [flightsSampleDataset]; + +describe('sample data uninstall route', () => { + let mockCoreSetup: MockedKeys; + let mockUsageTracker; + let mockClient; + let mockSOClient; + + beforeEach(() => { + mockCoreSetup = coreMock.createSetup(); + + mockUsageTracker = { + addInstall: jest.fn(), + addUninstall: jest.fn(), + }; + + mockClient = jest.fn(); + mockSOClient = { delete: jest.fn().mockResolvedValue(true) }; + }); + + it('handler calls expected api with the given request', async () => { + const mockContext = { + core: { + opensearch: { + legacy: { + client: { callAsCurrentUser: mockClient }, + }, + }, + savedObjects: { client: mockSOClient }, + }, + }; + const mockBody = { id: 'flights' }; + const mockQuery = {}; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + params: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createUninstallRoute(mockCoreSetup.http.createRouter(), sampleDatasets, mockUsageTracker); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.delete.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient).toBeCalled(); + expect(mockSOClient.delete).toBeCalled(); + }); + + it('handler calls expected api with the given request with data source', async () => { + const mockDataSourceId = 'dataSource'; + + const mockContext = { + dataSource: { + opensearch: { + legacy: { + getClient: (id) => { + return { + callAPI: mockClient, + }; + }, + }, + }, + }, + core: { + savedObjects: { client: mockSOClient }, + }, + }; + const mockBody = { id: 'flights' }; + const mockQuery = { data_source_id: mockDataSourceId }; + const mockRequest = httpServerMock.createOpenSearchDashboardsRequest({ + params: mockBody, + query: mockQuery, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + createUninstallRoute(mockCoreSetup.http.createRouter(), sampleDatasets, mockUsageTracker); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.delete.mock.calls[0][1]; + + await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); + + expect(mockClient).toBeCalled(); + expect(mockSOClient.delete).toBeCalled(); + }); +}); diff --git a/src/plugins/home/server/services/sample_data/routes/uninstall.ts b/src/plugins/home/server/services/sample_data/routes/uninstall.ts index e38a2224aae8..730de6afff30 100644 --- a/src/plugins/home/server/services/sample_data/routes/uninstall.ts +++ b/src/plugins/home/server/services/sample_data/routes/uninstall.ts @@ -45,34 +45,29 @@ export function createUninstallRoute( path: '/api/sample_data/{id}', validate: { params: schema.object({ id: schema.string() }), + query: schema.object({ + data_source_id: schema.maybe(schema.string()), + }), }, }, - async ( - { - core: { - opensearch: { - legacy: { - client: { callAsCurrentUser }, - }, - }, - savedObjects: { client: savedObjectsClient }, - }, - }, - request, - response - ) => { + async (context, request, response) => { const sampleDataset = sampleDatasets.find(({ id }) => id === request.params.id); + const dataSourceId = request.query.data_source_id; if (!sampleDataset) { return response.notFound(); } + const caller = dataSourceId + ? context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI + : context.core.opensearch.legacy.client.callAsCurrentUser; + for (let i = 0; i < sampleDataset.dataIndices.length; i++) { const dataIndexConfig = sampleDataset.dataIndices[i]; const index = createIndexName(sampleDataset.id, dataIndexConfig.id); try { - await callAsCurrentUser('indices.delete', { index }); + await caller('indices.delete', { index }); } catch (err) { return response.customError({ statusCode: err.status, @@ -83,8 +78,10 @@ export function createUninstallRoute( } } - const deletePromises = sampleDataset.savedObjects.map(({ type, id }) => - savedObjectsClient.delete(type, id) + const savedObjectsList = sampleDataset.savedObjects(dataSourceId); + + const deletePromises = savedObjectsList.map(({ type, id }) => + context.core.savedObjects.client.delete(type, id) ); try { diff --git a/src/plugins/home/server/services/sample_data/sample_data_registry.ts b/src/plugins/home/server/services/sample_data/sample_data_registry.ts index d90de532c339..5f298fd86ef3 100644 --- a/src/plugins/home/server/services/sample_data/sample_data_registry.ts +++ b/src/plugins/home/server/services/sample_data/sample_data_registry.ts @@ -84,23 +84,23 @@ export class SampleDataRegistry { } const defaultIndexSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => { return ( - savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex + savedObjectJson.type === 'index-pattern' && savedObjectJson.id === value.defaultIndex() ); }); if (!defaultIndexSavedObjectJson) { throw new Error( - `Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex}" does not exist in savedObjects list.` + `Unable to register sample dataset spec, defaultIndex: "${value.defaultIndex()}" does not exist in savedObjects list.` ); } const dashboardSavedObjectJson = value.savedObjects.find((savedObjectJson: any) => { return ( - savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard + savedObjectJson.type === 'dashboard' && savedObjectJson.id === value.overviewDashboard() ); }); if (!dashboardSavedObjectJson) { throw new Error( - `Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard}" does not exist in savedObject list.` + `Unable to register sample dataset spec, overviewDashboard: "${value.overviewDashboard()}" does not exist in savedObject list.` ); } this.sampleDatasets.push(value); From 84ec854c94cc11a84272f87f8081fc5097720af3 Mon Sep 17 00:00:00 2001 From: Miki Date: Wed, 21 Jun 2023 11:34:39 -0700 Subject: [PATCH 2/4] Upgrade the backport workflow (#4343) * Copy over the labels from the original PR * Label the backport PR with `autocut` * Label a PR that fails to backport Signed-off-by: Miki --- .github/workflows/backport.yml | 4 +++- CHANGELOG.md | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 0ba694cbf213..c8dfef417daa 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -34,8 +34,10 @@ jobs: installation_id: 22958780 - name: Backport - uses: VachaShah/backport@v2.1.0 + uses: VachaShah/backport@v2.2.0 with: github_token: ${{ steps.github_app_token.outputs.token }} head_template: backport/backport-<%= number %>-to-<%= base %> files_to_skip: "CHANGELOG.md" + labels_template: "<%= JSON.stringify([...labels, 'autocut']) %>" + failure_labels: "failed backport" diff --git a/CHANGELOG.md b/CHANGELOG.md index 081b56f4f6c2..dadb1948e340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Re-enable CI workflows for feature branches ([#2908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2908)) - Upgrade yarn version to be compatible with @opensearch-project/opensearch ([#3443](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3443)) - Add an achievement badger to the PR ([#3721](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3721)) +- Upgrade the backport workflow ([#4343](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4343)) ### 📝 Documentation From f298e7e97471253f4e7541c0aa5f855e20570036 Mon Sep 17 00:00:00 2001 From: Miki Date: Wed, 21 Jun 2023 12:39:12 -0700 Subject: [PATCH 3/4] Hide any output from `use_node` checking for Node compatibility (#4237) Signed-off-by: Miki Signed-off-by: Josh Romero Co-authored-by: Josh Romero --- CHANGELOG.md | 1 + scripts/use_node | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dadb1948e340..7502ed1191f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add plugin manifest config to define OpenSearch plugin dependency and verify if it is installed on the cluster ([#3116](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3116)) - Replace re2 with RegExp in timeline and add unit tests ([#3908](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3908)) +- Hide any output from use_node checking for Node compatibility ([#4237](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4237)) - Add category option within groups for context menus ([#4144](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4144)) - [Saved Object Service] Add Repository Factory Provider ([#4149](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4149)) - [Multiple DataSource] Backend support for adding sample data ([#4268](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4268)) diff --git a/scripts/use_node b/scripts/use_node index 48e7e2858200..695abfbcc4f2 100755 --- a/scripts/use_node +++ b/scripts/use_node @@ -64,7 +64,7 @@ else if [ -d "${OSD_HOME}/bin" ]; then NODE_ERROR_SHOW=true # Not all operating systems can run the latest Node.js and the fallback is for them - "${NODE}" -v 2> /dev/null + "${NODE}" -v > /dev/null 2>&1 if [ $? -ne 0 ] && [ -d "${OSD_HOME}/node/fallback" ]; then NODE="$OSD_HOME/node/fallback/bin/node" fi From 333e2b33e421f529a3f2c49c129f58d34640351f Mon Sep 17 00:00:00 2001 From: Manasvini B Suryanarayana Date: Thu, 22 Jun 2023 14:25:35 -0700 Subject: [PATCH 4/4] [Vis Colors] Update default color in TSVB to use `ouiPaletteColorBlind()[0]` (#4363) Signed-off-by: Manasvini B Suryanarayana --- CHANGELOG.md | 1 + src/plugins/vis_type_timeseries/public/metrics_type.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7502ed1191f1..aeb8d55ee5cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Remove unused Sass in `tile_map` plugin ([#4110](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4110)) - [Table Visualization] Remove custom styling for text-align:center in favor of OUI utility class. ([#4164](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4164)) - Replace the use of `bluebird` in `saved_objects` plugin ([#4026](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4026)) +- [Vis Colors] Update default color in TSVB to use `ouiPaletteColorBlind()[0]`([#4363](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4363)) ### 🔩 Tests diff --git a/src/plugins/vis_type_timeseries/public/metrics_type.ts b/src/plugins/vis_type_timeseries/public/metrics_type.ts index 3562684a0b1b..ed3ea21c25e2 100644 --- a/src/plugins/vis_type_timeseries/public/metrics_type.ts +++ b/src/plugins/vis_type_timeseries/public/metrics_type.ts @@ -30,6 +30,7 @@ import { i18n } from '@osd/i18n'; +import { euiPaletteColorBlind } from '@elastic/eui'; // @ts-ignore import { metricsRequestHandler } from './request_handler'; import { EditorController } from './application'; @@ -53,7 +54,7 @@ export const metricsVisDefinition = { series: [ { id: '61ca57f1-469d-11e7-af02-69e470af7417', - color: '#68BC00', + color: euiPaletteColorBlind()[0], split_mode: 'everything', split_color_mode: 'opensearchDashboards', metrics: [