Skip to content

Commit

Permalink
[discover] update interfaces and move dataset manager (#7745)
Browse files Browse the repository at this point in the history
* Move dataset location

Signed-off-by: Kawika Avilla <[email protected]>

* update interfaces

Signed-off-by: Kawika Avilla <[email protected]>

* Update src/plugins/data/common/datasets/types.ts

Co-authored-by: Ashwin P Chandran <[email protected]>
Signed-off-by: Kawika Avilla <[email protected]>

---------

Signed-off-by: Kawika Avilla <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
  • Loading branch information
2 people authored and abbyhu2000 committed Aug 19, 2024
1 parent 08aefa0 commit 49c3110
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 80 deletions.
133 changes: 106 additions & 27 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,74 @@ export interface DataSourceMeta {
* Represents the hierarchical structure of data within a data source.
*
* @example
* Example of an OpenSearch cluster with indices
*
* const openSearchCluster: DataStructure = {
* id: "b18e5f58-cf71-11ee-ad92-2468ce360004",
* title: "Production Cluster",
* type: "OPENSEARCH",
* title: "Data Cluster1",
* type: "DATA_SOURCE",
* children: [
* {
* id: "b18e5f58-cf71-11ee-ad92-2468ce360004::logs-2023.05",
* title: "logs-2023.05",
* type: "INDEX",
* parent: { id: "b18e5f58-cf71-11ee-ad92-2468ce360004", title: "Production Cluster", type: "OPENSEARCH" }
* parent: { id: "b18e5f58-cf71-11ee-ad92-2468ce360004", title: "Data Cluster1", type: "DATA_SOURCE" },
* meta: {
* type: 'FEATURE',
* icon: 'indexIcon',
* tooltip: 'Logs from May 2023'
* }
* },
* {
* id: "b18e5f58-cf71-11ee-ad92-2468ce360004::logs-2023.06",
* title: "logs-2023.06",
* type: "INDEX",
* parent: { id: "b18e5f58-cf71-11ee-ad92-2468ce360004", title: "Production Cluster", type: "OPENSEARCH" }
* parent: { id: "b18e5f58-cf71-11ee-ad92-2468ce360004", title: "Data Cluster1", type: "DATA_SOURCE" },
* meta: {
* type: 'FEATURE',
* icon: 'indexIcon',
* tooltip: 'Logs from June 2023'
* }
* }
* ]
* ],
* meta: {
* type: 'FEATURE',
* icon: 'clusterIcon',
* tooltip: 'OpenSearch Cluster'
* }
* };
*
* Example of an S3 data source with a database and tables:
* Example of an S3 data source with a connection, database, and tables:
*
* const s3DataSource: DataStructure = {
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003",
* title: "mys3",
* type: "S3,
* title: "Flint MDS cluster name",
* type: "DATA_SOURCE",
* children: [
* {
* id: "mys3.defaultDb",
* title: "defaultDb",
* type: "DATABASE",
* parent: { id: "myS3", title: "My S3 Bucket", type: "S3" },
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3",
* title: "mys3",
* type: "CONNECTION",
* parent: { id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003", title: "Flint MDS cluster name", type: "DATA_SOURCE" },
* children: [
* {
* id: "mys3.defaultDb.table1",
* title: "table1",
* type: "TABLE",
* parent: { id: "sales-db", title: "Sales Database", type: "DATABASE" }
* },
* {
* id: "mys3.defaultDb.table2",
* title: "table2",
* type: "TABLE",
* parent: { id: "sales-db", title: "Sales Database", type: "DATABASE" }
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3.defaultDb",
* title: "defaultDb",
* type: "DATABASE",
* parent: { id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3", title: "mys3", type: "CONNECTION" },
* children: [
* {
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3.defaultDb.table1",
* title: "table1",
* type: "TABLE",
* parent: { id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3.defaultDb", title: "defaultDb", type: "DATABASE" }
* },
* {
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3.defaultDb.table2",
* title: "table2",
* type: "TABLE",
* parent: { id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003::mys3.defaultDb", title: "defaultDb", type: "DATABASE" }
* }
* ]
* }
* ]
* }
Expand All @@ -88,12 +110,69 @@ export interface DataStructure {
id: string;
/** Human-readable name of the data structure */
title: string;
/** The type of the data structure, registered by other classes */
/** The type of the data structure */
type: string;
/** Optional reference to the parent data structure */
parent?: DataStructure;
/** Optional array of child data structures */
children?: DataStructure[];
/** Optional metadata for the data structure */
meta?: DataStructureMeta;
}

/**
* Metadata for a data structure, used for additional properties like icons or tooltips.
*/
export interface DataStructureMeta {
type: DATA_STRUCTURE_META_TYPES;
}

/**
* DataStructureMeta types
*/
export enum DATA_STRUCTURE_META_TYPES {
FEATURE = 'FEATURE',
CUSTOM = 'CUSTOM',
}

/**
* Metadata for a data structure, used for additional properties like icons or tooltips.
*/
export interface DataStructureFeatureMeta extends DataStructureMeta {
type: DATA_STRUCTURE_META_TYPES.FEATURE;
icon: string;
tooltip: string;
}

/**
* Metadata for a data structure with CUSTOM type, allowing any additional fields.
*/
export interface DataStructureCustomMeta extends DataStructureMeta {
type: DATA_STRUCTURE_META_TYPES.CUSTOM;
[key: string]: any;
}

/**
* Represents a cached version of DataStructure with string references instead of object references.
*
* @example
*
* const cachedOpenSearchCluster: CachedDataStructure = {
* id: "b18e5f58-cf71-11ee-ad92-2468ce360004",
* title: "Data Cluster1",
* type: "DATA_SOURCE",
* parent: "",
* children: [
* "b18e5f58-cf71-11ee-ad92-2468ce360004::logs-2023.05",
* "b18e5f58-cf71-11ee-ad92-2468ce360004::logs-2023.06"
* ]
* };
*/
export interface CachedDataStructure extends Omit<DataStructure, 'parent' | 'children' | 'meta'> {
/** ID of the parent data structure */
parent: string;
/** Array of child data structure IDs */
children: string[];
}

/**
Expand All @@ -103,7 +182,7 @@ export interface DataStructure {
* have similar titles and the data plugin assumes unique data set IDs.
*
* @example
* Example of a Dataset for an OpenSearch index
* Example of a Dataset for an OpenSearch index pattern
* const logsIndexDataset: Dataset = {
* id: "2e1b1b80-9c4d-11ee-8c90-0242ac120001",
* title: "logs-*",
Expand All @@ -112,7 +191,7 @@ export interface DataStructure {
* dataSource: {
* id: "main-cluster",
* title: "Main OpenSearch Cluster",
* type: "DEFAULT"
* type: "OPENSEARCH"
* },
* };
*
Expand All @@ -126,7 +205,7 @@ export interface DataStructure {
* dataSource: {
* id: "7d5c3e1c-ae5f-11ee-9c91-1357bd240003",
* title: "My S3 Connect",
* type: "EXAMPLE_DATASOURCE"
* type: "S3_GLUE"
* },
* };
*/
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ export {
QueryState,
getDefaultQuery,
FilterManager,
DataSetManager,
DataSetContract,
SavedQuery,
SavedQueryService,
SavedQueryTimeFilter,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export * from './lib';

export * from './query_service';
export * from './filter_manager';
export * from './dataset_manager';
export * from './query_string/dataset_manager';
export * from './timefilter';
export * from './saved_query';
export * from './persisted_log';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { QueryService, QuerySetup, QueryStart } from '.';
import { timefilterServiceMock } from './timefilter/timefilter_service.mock';
import { createFilterManagerMock } from './filter_manager/filter_manager.mock';
import { queryStringManagerMock } from './query_string/query_string_manager.mock';
import { dataSetManagerMock } from './dataset_manager/dataset_manager.mock';
import { dataSetManagerMock } from './query_string/dataset_manager/dataset_manager.mock';

type QueryServiceClientContract = PublicMethodsOf<QueryService>;

Expand Down
10 changes: 4 additions & 6 deletions src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class QueryService {
filterManager!: FilterManager;
timefilter!: TimefilterSetup;
queryStringManager!: QueryStringContract;
dataSetManager!: DataSetContract;

state$!: ReturnType<typeof createQueryStateObservable>;

Expand All @@ -81,20 +80,19 @@ export class QueryService {
});

this.queryStringManager = new QueryStringManager(storage, uiSettings);
this.dataSetManager = new DataSetManager(uiSettings);

this.state$ = createQueryStateObservable({
filterManager: this.filterManager,
timefilter: this.timefilter,
queryString: this.queryStringManager,
dataSetManager: this.dataSetManager,
datasetManager: this.queryStringManager.getDatasetManager(),
}).pipe(share());

return {
filterManager: this.filterManager,
timefilter: this.timefilter,
queryString: this.queryStringManager,
dataSetManager: this.dataSetManager,
datasetManager: this.queryStringManager.getDatasetManager(),
state$: this.state$,
};
}
Expand All @@ -105,15 +103,15 @@ export class QueryService {
uiSettings,
indexPatterns,
}: QueryServiceStartDependencies) {
this.dataSetManager.init(indexPatterns);
this.queryStringManager.getDatasetManager().init(indexPatterns);
return {
addToQueryLog: createAddToQueryLog({
storage,
uiSettings,
}),
filterManager: this.filterManager,
queryString: this.queryStringManager,
dataSetManager: this.dataSetManager,
dataSetManager: this.queryStringManager.getDatasetManager(),
savedQueries: createSavedQueryService(savedObjectsClient),
state$: this.state$,
timefilter: this.timefilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DataSetContract } from '.';
import { DatasetContract } from '.';

const createSetupContractMock = () => {
const dataSetManagerMock: jest.Mocked<DataSetContract> = {
const datasetManagerMock: jest.Mocked<DatasetContract> = {
init: jest.fn(),
getDataSet: jest.fn(),
setDataSet: jest.fn(),
getDataset: jest.fn(),
setDataset: jest.fn(),
getUpdates$: jest.fn(),
getDefaultDataSet: jest.fn(),
fetchDefaultDataSet: jest.fn(),
getDefaultDataset: jest.fn(),
fetchDefaultDataset: jest.fn(),
initWithIndexPattern: jest.fn(),
};
return dataSetManagerMock;
return datasetManagerMock;
};

export const dataSetManagerMock = {
export const datasetManagerMock = {
createSetupContract: createSetupContractMock,
createStartContract: createSetupContractMock,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DataSetManager } from './dataset_manager';
import { coreMock } from '../../../../../core/public/mocks';
import { Dataset } from '../../../common';
import { DatasetManager } from './dataset_manager';
import { coreMock } from '../../../../../../core/public/mocks';
import { Dataset } from '../../../../common';

describe('DatasetManager', () => {
let service: DataSetManager;
let service: DatasetManager;

beforeEach(() => {
const uiSettingsMock = coreMock.createSetup().uiSettings;
uiSettingsMock.get.mockReturnValue(true);
service = new DataSetManager(uiSettingsMock);
service = new DatasetManager(uiSettingsMock);
});

test('getUpdates$ is a cold emits only after dataset changes', () => {
Expand All @@ -25,16 +25,16 @@ describe('DatasetManager', () => {
expect(emittedValues).toHaveLength(0);
expect(emittedValues[0]).toEqual(undefined);

const newDataSet: Dataset = {
const newDataset: Dataset = {
id: 'test_dataset',
title: 'Test Dataset',
type: 'INDEX_PATTERN',
};
service.setDataSet(newDataSet);
service.setDataset(newDataset);
expect(emittedValues).toHaveLength(1);
expect(emittedValues[0]).toEqual(newDataSet);
expect(emittedValues[0]).toEqual(newDataset);

service.setDataSet({ ...newDataSet });
service.setDataset({ ...newDataset });
expect(emittedValues).toHaveLength(2);
});
});
Loading

0 comments on commit 49c3110

Please sign in to comment.