Skip to content

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchServiceSetup](./kibana-plugin-core-server.elasticsearchservicesetup.md) &gt; [legacy](./kibana-plugin-core-server.elasticsearchservicesetup.legacy.md)

## ElasticsearchServiceSetup.legacy property

<b>Signature:</b>

```typescript
legacy: {
readonly createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ICustomClusterClient;
readonly client: IClusterClient;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ export interface ElasticsearchServiceSetup

| Property | Type | Description |
| --- | --- | --- |
| [adminClient](./kibana-plugin-core-server.elasticsearchservicesetup.adminclient.md) | <code>IClusterClient</code> | |
| [createClient](./kibana-plugin-core-server.elasticsearchservicesetup.createclient.md) | <code>(type: string, clientConfig?: Partial&lt;ElasticsearchClientConfig&gt;) =&gt; ICustomClusterClient</code> | |
| [dataClient](./kibana-plugin-core-server.elasticsearchservicesetup.dataclient.md) | <code>IClusterClient</code> | |
| [legacy](./kibana-plugin-core-server.elasticsearchservicesetup.legacy.md) | <code>{</code><br/><code> readonly createClient: (type: string, clientConfig?: Partial&lt;ElasticsearchClientConfig&gt;) =&gt; ICustomClusterClient;</code><br/><code> readonly client: IClusterClient;</code><br/><code> }</code> | |

2 changes: 1 addition & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [PluginConfigDescriptor](./kibana-plugin-core-server.pluginconfigdescriptor.md) | Describes a plugin configuration properties. |
| [PluginInitializerContext](./kibana-plugin-core-server.plugininitializercontext.md) | Context that's available to plugins during initialization stage. |
| [PluginManifest](./kibana-plugin-core-server.pluginmanifest.md) | Describes the set of required and optional properties plugin can define in its mandatory JSON manifest file. |
| [RequestHandlerContext](./kibana-plugin-core-server.requesthandlercontext.md) | Plugin specific context passed to a route handler.<!-- -->Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.dataClient](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [elasticsearch.adminClient](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch admin client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request |
| [RequestHandlerContext](./kibana-plugin-core-server.requesthandlercontext.md) | Plugin specific context passed to a route handler.<!-- -->Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.legacy.client](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request |
| [RouteConfig](./kibana-plugin-core-server.routeconfig.md) | Route specific configuration. |
| [RouteConfigOptions](./kibana-plugin-core-server.routeconfigoptions.md) | Additional route options. |
| [RouteConfigOptionsBody](./kibana-plugin-core-server.routeconfigoptionsbody.md) | Additional body options for a route |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Plugin specific context passed to a route handler.

Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.dataClient](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [elasticsearch.adminClient](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch admin client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request
Provides the following clients and services: - [savedObjects.client](./kibana-plugin-core-server.savedobjectsclient.md) - Saved Objects client which uses the credentials of the incoming request - [savedObjects.typeRegistry](./kibana-plugin-core-server.isavedobjecttyperegistry.md) - Type registry containing all the registered types. - [elasticsearch.legacy.client](./kibana-plugin-core-server.scopedclusterclient.md) - Elasticsearch data client which uses the credentials of the incoming request - [uiSettings.client](./kibana-plugin-core-server.iuisettingsclient.md) - uiSettings client which uses the credentials of the incoming request

<b>Signature:</b>

Expand Down
47 changes: 17 additions & 30 deletions src/core/server/elasticsearch/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ import { IClusterClient, ICustomClusterClient } from './cluster_client';
import { IScopedClusterClient } from './scoped_cluster_client';
import { ElasticsearchConfig } from './elasticsearch_config';
import { ElasticsearchService } from './elasticsearch_service';
import {
InternalElasticsearchServiceSetup,
ElasticsearchServiceSetup,
ElasticsearchServiceStart,
ElasticsearchStatusMeta,
} from './types';
import { InternalElasticsearchServiceSetup, ElasticsearchStatusMeta } from './types';
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
import { ServiceStatus, ServiceStatusLevels } from '../status';

Expand All @@ -51,32 +46,26 @@ function createClusterClientMock() {
return client;
}

type MockedElasticSearchServiceSetup = jest.Mocked<
ElasticsearchServiceSetup & {
adminClient: jest.Mocked<IClusterClient>;
dataClient: jest.Mocked<IClusterClient>;
}
>;
interface MockedElasticSearchServiceSetup {
legacy: {
createClient: jest.Mock<ICustomClusterClient, any>;
client: jest.Mocked<IClusterClient>;
};
}

const createSetupContractMock = () => {
const setupContract: MockedElasticSearchServiceSetup = {
createClient: jest.fn(),
adminClient: createClusterClientMock(),
dataClient: createClusterClientMock(),
legacy: {
createClient: jest.fn(),
client: createClusterClientMock(),
},
};
setupContract.createClient.mockReturnValue(createCustomClusterClientMock());
setupContract.adminClient.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.dataClient.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock());
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
return setupContract;
};

type MockedElasticSearchServiceStart = {
legacy: jest.Mocked<ElasticsearchServiceStart['legacy']>;
} & {
legacy: {
client: jest.Mocked<IClusterClient>;
};
};
type MockedElasticSearchServiceStart = MockedElasticSearchServiceSetup;

const createStartContractMock = () => {
const startContract: MockedElasticSearchServiceStart = {
Expand All @@ -92,13 +81,11 @@ const createStartContractMock = () => {

type MockedInternalElasticSearchServiceSetup = jest.Mocked<
InternalElasticsearchServiceSetup & {
adminClient: jest.Mocked<IClusterClient>;
dataClient: jest.Mocked<IClusterClient>;
legacy: { client: jest.Mocked<IClusterClient> };
}
>;
const createInternalSetupContractMock = () => {
const setupContract: MockedInternalElasticSearchServiceSetup = {
...createSetupContractMock(),
esNodesCompatibility$: new BehaviorSubject<NodesVersionCompatibility>({
isCompatible: true,
incompatibleNodes: [],
Expand All @@ -111,10 +98,10 @@ const createInternalSetupContractMock = () => {
}),
legacy: {
config$: new BehaviorSubject({} as ElasticsearchConfig),
...createSetupContractMock().legacy,
},
};
setupContract.adminClient.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.dataClient.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
return setupContract;
};

Expand Down
80 changes: 29 additions & 51 deletions src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,16 @@ describe('#setup', () => {
);
});

it('returns data and admin client as a part of the contract', async () => {
const mockAdminClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockDataClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
it('returns elasticsearch client as a part of the contract', async () => {
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

const setupContract = await elasticsearchService.setup(deps);
const client = setupContract.legacy.client;

const adminClient = setupContract.adminClient;
const dataClient = setupContract.dataClient;

expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
await adminClient.callAsInternalUser('any');
expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);

expect(mockDataClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
await dataClient.callAsInternalUser('any');
expect(mockDataClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
await client.callAsInternalUser('any');
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
});

describe('#createClient', () => {
Expand All @@ -103,7 +94,7 @@ describe('#setup', () => {
MockClusterClient.mockImplementation(() => mockClusterClientInstance);

const customConfig = { logQueries: true };
const clusterClient = setupContract.createClient('some-custom-type', customConfig);
const clusterClient = setupContract.legacy.createClient('some-custom-type', customConfig);

expect(clusterClient).toBe(mockClusterClientInstance);

Expand All @@ -124,7 +115,7 @@ describe('#setup', () => {
logQueries: true,
ssl: { certificate: 'certificate-value' },
};
setupContract.createClient('some-custom-type', customConfig);
setupContract.legacy.createClient('some-custom-type', customConfig);

const config = MockClusterClient.mock.calls[0][0];
expect(config).toMatchInlineSnapshot(`
Expand All @@ -149,7 +140,7 @@ describe('#setup', () => {
// reset all mocks called during setup phase
MockClusterClient.mockClear();

setupContract.createClient('another-type');
setupContract.legacy.createClient('another-type');

const config = MockClusterClient.mock.calls[0][0];
expect(config).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -195,7 +186,7 @@ describe('#setup', () => {
logQueries: true,
ssl: { certificate: 'certificate-value' },
};
setupContract.createClient('some-custom-type', customConfig);
setupContract.legacy.createClient('some-custom-type', customConfig);

const config = MockClusterClient.mock.calls[0][0];
expect(config).toMatchInlineSnapshot(`
Expand All @@ -218,79 +209,66 @@ describe('#setup', () => {
});

it('esNodeVersionCompatibility$ only starts polling when subscribed to', async (done) => {
const mockAdminClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockDataClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
const clusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(() => clusterClientInstance);

mockAdminClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
clusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());

const setupContract = await elasticsearchService.setup(deps);
await delay(10);

expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
expect(clusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
setupContract.esNodesCompatibility$.subscribe(() => {
expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
expect(clusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
done();
});
});

it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async (done) => {
const mockAdminClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockDataClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

mockAdminClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
mockClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());

const setupContract = await elasticsearchService.setup(deps);

expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(0);
const sub = setupContract.esNodesCompatibility$.subscribe(async () => {
sub.unsubscribe();
await delay(100);
expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
done();
});
});
});

describe('#stop', () => {
it('stops both admin and data clients', async () => {
const mockAdminClusterClientInstance = { close: jest.fn() };
const mockDataClusterClientInstance = { close: jest.fn() };
MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
const mockClusterClientInstance = { close: jest.fn() };
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

await elasticsearchService.setup(deps);
await elasticsearchService.stop();

expect(mockAdminClusterClientInstance.close).toHaveBeenCalledTimes(1);
expect(mockDataClusterClientInstance.close).toHaveBeenCalledTimes(1);
expect(mockClusterClientInstance.close).toHaveBeenCalledTimes(1);
});

it('stops pollEsNodeVersions even if there are active subscriptions', async (done) => {
expect.assertions(2);
const mockAdminClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();
const mockDataClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();
const mockClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();

MockClusterClient.mockImplementationOnce(
() => mockAdminClusterClientInstance
).mockImplementationOnce(() => mockDataClusterClientInstance);
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

mockAdminClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
mockClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());

const setupContract = await elasticsearchService.setup(deps);

setupContract.esNodesCompatibility$.subscribe(async () => {
expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);

await elasticsearchService.stop();
await delay(100);
expect(mockAdminClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
expect(mockClusterClientInstance.callAsInternalUser).toHaveBeenCalledTimes(1);
done();
});
});
Expand Down
Loading