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 23 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 @@ -108,6 +108,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [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))
- Add `rightNavigationButton` component in chrome service for applications to register and add dev tool to top right navigation. ([#6553](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6553))
- [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
46 changes: 46 additions & 0 deletions src/plugins/data/public/data_sources/constants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { DataSourceUIGroupType } from './datasource/types';

export const S3_GLUE_DATA_SOURCE_DISPLAY_NAME = 'Amazon S3';
Copy link
Member

Choose a reason for hiding this comment

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

Are we still hard coding these? Is there a plan to remove them?

export const S3_GLUE_DATA_SOURCE_TYPE = 's3glue';
export const DEFAULT_DATA_SOURCE_TYPE = 'DEFAULT_INDEX_PATTERNS';
export const DEFAULT_DATA_SOURCE_NAME = i18n.translate('data.datasource.type.openSearchDefault', {
defaultMessage: 'OpenSearch Default',
});
export const DEFAULT_DATA_SOURCE_DISPLAY_NAME = i18n.translate(
'data.datasource.type.openSearchDefaultDisplayName',
{
defaultMessage: 'Index patterns',
}
);

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: S3_GLUE_DATA_SOURCE_DISPLAY_NAME,
typeLabel: S3_GLUE_DATA_SOURCE_TYPE,
groupType: DataSourceUIGroupType.s3glue,
selector: {
displayDatasetsAsSource: false,
},
},
};

export const DATA_SELECTOR_REFRESHER_POPOVER_TEXT = 'Refresh data selector';
export const DATA_SELECTOR_DEFAULT_PLACEHOLDER = 'Select a data source';
export const DATA_SELECTOR_S3_DATA_SOURCE_GROUP_HINT_LABEL = ' - Opens in Log Explorer';
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';
109 changes: 86 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,112 @@
* 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 {
name: string;
export interface DataSetWithDataSource<T = unknown> {
ds: DataSource;
list: T[];
}

export interface ISourceDataSet {
ds: DataSourceType;
data_sets: Array<string | IndexPatternOption>;
export interface IDataSetParams<T = {}> {
query: T;
}

// to-dos: add common interfaces for datasource
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSetParams {}
export interface IDataSourceQueryParams<T = {}> {
query: T;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSourceQueryParams {}
export interface IDataSourceQueryResult<T = {}> {
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
data: T;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IDataSourceQueryResult {}
export enum ConnectionStatus {
Connected = 'connected',
Disconnected = 'disconnected',
Error = 'error',
}

export interface ConnectionStatus {
success: boolean;
info: string;
export interface DataSourceConnectionStatus {
status: ConnectionStatus;
message: string;
error?: Error;
}

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

export interface IDataSourceMetadata {
ui: IDataSourceUISettings;
}

export interface IDataSourceUISelector {
displayDatasetsAsSource: boolean;
}

/**
* Represents the UI settings for a data source.
*/
export interface IDataSourceUISettings {
/**
* Controls UI elements related to data source selector.
*/
selector: IDataSourceUISelector;

/**
* The display name of the data source.
*/
label: string;

/**
* The group to which the data source belongs. This is used to group data sources in the selector.
*/
groupType: DataSourceUIGroupType;

/**
* The display name of the data source type.
*/
typeLabel: string;

/**
* A short description of the data source.
* @optional
*/
description?: string;

/**
* URI of the icon representing the data source.
* @optional
*/
icon?: string;
}

export interface IDataSourceDataSet<T = {}> {
dataSets: T;
}

export interface IDataSourceQueryResponse<T = {}> {
data: T;
}

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