Skip to content

Commit

Permalink
[nodejs client] hookup js client with dashboards (#1180)
Browse files Browse the repository at this point in the history
change @elastic/elasticsearch to @opensearch-project/opensearch

Partically Resolved: #837

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
ananzh authored Jan 27, 2022
1 parent 8777eb3 commit bf366da
Show file tree
Hide file tree
Showing 33 changed files with 92 additions and 94 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
},
"dependencies": {
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "7.10.0-rc.1",
"@elastic/eui": "29.3.2",
"@elastic/good": "^9.0.1-kibana3",
"@elastic/numeral": "^2.5.0",
Expand All @@ -134,6 +133,7 @@
"@hapi/podium": "^4.1.3",
"@hapi/vision": "^6.1.0",
"@hapi/wreck": "^17.1.0",
"@opensearch-project/opensearch": "^1.0.2",
"@osd/ace": "1.0.0",
"@osd/analytics": "1.0.0",
"@osd/apm-config-loader": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-opensearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"osd:watch": "node scripts/build --watch"
},
"dependencies": {
"@elastic/elasticsearch": "7.10.0-rc.1",
"@opensearch-project/opensearch": "^1.0.2",
"@osd/dev-utils": "1.0.0",
"abort-controller": "^3.0.0",
"chalk": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-opensearch/src/utils/native_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

const { Client } = require('@elastic/elasticsearch');
const { Client } = require('@opensearch-project/opensearch');
const chalk = require('chalk');

const { log: defaultLog } = require('./log');
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-opensearch/src/utils/native_realm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

const { NativeRealm } = require('./native_realm');

jest.genMockFromModule('@elastic/elasticsearch');
jest.mock('@elastic/elasticsearch');
jest.genMockFromModule('@opensearch-project/opensearch');
jest.mock('@opensearch-project/opensearch');

const { ToolingLog } = require('@osd/dev-utils');
const { Client } = require('@elastic/elasticsearch');
const { Client } = require('@opensearch-project/opensearch');

const mockClient = {
xpack: {
Expand Down
10 changes: 5 additions & 5 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts

import { Action } from 'history';
import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';
import { ApiResponse } from '@opensearch-project/opensearch/lib/Transport';
import Boom from '@hapi/boom';
import { ConfigPath } from '@osd/config';
import { EnvironmentMode } from '@osd/config';
Expand All @@ -17,7 +17,7 @@ import { ExclusiveUnion } from '@elastic/eui';
import { History } from 'history';
import { Href } from 'history';
import { IconType } from '@elastic/eui';
import { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { KibanaClient } from '@opensearch-project/opensearch/api/kibana';
import { Location } from 'history';
import { LocationDescriptorObject } from 'history';
import { Logger } from '@osd/logging';
Expand All @@ -33,9 +33,9 @@ import React from 'react';
import { RecursiveReadonly } from '@osd/utility-types';
import * as Rx from 'rxjs';
import { ShallowPromise } from '@osd/utility-types';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestOptions } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestParams } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';
import { Type } from '@osd/config-schema';
import { TypeOf } from '@osd/config-schema';
import { UnregisterCallback } from 'history';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jest.doMock('elasticsearch', () => {
});

export const MockOpenSearchClient = jest.fn();
jest.doMock('@elastic/elasticsearch', () => {
const real = jest.requireActual('@elastic/elasticsearch');
jest.doMock('@opensearch-project/opensearch', () => {
const real = jest.requireActual('@opensearch-project/opensearch');
return {
...real,
Client: MockOpenSearchClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { errors as opensearchErrors } from 'elasticsearch';
import { LegacyOpenSearchErrorHelpers } from '../../opensearch/legacy';

import { opensearchClientMock } from '../../opensearch/client/mocks';
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { ResponseError } from '@opensearch-project/opensearch/lib/errors';
import * as osdTestServer from '../../../test_helpers/osd_server';
import { InternalOpenSearchServiceStart } from '../../opensearch';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
import { URL } from 'url';
import { Duration } from 'moment';
import { ClientOptions, NodeOptions } from '@elastic/elasticsearch';
import { ClientOptions, NodeOptions } from '@opensearch-project/opensearch';
import { OpenSearchConfig } from '../opensearch_config';
import { DEFAULT_HEADERS } from '../default_headers';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { Client } from '@elastic/elasticsearch';
import { Client } from '@opensearch-project/opensearch';
import { Logger } from '../../logging';
import { GetAuthHeaders, Headers, isOpenSearchDashboardsRequest, isRealRequest } from '../../http';
import { ensureRawRequest, filterHeaders } from '../../http/router';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jest.doMock('./client_config', () => ({
}));

export const ClientMock = jest.fn();
jest.doMock('@elastic/elasticsearch', () => {
const actual = jest.requireActual('@elastic/elasticsearch');
jest.doMock('@opensearch-project/opensearch', () => {
const actual = jest.requireActual('@opensearch-project/opensearch');
return {
...actual,
Client: ClientMock,
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/opensearch/client/configure_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import { Buffer } from 'buffer';
import { Readable } from 'stream';

import { RequestEvent, errors } from '@elastic/elasticsearch';
import { TransportRequestParams, RequestBody } from '@elastic/elasticsearch/lib/Transport';
import { RequestEvent, errors } from '@opensearch-project/opensearch';
import { TransportRequestParams, RequestBody } from '@opensearch-project/opensearch/lib/Transport';

import { parseClientOptionsMock, ClientMock } from './configure_client.test.mocks';
import { loggingSystemMock } from '../../logging/logging_system.mock';
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('configureClient', () => {
});

describe('Client logging', () => {
it('logs error when the client emits an @elastic/elasticsearch error', () => {
it('logs error when the client emits an @opensearch-project/opensearch error', () => {
const client = configureClient(config, { logger, scoped: false });

const response = createApiResponse({ body: {} });
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/opensearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
import { Buffer } from 'buffer';
import { stringify } from 'querystring';
import { Client } from '@elastic/elasticsearch';
import { RequestBody } from '@elastic/elasticsearch/lib/Transport';
import { Client } from '@opensearch-project/opensearch';
import { RequestBody } from '@opensearch-project/opensearch/lib/Transport';

import { Logger } from '../../logging';
import { parseClientOptions, OpenSearchClientConfig } from './client_config';
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/opensearch/client/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import {
ResponseError,
ConnectionError,
ConfigurationError,
} from '@elastic/elasticsearch/lib/errors';
import { ApiResponse } from '@elastic/elasticsearch';
} from '@opensearch-project/opensearch/lib/errors';
import { ApiResponse } from '@opensearch-project/opensearch';
import { isResponseError, isUnauthorizedError } from './errors';

const createApiResponseError = ({
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { ResponseError } from '@opensearch-project/opensearch/lib/errors';

export type UnauthorizedError = ResponseError & {
statusCode: 401;
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/opensearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import { Client, ApiResponse } from '@elastic/elasticsearch';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { Client, ApiResponse } from '@opensearch-project/opensearch';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';
import { OpenSearchClient } from './types';
import { ICustomClusterClient } from './cluster_client';

Expand Down Expand Up @@ -63,7 +63,7 @@ const createInternalClientMock = (): DeeplyMockedKeys<Client> => {
};

const mockify = (obj: Record<string, any>, omitted: string[] = []) => {
// the @elastic/elasticsearch::Client uses prototypical inheritance
// the @opensearch-project/opensearch::Client uses prototypical inheritance
// so we have to crawl up the prototype chain and get all descriptors
// to find everything that we should be mocking
const descriptors = getAllPropertyDescriptors(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { errors } from '@elastic/elasticsearch';
import { errors } from '@opensearch-project/opensearch';
import { opensearchClientMock } from './mocks';
import { loggingSystemMock } from '../../logging/logging_system.mock';
import { retryCallCluster, migrationRetryCallCluster } from './retry_call_cluster';
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/opensearch/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
* GitHub history for details.
*/

import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import type { KibanaClient } from '@opensearch-project/opensearch/api/kibana';
import type {
ApiResponse,
TransportRequestOptions,
TransportRequestParams,
TransportRequestPromise,
} from '@elastic/elasticsearch/lib/Transport';
} from '@opensearch-project/opensearch/lib/Transport';

/**
* Client used to query the opensearch cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import type { TransportRequestOptions } from '@opensearch-project/opensearch/lib/Transport';
import { get } from 'lodash';
import { set } from '@elastic/safer-lodash-set';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from './saved_objects_service.test.mocks';
import { BehaviorSubject } from 'rxjs';
import { ByteSizeValue } from '@osd/config-schema';
import { errors as opensearchErrors } from '@elastic/elasticsearch';
import { errors as opensearchErrors } from '@opensearch-project/opensearch';

import { SavedObjectsService } from './saved_objects_service';
import { mockCoreContext } from '../core_context.mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { errors as opensearchErrors } from '@elastic/elasticsearch';
import { errors as opensearchErrors } from '@opensearch-project/opensearch';
import { opensearchClientMock } from '../../../opensearch/client/mocks';
import { decorateOpenSearchError } from './decorate_opensearch_error';
import { SavedObjectsErrorHelpers } from './errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { errors as opensearchErrors } from '@elastic/elasticsearch';
import { errors as opensearchErrors } from '@opensearch-project/opensearch';
import { get } from 'lodash';

const responseErrors = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import type { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import type { TransportRequestOptions } from '@opensearch-project/opensearch/lib/Transport';

import { OpenSearchClient } from '../../../opensearch/';
import { retryCallCluster } from '../../../opensearch/client/retry_call_cluster';
Expand Down
12 changes: 6 additions & 6 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```ts

import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';
import { ApiResponse } from '@opensearch-project/opensearch/lib/Transport';
import Boom from '@hapi/boom';
import { BulkIndexDocumentsParams } from 'elasticsearch';
import { CatAliasesParams } from 'elasticsearch';
Expand All @@ -23,7 +23,7 @@ import { CatThreadPoolParams } from 'elasticsearch';
import { ClearScrollParams } from 'elasticsearch';
import { CliArgs } from '@osd/config';
import { Client } from 'elasticsearch';
import { ClientOptions } from '@elastic/elasticsearch';
import { ClientOptions } from '@opensearch-project/opensearch';
import { ClusterAllocationExplainParams } from 'elasticsearch';
import { ClusterGetSettingsParams } from 'elasticsearch';
import { ClusterHealthParams } from 'elasticsearch';
Expand Down Expand Up @@ -100,7 +100,7 @@ import { IngestDeletePipelineParams } from 'elasticsearch';
import { IngestGetPipelineParams } from 'elasticsearch';
import { IngestPutPipelineParams } from 'elasticsearch';
import { IngestSimulateParams } from 'elasticsearch';
import { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { KibanaClient } from '@opensearch-project/opensearch/api/kibana';
import { Logger } from '@osd/logging';
import { LoggerFactory } from '@osd/logging';
import { LogLevel } from '@osd/logging';
Expand Down Expand Up @@ -155,9 +155,9 @@ import { TasksCancelParams } from 'elasticsearch';
import { TasksGetParams } from 'elasticsearch';
import { TasksListParams } from 'elasticsearch';
import { TermvectorsParams } from 'elasticsearch';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestOptions } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestParams } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';
import { Type } from '@osd/config-schema';
import { TypeOf } from '@osd/config-schema';
import { UpdateDocumentByQueryParams } from 'elasticsearch';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/opensearch_search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/
import { SearchResponse } from 'elasticsearch';
import { Search } from '@elastic/elasticsearch/api/requestParams';
import { Search } from '@opensearch-project/opensearch/api/requestParams';
import { IOpenSearchDashboardsSearchRequest, IOpenSearchDashboardsSearchResponse } from '../types';

export const OPENSEARCH_SEARCH_STRATEGY = 'opensearch';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

import { BehaviorSubject } from 'rxjs';
import { ApiResponse } from '@elastic/elasticsearch';
import { ApiResponse } from '@opensearch-project/opensearch';
import { SearchResponse } from 'elasticsearch';
import { FetchHandlers, SearchRequest } from '../fetch';

Expand Down
14 changes: 7 additions & 7 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { $Values } from '@osd/utility-types';
import { Action } from 'history';
import { ApiResponse } from '@elastic/elasticsearch';
import { ApiResponse as ApiResponse_2 } from '@elastic/elasticsearch/lib/Transport';
import { ApiResponse } from '@opensearch-project/opensearch';
import { ApiResponse as ApiResponse_2 } from '@opensearch-project/opensearch/lib/Transport';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { Assign } from '@osd/utility-types';
import { BehaviorSubject } from 'rxjs';
Expand Down Expand Up @@ -35,7 +35,7 @@ import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public';
import { ISearchSource as ISearchSource_2 } from 'src/plugins/data/public';
import { IStorageWrapper } from 'src/plugins/opensearch_dashboards_utils/public';
import { IUiSettingsClient } from 'src/core/public';
import { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { KibanaClient } from '@opensearch-project/opensearch/api/kibana';
import { Location } from 'history';
import { LocationDescriptorObject } from 'history';
import { Logger } from '@osd/logging';
Expand Down Expand Up @@ -66,14 +66,14 @@ import { SavedObject } from 'src/core/server';
import { SavedObject as SavedObject_2 } from 'src/core/public';
import { SavedObjectReference as SavedObjectReference_2 } from 'src/core/types';
import { SavedObjectsClientContract } from 'src/core/public';
import { Search } from '@elastic/elasticsearch/api/requestParams';
import { Search } from '@opensearch-project/opensearch/api/requestParams';
import { SearchResponse } from 'elasticsearch';
import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/common';
import { ToastInputFields } from 'src/core/public/notifications';
import { ToastsSetup } from 'opensearch-dashboards/public';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestOptions } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestParams } from '@opensearch-project/opensearch/lib/Transport';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';
import { TypeOf } from '@osd/config-schema';
import { UiActionsSetup } from 'src/plugins/ui_actions/public';
import { UiActionsStart } from 'src/plugins/ui_actions/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { first } from 'rxjs/operators';
import { SharedGlobalConfig, Logger } from 'opensearch-dashboards/server';
import { SearchResponse } from 'elasticsearch';
import { Observable } from 'rxjs';
import { ApiResponse } from '@elastic/elasticsearch';
import { ApiResponse } from '@opensearch-project/opensearch';
import { SearchUsage } from '../collectors/usage';
import { toSnakeCase } from './to_snake_case';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport';

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/routes/call_msearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { ApiResponse } from '@elastic/elasticsearch';
import { ApiResponse } from '@opensearch-project/opensearch';
import { SearchResponse } from 'elasticsearch';
import { IUiSettingsClient, IScopedClusterClient, SharedGlobalConfig } from 'src/core/server';

Expand Down
Loading

0 comments on commit bf366da

Please sign in to comment.