Open manasvinibs opened 1 year ago
Following are the list of functions, interfaces and type definitions that are using legacy elasticsearch client properties and methods within the Opensearch Dashboard repo -
In src/core/server/opensearch/legacy/api_types.ts
-
LegacyCallAPIOptions
which defines how Opensearch API call should be made and result be processed.LegacyAPICaller
that defines Opensearch endpoints and makes use of legacy client class methods as API endpoint return types. LegacyAPICaller
is used to provide type definitions. Instead we should replace it with opensearch-js client caller interface type.
getUsageCollector()
- src/plugins/vis_type_vega/server/usage_collector/get_usage_collector.tsgetUsageCollector()
- src/plugins/visualizations/server/usage_collector/get_usage_collector.tsValidationTelemetryService
- src/plugins/vis_type_timeseries/server/validation_telemetry/validation_telemetry_service.tsgetUsage()
, getClusterUuid()
- src/plugins/usage_collection/server/routes/stats/stats.tsbulkFetch()
, bulkFetchUsage()
- src/plugins/usage_collection/server/collector/collector_set.tsfetch()
- src/plugins/usage_collection/server/collector/collector.tsStatsCollectionConfig {}
interface - src/plugins/telemetry_collection_manager/server/types.tsgetOpenSearchDashboards()
- src/plugins/telemetry/server/telemetry_collection/get_opensearch_dashboards.tsgetSavedObjectsCounts()
- src/plugins/opensearch_dashboards_usage_collection/server/collectors/opensearch_dashboards/get_saved_object_counts.tsgetQueryClient()
, getBasicAuthClient()
- src/plugins/data_source/server/legacy/configure_legacy_client.tsfetchProvider()
- src/plugins/data/server/search/collectors/fetch.tsdecideClient()
- src/plugins/data/server/index_patterns/routes.tsresolveTimePattern()
- src/plugins/data/server/index_patterns_fetcher/lib/resolve_time_pattern.tscallIndexAliasApi()
, callFieldCapsApi()
- src/plugins/data/server/index_patterns/fetcher/lib/opensearch_api.tsgetFieldCapabilities()
- src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_capabilities.tsIndexPatternsFetcher
- src/plugins/data/server/index_patterns/fetcher/index_patterns_fetcher.tsfetchProvider()
- src/plugins/data/server/dql_telemetry/usage_collector/fetch.tssetupMockCallCluster()
- src/plugins/data/server/dql_telemetery/usage_collector/fethc.test.tsTestOpenSearchServer
class - src/core/test_helpers/osd_server.tsAllServices
class- src/core/server/ui_settings/integration_tests/lib/server.tsLegacyScopedClusterClient
- src/core/server/opensearch/legacy/scoped_cluster_clients.tscallAsInternalUser()
, callAsCurrentUser()
- src/core/server/opensearch/legacy/cluster_client.tssrc/core/server/opensearch/legacy/cluster_client.ts
-
LegacyClusterClient
class creates Elasticsearch client instance to make API calls on behalf of dashboards internal user.
createLegacyClusterClient()
- src/core/server/opensearch/opensearch_service.ts
2.ILegacyClusterClient
type - Cluster API client created by platform. Below are the interfaces and functions with ILegacyClusterClient
type definitionsCollectionConfig{}
, Collection{}
- src/plugins/telemetery_collection_manager/server/types.tsregisterCollection()
- src/plugins/telemetry/server/telemetery_collection/register_collection.tsOpenSearchServiceSetup{}
- src/core/server/opensearch/types.tsOpenSearchServiceStart{}
- src/core/server/opensearch/types.tsILegacyCustomClusterClient
type - Cluster API client created by plugin. Below are the files with its type definitions -
FetcherTask
-src/plugins/telemetry/server/fetcher.ts OpenSearchServiceStart{}
- src/core/server/opensearch/types.tsOpenSearchServiceSetup{}
- src/core/server/opensearch/types.tscreateLegacyCustomClient()
- src/core/server/opensearch/opensearch_service.tscallAsInternalUser()
- LegacyAPICaller interface implementation to make Opensearch API call on behalf of Dashboards internal user.
getStatsCollectionConfig()
- src/plugins/telemetery_collection_manager/server/plugin.tscallAsCurrentUser()
- LegacyAPICaller
interface implementation to make API call on behalf of user initiated request to dashboards server via http request headers.asScoped()
- Elasticsearch client instance shared between all the scoped clients created for the cluster client
CoreOpenSearchRouteHandlerContext
class - src/core/server/core_route_handler_context.tsgetStatsCollectionConfig()
- src/plugins/telemetery_collection_manager/server/plugin.tssrc/plugins/data_source/server/legacy/client_config.ts
parseClientOptions()
- Provides config options which is used by legacy Elasticsearch client object to create root client instance. This consumes ConfigOptions module from elasticSearch package which will be replaced by opensearch js client options.src/plugins/data_source/server/legacy/configure_legacy_client.ts
- Mainly Data Source plugin consumes this wrapper for legacy client connection to opensearch APIs
configureLegacyClient()
- creates root client which is an instance of legacy client class and use it for connection with the given data source endpoint.
DataSourceService
class provides legacy data source client as part of the setup() lifecycle methods to the plugins that uses DataSourceService - src/plugins/data_source/server/data_source_service.tsgetBasicAuthClient()
- Root client uses legacy elasticsearch clientgetAWSClient()
getQueryClient()
- Creating root client from legacy elasticsearch for different types of auth typescallAPI()
- calls Opensearch API endpoint using legacy clientsrc/plugins/data_source/server/plugins.ts
- DataSourcePlugin using DataSourceService to register plugin context to route handler context and create router methods.
context.dataSource.opensearch.legacy.getClient()
registerResolveIndexRoute()
- src/plugins/index_pattern_management/server/routes/resolve_index.ts DataSourcePluginRequestContext{}
- src/plugins/data_source/server/types.tsregisterRoutes()
- src/plugins/data/server/index_patterns/routes.tssrc/core/server/opensearch/opensearch_service.ts
- class OpenSearchService which implements CoreService, creates both legacy elasticsearch client as well as new opensearch js client. With legacy client, there are two instances: legacy custom client and legacy client. OpenSearchService setup() lifecycle method takes care of instantiating all the 3 clients before moving on to start() lifecycle. Below are its references:
setup()
- src/core/server/server.ts
coreSetup
, savedObjectsSetup
, statusSetup
- Server class initializes all the core services that are part of Opensearch Dashboard and also defines its lifecycle methods. packages/osd-opensearch-archiver/src/opensearch_archiver.ts
createGenerateIndexRecordsStream()
- packages/osd-opensearch-archiver/src/lib/indices/generate_index_records_stream.tscreateGenerateDocRecordsStream()
- packages/osd-opensearch-archiver/src/lib/docs/generate_doc_records_stream.tsloadAction()
- packages/osd-opensearch-archiver/src/actions/load.ts
createCreateIndexStream()
- packages/osd-opensearch-archiver/src/lib/indices/create_index_stream.ts
deleteOpenSearchDashboardsIndices()
- packages/osd-opensearch-archiver/src/lib/indices/opensearch_dashboards_index.ts
deleteIndex()
→waitForSnapshotCompletion()
fetchOpenSearchDashboardsIndices()
createIndexDocRecordsStream()
- packages/osd-opensearch-archiver/src/lib/docs/index_doc_records_stream.tscreateDefaultSpace()
unloadAction()
createDeleteIndexStream()
→ cleanOpenSearchDashboardsIndices()
emptyOpenSearchDashboardsIndexAction()
→ migrateOpenSearchDashboardsIndex()
vis_type_vega
visualizations
vis_type_timeseries
usage_collection
telemetry_collection_manager
opensearch_dashboards_usage_collection
telemetry_collection
data_source
data
index_pattern_management
List of packages in OSD currently using Elasticsearch legacy client methods:
osd-opensearch-archiver
Aliasing elasticsearch to npm:@opensearch-project/opensearch@2.1.0
yarn osd bootstrap
yarn run v1.22.19
$ scripts/use_node scripts/osd bootstrap
info [opensearch-dashboards] running yarn
$ scripts/use_node ./preinstall_check
[1/5] Validating package.json...
[2/5] Resolving packages...
warning Resolution field "typescript@4.0.2" is incompatible with requested version "typescript@~4.5.2"
success Already up-to-date.
succ yarn.lock analysis completed without any issues
succ 22 bootstrap builds are cached
info [@osd/opensearch-archiver] running [osd:bootstrap] script
ERROR [bootstrap] failed:
ERROR Error: Command failed with exit code 2: /home/ubuntu/.nvm/versions/node/v14.20.1/lib/node_modules/yarn/bin/yarn.js run osd:bootstrap
error Command failed with exit code 2.
$ ../../scripts/use_node ../../scripts/remove.js target && tsc
Deleted files and directories:
/home/ubuntu/OpenSearch-Dashboards/packages/osd-opensearch-archiver/target
src/cli.ts(103,9): error TS2345: Argument of type '{ host: string | true | string[]; log: string | never[]; }' is not assignable to parameter of type 'ClientOptions'.
Object literal may only specify known properties, and 'host' does not exist in type 'ClientOptions'.
src/lib/docs/generate_doc_records_stream.ts(32,18): error TS2305: Module '"../../../node_modules/@types/elasticsearch"' has no exported member 'SearchParams'.
src/lib/docs/generate_doc_records_stream.ts(32,32): error TS2305: Module '"../../../node_modules/@types/elasticsearch"' has no exported member 'SearchResponse'.
src/lib/docs/generate_doc_records_stream.ts(74,15): error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: Scroll<Record<string, any>> | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<ApiResponse<Record<string, any>, unknown>>', gave the following error.
Argument of type '{ scrollId: any; scroll: string; }' is not assignable to parameter of type 'Scroll<Record<string, any>>'.
Object literal may only specify known properties, but 'scrollId' does not exist in type 'Scroll<Record<string, any>>'. Did you mean to write 'scroll_id'?
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, unknown>): TransportRequestCallback', gave the following error.
Argument of type '{ scrollId: any; scroll: string; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, unknown>'.
Object literal may only specify known properties, and 'scrollId' does not exist in type 'callbackFn<Record<string, any>, unknown>'.
src/lib/docs/index_doc_records_stream.ts(61,38): error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: Bulk<any[]> | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<ApiResponse<Record<string, any>, unknown>>', gave the following error.
Argument of type '{ requestTimeout: number; body: any[]; }' is not assignable to parameter of type 'Bulk<any[]>'.
Object literal may only specify known properties, and 'requestTimeout' does not exist in type 'Bulk<any[]>'.
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, unknown>): TransportRequestCallback', gave the following error.
Argument of type '{ requestTimeout: number; body: any[]; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, unknown>'.
Object literal may only specify known properties, and 'requestTimeout' does not exist in type 'callbackFn<Record<string, any>, unknown>'.
src/lib/docs/index_doc_records_stream.ts(62,14): error TS2339: Property 'errors' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/delete_index.ts(49,29): error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: IndicesGetAlias | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<ApiResponse<Record<string, any>, unknown>>', gave the following error.
Argument of type '{ name: string; ignore: number[]; }' is not assignable to parameter of type 'IndicesGetAlias'.
Object literal may only specify known properties, and 'ignore' does not exist in type 'IndicesGetAlias'.
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, unknown>): TransportRequestCallback', gave the following error.
Argument of type '{ name: string; ignore: number[]; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, unknown>'.
Object literal may only specify known properties, and 'name' does not exist in type 'callbackFn<Record<string, any>, unknown>'.
src/lib/indices/delete_index.ts(50,22): error TS2339: Property 'status' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/delete_index.ts(95,7): error TS2339: Property 'snapshots' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/delete_index.ts(106,13): error TS2339: Property 'snapshots' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/generate_index_records_stream.ts(41,29): error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: IndicesGet | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<ApiResponse<Record<string, any>, unknown>>', gave the following error.
Argument of type '{ index: any; filterPath: string[]; }' is not assignable to parameter of type 'IndicesGet'.
Object literal may only specify known properties, but 'filterPath' does not exist in type 'IndicesGet'. Did you mean to write 'filter_path'?
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, unknown>): TransportRequestCallback', gave the following error.
Argument of type '{ index: any; filterPath: string[]; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, unknown>'.
Object literal may only specify known properties, and 'index' does not exist in type 'callbackFn<Record<string, any>, unknown>'.
src/lib/indices/generate_index_records_stream.ts(60,14): error TS2537: Type 'ApiResponse<Record<string, any>, unknown>' has no matching index signature for type 'string'.
src/lib/indices/opensearch_dashboards_index.ts(31,18): error TS2305: Module '"../../../node_modules/@types/elasticsearch"' has no exported member 'CreateDocumentParams'.
src/lib/indices/opensearch_dashboards_index.ts(105,6): error TS2339: Property 'map' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/opensearch_dashboards_index.ts(129,24): error TS2769: No overload matches this call.
Overload 1 of 4, '(params?: DeleteByQuery<{ query: { bool: { must_not: { ids: { type: string; values: string[]; }; }; }; }; }> | undefined, options?: TransportRequestOptions | undefined): TransportRequestPromise<...>', gave the following error.
Argument of type '{ index: string; body: { query: { bool: { must_not: { ids: { type: string; values: string[]; }; }; }; }; }; ignore: number[]; }' is not assignable to parameter of type 'DeleteByQuery<{ query: { bool: { must_not: { ids: { type: string; values: string[]; }; }; }; }; }>'.
Object literal may only specify known properties, and 'ignore' does not exist in type 'DeleteByQuery<{ query: { bool: { must_not: { ids: { type: string; values: string[]; }; }; }; }; }>'.
Overload 2 of 4, '(callback: callbackFn<Record<string, any>, unknown>): TransportRequestCallback', gave the following error.
Argument of type '{ index: string; body: { query: { bool: { must_not: { ids: { type: string; values: string[]; }; }; }; }; }; ignore: number[]; }' is not assignable to parameter of type 'callbackFn<Record<string, any>, unknown>'.
Object literal may only specify known properties, and 'index' does not exist in type 'callbackFn<Record<string, any>, unknown>'.
src/lib/indices/opensearch_dashboards_index.ts(146,14): error TS2339: Property 'total' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/opensearch_dashboards_index.ts(146,29): error TS2339: Property 'deleted' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/opensearch_dashboards_index.ts(149,14): error TS2339: Property 'deleted' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
src/lib/indices/opensearch_dashboards_index.ts(150,14): error TS2339: Property 'total' does not exist on type 'ApiResponse<Record<string, any>, unknown>'.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
at makeError (/home/ubuntu/OpenSearch-Dashboards/packages/osd-pm/dist/index.js:25045:11)
at handlePromise (/home/ubuntu/OpenSearch-Dashboards/packages/osd-pm/dist/index.js:23981:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async /home/ubuntu/OpenSearch-Dashboards/packages/osd-pm/dist/index.js:9238:9
at async scheduleItem (/home/ubuntu/OpenSearch-Dashboards/packages/osd-pm/dist/index.js:11285:9)
error Command failed with exit code 1.
Params type mismatch in Elasticseach client modules vs Opensearch client modules.
Client['deleteTemplate']
Client['fieldStats']
Client['getTemplate']
Client['putTemplate']
Client['suggest']
Client['indices']['flushSynced']
Client['indices']['existsType']
Hi, Can we consider this issue as done since issue #4041 and #4142 are closed and merged, what is the dependency on #4306
Hi, Can we consider this issue as done since issue #4041 and #4142 are closed and merged, what is the dependency on #4306 Here is the link to the list of places where client update needs to happen - https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3900#issuecomment-1544753815 The PR's above linked are only addressing consolidating clients in
osd-opensearch-archiver
package.
As part of version decoupling project, one of the pre-req task is to consolidate all the clients usages in Opensearch Dashboards which interacts with Opensearch.
Reference: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3095
Decoupling OpenSearch Dashboards and OpenSearch
Various components of OpenSearch Dashboards interact with OpenSearch using one of three unrelated methods: the legacy client, the OpenSearch client, and direct HTTP calls.
* elasticsearch@16.7.3 ([npm](https://www.npmjs.com/package/@elastic/elasticsearch)) * via core/server/opensearch/legacy * via plugins/data_source/server/legacy * directly by @osd/opensearch-archiver * to provide type definitions in * plugins/data/server/search * plugins/data/public/search * plugins/data/common/search * plugins/data_source/server/client * plugins/discover/public/application * plugins/vis_type_vega/server * plugins/visualizations/server * some tests * @opensearch-project/opensearch ([npm](https://www.npmjs.com/package/@opensearch-project/opensearch)) * via core/server/opensearch/client * via plugins/data_source/server/client * to provide type definitions in * plugins/data/server/search * plugins/data/common/search * OsdClientRequester ([github](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/d7004dc5b0392477fdd54ac66b29d231975a173b/packages/osd-dev-utils/src/osd_client/osd_client_requester.ts#L89)) making HTTP calls * via @osd/dev-utilsProposed Solution
Make OpenSearch Dashboards rely solely on the Node.js client, @opensearch-project/opensearch, and delegate the responsibility of interacting with OpenSearch to it. The Node.js client is a low-level library that could be compatible with more that one major version of OpenSearch and any variations would be normalized by a wrapper (introduced below). OpenSearch Dashboards will be instructed to use the latest compatible major version of the Node.js client available. This involves replacing the components that consume the legacy elasticsearch client and the direct HTTP channel with method that call the official Node.js client.
Requirement:
elasticsearch@16.7.3
npm usages and replace it with opensearch-js client.