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

[Discover] Data selector enhancement #6571

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
953e448
datasource and service refactoring
mengweieric Mar 12, 2024
a21e887
datasource enhancement and refactoring
mengweieric Apr 21, 2024
564c820
datasource selectable consolidation and refactoring
mengweieric Apr 22, 2024
c1feb10
add in memory cache with refresh
mengweieric Apr 26, 2024
46d0b35
move refresh to right side
mengweieric Apr 26, 2024
9005834
renaming
mengweieric Apr 28, 2024
c412a7d
update default datasource tests
mengweieric Apr 28, 2024
5e8448a
added more tests for default datasource
mengweieric Apr 28, 2024
ae2921a
update selector tests
mengweieric Apr 28, 2024
6e14ca8
update changelog
mengweieric Apr 28, 2024
ddbb6f2
fix data source service tests
mengweieric Apr 28, 2024
535d558
add and update tests for datasource service
mengweieric Apr 28, 2024
7de39cf
add more data source service tests
mengweieric Apr 29, 2024
2a9b5d7
fix sidebar tests
mengweieric Apr 29, 2024
aceb01e
Merge branch 'main' into feature/data-selector-enhancement
mengweieric Apr 29, 2024
a41a88c
add to change log yml
mengweieric Apr 29, 2024
ee1aad3
address comments along with more tests
mengweieric Apr 30, 2024
1023d02
Merge branch 'main' into feature/data-selector-enhancement
mengweieric Apr 30, 2024
2e688e2
add test subject
mengweieric Apr 30, 2024
98225e0
reference from correct type path
mengweieric Apr 30, 2024
ce3d405
correct text
mengweieric Apr 30, 2024
b18cd4a
Merge branch 'main' into feature/data-selector-enhancement
mengweieric Apr 30, 2024
6514483
minor change - remove yet used displayOrder
mengweieric Apr 30, 2024
8e7b8e4
remove from changelog as having fragments already
mengweieric Apr 30, 2024
909bb92
use expanded name
mengweieric Apr 30, 2024
c8753d9
fix one test
mengweieric Apr 30, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Extract the button component for datasource picker to avoid duplicate code ([#6559](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6559))
- [Workspace] Add workspaces filter to saved objects page. ([#6458](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6458))
- [Multiple Datasource] Support multi data source in Region map ([#6654](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6654))
- [Discover Data Selector] - Data selector enhancement and refactoring ([#6571](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6571))
mengweieric marked this conversation as resolved.
Show resolved Hide resolved

### 🐛 Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/6571.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- discover data selector enhancement and refactoring ([#6571](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6571))
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions src/plugins/data/public/data_sources/constants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { DataSourceUIGroupType } from './datasource/types';
import { DEFAULT_DATA_SOURCE_DISPLAY_NAME } from './register_default_datasource';

export const defaultDataSourceMetadata = {
Copy link
Member

Choose a reason for hiding this comment

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

qq: did we settle on this code wise being internally referenced as data source?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In last Thursday's meeting @kgcreative mentioned we should for now only aligns on data connector in replace of previous data source selector naming, but not for renaming other existing datasource names through out the code for this. Soon will have a push for renaming stuff only for datasource selector to be data selector.

ui: {
label: DEFAULT_DATA_SOURCE_DISPLAY_NAME,
typeLabel: DEFAULT_DATA_SOURCE_DISPLAY_NAME,
groupType: DataSourceUIGroupType.defaultOpenSearchDataSource,
selector: {
displayDatasetsAsSource: true,
},
},
};

export const s3DataSourceMetadata = {
ui: {
label: 'Amazon S3',
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
typeLabel: 's3glue',
groupType: DataSourceUIGroupType.s3glue,
selector: {
displayDatasetsAsSource: false,
},
},
};
52 changes: 35 additions & 17 deletions src/plugins/data/public/data_sources/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,41 @@
* DataSourceQueryResult: Represents the result from querying the data source.
*/

import { ConnectionStatus } from './types';
import {
DataSourceConnectionStatus,
IDataSetParams,
IDataSourceDataSet,
IDataSourceMetadata,
IDataSourceQueryParams,
IDataSourceQueryResponse,
IDataSourceSettings,
} from './types';

/**
* @experimental this class is experimental and might change in future releases.
*/
export abstract class DataSource<
DataSourceMetaData,
DataSetParams,
SourceDataSet,
DataSourceQueryParams,
DataSourceQueryResult
TMetadata extends IDataSourceMetadata = IDataSourceMetadata,
TDataSetParams extends IDataSetParams = IDataSetParams,
TDataSet extends IDataSourceDataSet = IDataSourceDataSet,
TQueryParams extends IDataSourceQueryParams = IDataSourceQueryParams,
TQueryResult extends IDataSourceQueryResponse = IDataSourceQueryResponse
> {
constructor(
private readonly name: string,
private readonly type: string,
private readonly metadata: DataSourceMetaData
) {}
private readonly id: string;
private readonly name: string;
private readonly type: string;
private readonly metadata: TMetadata;

constructor(settings: IDataSourceSettings<TMetadata>) {
this.id = settings.id;
this.name = settings.name;
this.type = settings.type;
this.metadata = settings.metadata;
}

getId() {
return this.id;
}

getName() {
return this.name;
Expand All @@ -53,27 +71,27 @@ export abstract class DataSource<
* patterns for OpenSearch data source
*
* @experimental This API is experimental and might change in future releases.
* @returns {SourceDataSet} Dataset associated with the data source.
* @returns {Promise<TDataSet>} Dataset associated with the data source.
*/
abstract getDataSet(dataSetParams?: DataSetParams): SourceDataSet;
abstract getDataSet(dataSetParams?: TDataSetParams): Promise<TDataSet>;

/**
* Abstract method to run a query against the data source.
* Implementing classes need to provide the specific implementation.
*
* @experimental This API is experimental and might change in future releases.
* @returns {DataSourceQueryResult} Result from querying the data source.
* @returns {Promise<TQueryResult>} Result from querying the data source.
*/
abstract runQuery(queryParams: DataSourceQueryParams): DataSourceQueryResult;
abstract runQuery(queryParams?: TQueryParams): Promise<TQueryResult>;

/**
* Abstract method to test the connection to the data source.
* Implementing classes should provide the specific logic to determine
* the connection status, typically indicating success or failure.
*
* @experimental This API is experimental and might change in future releases.
* @returns {ConnectionStatus | Promise<void>} Status of the connection test.
* @returns {Promise<DataSourceConnectionStatus | boolean>} Status of the connection test.
* @experimental
*/
abstract testConnection(): ConnectionStatus | Promise<boolean>;
abstract testConnection(): Promise<DataSourceConnectionStatus | boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ class MockDataSource extends DataSource<any, any, any, any, any> {
private readonly indexPatterns;

constructor({
id,
name,
type,
metadata,
indexPatterns,
}: {
id: string;
name: string;
type: string;
metadata: any;
indexPatterns: IndexPatternsService;
}) {
super(name, type, metadata);
super({ id, name, type, metadata });
this.indexPatterns = indexPatterns;
}

Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/public/data_sources/datasource/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* It serves as a registry for different data source types and provides a way to instantiate them.
*/

import { DataSourceType } from '../datasource_services';
import { DataSource } from '../datasource';

type DataSourceClass<
Expand Down Expand Up @@ -66,11 +65,11 @@ export class DataSourceFactory {
*
* @experimental This API is experimental and might change in future releases.
* @param {string} type - The identifier for the data source type.
* @param {any} config - The configuration for the data source instance.
* @param {unknown} config - The configuration for the data source instance.
* @returns {DataSourceType} An instance of the specified data source type.
* @throws {Error} Throws an error if the data source type is not supported.
*/
getDataSourceInstance(type: string, config: any): DataSourceType {
getDataSourceInstance(type: string, config: unknown): DataSource {
const DataSourceClass = this.dataSourceClasses[type];
if (!DataSourceClass) {
throw new Error('Unsupported data source type');
Expand Down
7 changes: 3 additions & 4 deletions src/plugins/data/public/data_sources/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

export { DataSource } from './datasource';
export {
IDataSourceMetaData,
ISourceDataSet,
IDataSourceMetadata,
DataSetWithDataSource,
IDataSetParams,
IDataSourceQueryParams,
IDataSourceQueryResult,
ConnectionStatus,
DataSourceConfig,
DataSourceConnectionStatus,
IndexPatternOption,
} from './types';
export { DataSourceFactory } from './factory';
76 changes: 53 additions & 23 deletions src/plugins/data/public/data_sources/datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,79 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DataSource } from './datasource';

/**
* @experimental These interfaces are experimental and might change in future releases.
*/

import { IndexPatternsService } from '../../index_patterns';
import { DataSourceType } from '../datasource_services';

export interface IndexPatternOption {
title: string;
id: string;
}

export interface IDataSourceMetaData {
export interface IDataSourceGroup {
name: string;
}

export interface IDataSourceGroup {
export interface DataSetWithDataSource<T = []> {
ds: DataSource;
list: T;
}
mengweieric marked this conversation as resolved.
Show resolved Hide resolved

export interface IDataSetParams<T = {}> {
query: T;
}

export interface IDataSourceQueryParams<T = {}> {
query: T;
}

export interface IDataSourceQueryResult<T = {}> {
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
data: T;
}

export interface DataSourceConnectionStatus {
status: string;
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
message: string;
error?: Error;
}

export interface IDataSourceSettings<T extends IDataSourceMetadata = IDataSourceMetadata> {
id: string;
type: string;
name: string;
metadata: T;
}

export interface ISourceDataSet {
ds: DataSourceType;
data_sets: Array<string | IndexPatternOption>;
export interface IDataSourceMetadata {
ui: IDataSourceUISettings;
}

// to-dos: add common interfaces for datasource
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSetParams {}
export interface IDataSourceUISelector {
displayDatasetsAsSource: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSourceQueryParams {}
export interface IDataSourceUISettings {
selector: IDataSourceUISelector;
label: string; // the display name of data source
groupType: DataSourceUIGroupType; // the group to which the data source belongs
typeLabel: string; // the display name of data source type
displayOrder?: number; // the order in which the data source should be displayed in selector
description?: string; // short description of your database
icon?: string; // uri of the icon
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSourceQueryResult {}
export interface IDataSourceDataSet<T = {}> {
dataSets: T;
}

export interface ConnectionStatus {
success: boolean;
info: string;
export interface IDataSourceQueryResponse<T = {}> {
data: T;
}

export interface DataSourceConfig {
name: string;
type: string;
metadata: any;
indexPatterns: IndexPatternsService;
export enum DataSourceUIGroupType {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, do we have a plan on getting away from hardcoding datasource types in this service? These should be generic enough to allow different groups of datasources.

defaultOpenSearchDataSource = 'DEFAULT_INDEX_PATTERNS',
s3glue = 's3glue',
spark = 'spark',
}
Loading
Loading