Skip to content

Commit

Permalink
[Discover-next] add query enhancements plugin as a core plugin (opens…
Browse files Browse the repository at this point in the history
…earch-project#7212)

### Description

Introduces the addition of a new core plugin called `Query Enhancements`

This plugin seems to be focused on enhancing query capabilities, particularly in areas like PPL (Piped Processing Language), SQL, and natural language query assistance.

#### Plugin Configuration and Setup

The plugin is set up with the necessary configuration files:

- src/plugins/query_enhancements/opensearch_dashboards.json: Defines the plugin's metadata and dependencies.
- src/plugins/query_enhancements/common/config.ts: Contains the configuration schema for the plugin.
- src/plugins/query_enhancements/public/plugin.tsx: The main plugin file that sets up the public-facing part of the plugin.
- src/plugins/query_enhancements/server/plugin.ts: The server-side setup for the plugin.

#### Query Assist Feature

A significant part of the plugin is dedicated to a "Query Assist" feature:

- src/plugins/query_enhancements/public/query_assist/: This directory contains components, hooks, and utilities for the Query Assist feature.
- src/plugins/query_enhancements/public/query_assist/components/query_assist_bar.tsx: A React component for the Query Assist bar.
- src/plugins/query_enhancements/server/routes/query_assist/: Server-side routing for Query Assist functionality.

#### Search Interceptors

The plugin introduces several search interceptors:

- src/plugins/query_enhancements/public/search/ppl_search_interceptor.ts
- src/plugins/query_enhancements/public/search/sql_search_interceptor.ts
- src/plugins/query_enhancements/public/search/sql_async_search_interceptor.ts

These interceptors likely modify or enhance the search functionality for different query languages.

#### Data Source Connection

There's a new feature for data source connections:

- src/plugins/query_enhancements/public/data_source_connection/: This directory contains components and services for managing data source connections.

#### Server-side Search Strategies

The plugin implements server-side search strategies for different query types:

- src/plugins/query_enhancements/server/search/ppl_search_strategy.ts
- src/plugins/query_enhancements/server/search/sql_search_strategy.ts
- src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts

#### Modifications to Existing Files

There are some modifications to existing files outside the new plugin directory:

- src/plugins/data/public/index.ts: Exports new types and interfaces.
- src/plugins/data/public/ui/index.ts: Exports new UI components.
- src/plugins/data/public/ui/query_editor/index.tsx: Modifies the QueryEditor component.

#### Testing

The plugin includes a comprehensive test setup:

- src/plugins/query_enhancements/test/: Contains Jest configuration and setup files for testing.

#### Acknowledgements

Contains work by @sejli @joshuali925 @Swiddis @paulstn @mengweieric 
Thx @ashwin-pc for the description summary

### Issues Related

opensearch-project#6072
opensearch-project#6074
opensearch-project#6075

Commits include:
* init

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

* fixing bugs and removing target

Signed-off-by: Sean Li <[email protected]>

* add target and build to .gitignore

Signed-off-by: Sean Li <[email protected]>

* Remove SQL Async and Query Assist

Going for the light weight solution for 2.15. So took out what wasn't
required deliverable.

However, I created a branch `feature/discover-next` which has the state
where all the features where added so we can port it over post 2.15.

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

* adding fix for PPL queries

Signed-off-by: Sean Li <[email protected]>

* Clean up files and add helper functions

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

* final touches

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

* [Discover-next] add query assist to query enhancements plugin (opensearch-project#6895)

it adds query assist specific logic in query enhancements plugin to show a UI above the PPL search bar if user has configured PPL agent.

Issues Resolved: opensearch-project#6820

* add query assist to query enhancements

Signed-off-by: Joshua Li <[email protected]>

* align language to uppercase

Signed-off-by: Joshua Li <[email protected]>

* pick PR 6167

Signed-off-by: Joshua Li <[email protected]>

* use useState hooks for query assist

There is a bug in data explorer `AppContainer` where memorized
`DiscoverCanvas` gets unmounted after `setQuery`. PR 6167 works around
it by memorizing `AppContainer`. As query assist is no longer being
unmounted, we can use proper hooks to persist state now.

Signed-off-by: Joshua Li <[email protected]>

* Revert "pick PR 6167"

This reverts commit acb0d41.

Wait for official 6167 to merge to avoid conflict

Signed-off-by: Joshua Li <[email protected]>

* address comments for PR 6894

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
(cherry picked from commit 016e0f2)

* [Discover-next] Address comments for search bar extensions and query assist (opensearch-project#6933)

* pass dependencies to isEnabled func

Signed-off-by: Joshua Li <[email protected]>

* add lazy and memo to search bar extensions

Signed-off-by: Joshua Li <[email protected]>

* move ppl specific string out from query assist

Signed-off-by: Joshua Li <[email protected]>

* prevent setstate after hook unmounts

Signed-off-by: Joshua Li <[email protected]>

* add max-height to search bar extensions

Signed-off-by: Joshua Li <[email protected]>

* prevent setstate after component unmounts

Signed-off-by: Joshua Li <[email protected]>

* move ml-commons API to common/index.ts

Signed-off-by: Joshua Li <[email protected]>

* improve i18n and accessibility usages

Signed-off-by: Joshua Li <[email protected]>

* add hard-coded suggestions for sample data indices

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
(cherry picked from commit 4aade0f)

* [Discover-next] Support data sources for query assist (opensearch-project#6972)

* disable query assist for non-default datasource

Signed-off-by: Joshua Li <[email protected]>

* disable query assist input when loading

Signed-off-by: Joshua Li <[email protected]>

* support MDS for query assist

Signed-off-by: Joshua Li <[email protected]>

* add unit tests for agents

Signed-off-by: Joshua Li <[email protected]>

* Revert "add unit tests for agents"

This reverts commit 983514e.
The test configs are not yet setup in query_enhancements plugins.

Signed-off-by: Joshua Li <[email protected]>

---------

Signed-off-by: Joshua Li <[email protected]>
(cherry picked from commit 328e08e)

* add query assist banner

Signed-off-by: Joshua Li <[email protected]>

* implement banner rendering logic

Signed-off-by: Joshua Li <[email protected]>

* pick opensearch-project/dashboards-observability/pull/1896

Signed-off-by: Joshua Li <[email protected]>

* Conditionally render the data source select config

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

* restore no space

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

* add basic tests

Signed-off-by: Joshua Li <[email protected]>

* add index selector

This is a temporary solution given that in discover the index pattern
selector will be removed. Before datasource and dataset selectors are
added, query assist will rely on this index pattern selector to
determine which index user wants to query.

Signed-off-by: Joshua Li <[email protected]>

* MDS working with PPL and SQL

Utilizing the work from MDS to make PPL and SQL calls to a remote
cluster.

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

* rename logo to mark

Signed-off-by: Joshua Li <[email protected]>

* extract supported languages to config

Signed-off-by: Joshua Li <[email protected]>

* Add missing license headers

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

* initial implementation for async queries

Signed-off-by: Sean Li <[email protected]>

* remove queryId and sessionId from facet

Signed-off-by: Sean Li <[email protected]>

* fix: Update call out tests with intl wrapper

Signed-off-by: Simeon Widdis <[email protected]>

* maintenance: Add and apply lint command

Signed-off-by: Simeon Widdis <[email protected]>

* changing to observables

Signed-off-by: Sean Li <[email protected]>

* search interceptor and cleanup

Signed-off-by: Sean Li <[email protected]>

* moving polling class into plugin

Signed-off-by: Sean Li <[email protected]>

* Some minor clean ups plus lint

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

* test: Add mock-heavy tests for sql search strategy

Signed-off-by: Simeon Widdis <[email protected]>

* test: add GH workflows

Signed-off-by: Simeon Widdis <[email protected]>

* More clean ups

Add some props interfaces and consolidated some of the facets

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

* chore: apply auto-lints to plugin

Signed-off-by: Simeon Widdis <[email protected]>

* Not done

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

* working

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

* working and styled

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

* add connection service

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

* Update public/types.ts

Co-authored-by: Joshua Li <[email protected]>

* Update public/plugin.tsx

Co-authored-by: Joshua Li <[email protected]>

* Update public/plugin.tsx

Co-authored-by: Joshua Li <[email protected]>

* fix linter

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

* add more tests for query assist (opensearch-project#31)

add more tests for query assist
update eslint config to make it work
increase index selector width

Signed-off-by: Joshua Li <[email protected]>

* fix!: remove dataSource key in get connection response

The `Connection` type does not have the extra `dataSource` object around
response, and most of the time code references connection over
dataSource. remove the redundent object to make response consistent with
type.

Signed-off-by: Joshua Li <[email protected]>

* change isEnabled to an observable based on selected connection

Signed-off-by: Joshua Li <[email protected]>

* protect duplicated calls

Signed-off-by: Joshua Li <[email protected]>

* [build] import via start services

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

* Changeset file for PR opensearch-project#7212 created/updated

* foobar

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

* updating imports still in progress

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

* Update more imports

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

* fix setting of state

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

* fixes bugs

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

* Update test

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

---------

Signed-off-by: Kawika Avilla <[email protected]>
Signed-off-by: Sean Li <[email protected]>
Signed-off-by: Joshua Li <[email protected]>
Signed-off-by: Simeon Widdis <[email protected]>
Co-authored-by: Sean Li <[email protected]>
Co-authored-by: Joshua Li <[email protected]>
Co-authored-by: Simeon Widdis <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla authored Jul 16, 2024
1 parent 27669cf commit 9194d83
Show file tree
Hide file tree
Showing 84 changed files with 4,344 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7212.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add query enhancements plugin as a core plugin ([#7212](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7212))
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- forms
- [Form_wizard](../src/plugins/opensearch_ui_shared/public/forms/form_wizard/README.md)
- [Multi_content](../src/plugins/opensearch_ui_shared/public/forms/multi_content/README.md)
- [Query_enhancements](../src/plugins/query_enhancements/README.md)
- [Saved_objects](../src/plugins/saved_objects/README.md)
- [Saved_objects_management](../src/plugins/saved_objects_management/README.md)
- [Share](../src/plugins/share/README.md)
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ export {
IndexPatternSelectProps,
QueryStringInput,
QueryStringInputProps,
QueryEditor,
QueryEditorExtensionConfig,
QueryEditorExtensions,
QueryEditorExtensionDependencies,
QueryEditorProps,
QueryEditorTopRow,
// for BWC, keeping the old name
IUiStart as DataPublicPluginStartUi,
} from './ui';
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/data/public/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@ export {
export { IndexPatternSelectProps } from './index_pattern_select';
export { FilterLabel } from './filter_bar';
export { QueryStringInput, QueryStringInputProps } from './query_string_input';
export {
QueryEditorTopRow,
QueryEditor,
QueryEditorProps,
QueryEditorExtensions,
QueryEditorExtensionDependencies,
QueryEditorExtensionConfig,
} from './query_editor';
export { SearchBar, SearchBarProps, StatefulSearchBarProps } from './search_bar';
export { SuggestionsComponent } from './typeahead';
6 changes: 5 additions & 1 deletion src/plugins/data/public/ui/query_editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ export const QueryEditor = (props: QueryEditorProps) => (
);
export type { QueryEditorProps };

export { QueryEditorExtensions, QueryEditorExtensionConfig } from './query_editor_extensions';
export {
QueryEditorExtensions,
QueryEditorExtensionDependencies,
QueryEditorExtensionConfig,
} from './query_editor_extensions';
20 changes: 9 additions & 11 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ export default class QueryEditorUI extends Component<Props, State> {
: undefined;
this.onChange(newQuery, dateRange);
this.onSubmit(newQuery, dateRange);
this.setState({ isDataSetsVisible: enhancement?.searchBar?.showDataSetsSelector ?? true });
this.setState({
isDataSourcesVisible: enhancement?.searchBar?.showDataSourcesSelector ?? true,
isDataSetsVisible: enhancement?.searchBar?.showDataSetsSelector ?? true,
});
};

Expand All @@ -231,19 +231,15 @@ export default class QueryEditorUI extends Component<Props, State> {
private initDataSourcesVisibility = () => {
if (this.componentIsUnmounting) return;

const isDataSourcesVisible =
this.props.settings.getQueryEnhancements(this.props.query.language)?.searchBar
?.showDataSourcesSelector ?? true;
this.setState({ isDataSourcesVisible });
return this.props.settings.getQueryEnhancements(this.props.query.language)?.searchBar
?.showDataSourcesSelector;
};

private initDataSetsVisibility = () => {
if (this.componentIsUnmounting) return;

const isDataSetsVisible =
this.props.settings.getQueryEnhancements(this.props.query.language)?.searchBar
?.showDataSetsSelector ?? true;
this.setState({ isDataSetsVisible });
return this.props.settings.getQueryEnhancements(this.props.query.language)?.searchBar
?.showDataSetsSelector;
};

public onMouseEnterSuggestion = (index: number) => {
Expand All @@ -260,8 +256,10 @@ export default class QueryEditorUI extends Component<Props, State> {

this.initPersistedLog();
// this.fetchIndexPatterns().then(this.updateSuggestions);
this.initDataSourcesVisibility();
this.initDataSetsVisibility();
this.setState({
isDataSourcesVisible: this.initDataSourcesVisibility() || true,
isDataSetsVisible: this.initDataSetsVisibility() || true,
});
}

public componentDidUpdate(prevProps: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export const QueryEditorExtensions = (props: ComponentProps<typeof LazyQueryEdit
</React.Suspense>
);

export { QueryEditorExtensionConfig } from './query_editor_extension';
export {
QueryEditorExtensionDependencies,
QueryEditorExtensionConfig,
} from './query_editor_extension';
7 changes: 7 additions & 0 deletions src/plugins/query_enhancements/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prefix": "queryEnhancements",
"paths": {
"queryEnhancements": "."
},
"translations": ["translations/ja-JP.json"]
}
9 changes: 9 additions & 0 deletions src/plugins/query_enhancements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Query Enhancements Plugin

Optional plugin, that registers query enhancing capabilities within
the application.

## List of enhancements

* PPL within Discover
* SQL within Discover
23 changes: 23 additions & 0 deletions src/plugins/query_enhancements/common/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { schema, TypeOf } from '@osd/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
queryAssist: schema.object({
supportedLanguages: schema.arrayOf(
schema.object({
language: schema.string(),
agentConfig: schema.string(),
}),
{
defaultValue: [{ language: 'PPL', agentConfig: 'os_query_assist_ppl' }],
}
),
}),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
47 changes: 47 additions & 0 deletions src/plugins/query_enhancements/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const PLUGIN_ID = 'queryEnhancements';
export const PLUGIN_NAME = 'queryEnhancements';

export const BASE_API = '/api/enhancements';

export const SEARCH_STRATEGY = {
PPL: 'ppl',
SQL: 'sql',
SQL_ASYNC: 'sqlasync',
};

export const API = {
SEARCH: `${BASE_API}/search`,
PPL_SEARCH: `${BASE_API}/search/${SEARCH_STRATEGY.PPL}`,
SQL_SEARCH: `${BASE_API}/search/${SEARCH_STRATEGY.SQL}`,
SQL_ASYNC_SEARCH: `${BASE_API}/search/${SEARCH_STRATEGY.SQL_ASYNC}`,
QUERY_ASSIST: {
LANGUAGES: `${BASE_API}/assist/languages`,
GENERATE: `${BASE_API}/assist/generate`,
},
DATA_SOURCE: {
CONNECTIONS: `${BASE_API}/datasource/connections`,
},
};

export const URI = {
PPL: '/_plugins/_ppl',
SQL: '/_plugins/_sql',
ASYNC_QUERY: '/_plugins/_async_query',
ML: '/_plugins/_ml',
OBSERVABILITY: '/_plugins/_observability',
DATA_CONNECTIONS: '/_plugins/_query/_datasources',
};

export const OPENSEARCH_API = {
PANELS: `${URI.OBSERVABILITY}/object`,
DATA_CONNECTIONS: URI.DATA_CONNECTIONS,
};

export const UI_SETTINGS = {};

export const ERROR_DETAILS = { GUARDRAILS_TRIGGERED: 'guardrails triggered' };
8 changes: 8 additions & 0 deletions src/plugins/query_enhancements/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export * from './constants';
export * from './types';
export * from './utils';
6 changes: 6 additions & 0 deletions src/plugins/query_enhancements/common/query_assist/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { QueryAssistParameters, QueryAssistResponse } from './types';
19 changes: 19 additions & 0 deletions src/plugins/query_enhancements/common/query_assist/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { TimeRange } from 'src/plugins/data/common';

export interface QueryAssistResponse {
query: string;
timeRange?: TimeRange;
}

export interface QueryAssistParameters {
question: string;
index: string;
language: string;
// for MDS
dataSourceId?: string;
}
15 changes: 15 additions & 0 deletions src/plugins/query_enhancements/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { CoreSetup } from 'opensearch-dashboards/public';
import { Observable } from 'rxjs';

export interface FetchDataFrameContext {
http: CoreSetup['http'];
path: string;
signal?: AbortSignal;
}

export type FetchFunction<T, P = void> = (params?: P) => Observable<T>;
Loading

0 comments on commit 9194d83

Please sign in to comment.