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

expose es config on es setup contract #73055

Merged
merged 3 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- 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; [config$](./kibana-plugin-core-server.elasticsearchservicesetup.config_.md)

## ElasticsearchServiceSetup.config$ property

> Warning: This API is now obsolete.
>
> this will be removed in a later version.
>

Provide direct access to the current elasticsearch configuration.

<b>Signature:</b>

```typescript
readonly config$: Observable<ElasticsearchConfig>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export interface ElasticsearchServiceSetup

| Property | Type | Description |
| --- | --- | --- |
| [config$](./kibana-plugin-core-server.elasticsearchservicesetup.config_.md) | <code>Observable&lt;ElasticsearchConfig&gt;</code> | Provide direct access to the current elasticsearch configuration. |
| [legacy](./kibana-plugin-core-server.elasticsearchservicesetup.legacy.md) | <code>{</code><br/><code> readonly createClient: (type: string, clientConfig?: Partial&lt;LegacyElasticsearchClientConfig&gt;) =&gt; ILegacyCustomClusterClient;</code><br/><code> readonly client: ILegacyClusterClient;</code><br/><code> }</code> | |

8 changes: 5 additions & 3 deletions src/core/server/elasticsearch/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';
import { ILegacyClusterClient, ILegacyCustomClusterClient } from './legacy';
import {
elasticsearchClientMock,
Expand All @@ -32,13 +32,14 @@ import { NodesVersionCompatibility } from './version_check/ensure_es_version';
import { ServiceStatus, ServiceStatusLevels } from '../status';

interface MockedElasticSearchServiceSetup {
config$: Observable<ElasticsearchConfig>;
legacy: {
createClient: jest.Mock<ILegacyCustomClusterClient, any>;
client: jest.Mocked<ILegacyClusterClient>;
};
}

type MockedElasticSearchServiceStart = MockedElasticSearchServiceSetup;
type MockedElasticSearchServiceStart = Omit<MockedElasticSearchServiceSetup, 'config$'>;

interface MockedInternalElasticSearchServiceStart extends MockedElasticSearchServiceStart {
client: ClusterClientMock;
Expand All @@ -47,6 +48,7 @@ interface MockedInternalElasticSearchServiceStart extends MockedElasticSearchSer

const createSetupContractMock = () => {
const setupContract: MockedElasticSearchServiceSetup = {
config$: new BehaviorSubject({} as ElasticsearchConfig),
legacy: {
createClient: jest.fn(),
client: legacyClientMock.createClusterClient(),
Expand Down Expand Up @@ -92,6 +94,7 @@ type MockedInternalElasticSearchServiceSetup = jest.Mocked<
>;
const createInternalSetupContractMock = () => {
const setupContract: MockedInternalElasticSearchServiceSetup = {
config$: new BehaviorSubject({} as ElasticsearchConfig),
esNodesCompatibility$: new BehaviorSubject<NodesVersionCompatibility>({
isCompatible: true,
incompatibleNodes: [],
Expand All @@ -103,7 +106,6 @@ const createInternalSetupContractMock = () => {
summary: 'Elasticsearch is available',
}),
legacy: {
config$: new BehaviorSubject({} as ElasticsearchConfig),
...createSetupContractMock().legacy,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ beforeEach(() => {
afterEach(() => jest.clearAllMocks());

describe('#setup', () => {
it('returns legacy Elasticsearch config as a part of the contract', async () => {
it('returns Elasticsearch config as a part of the contract', async () => {
const setupContract = await elasticsearchService.setup(setupDeps);

await expect(setupContract.legacy.config$.pipe(first()).toPromise()).resolves.toBeInstanceOf(
await expect(setupContract.config$.pipe(first()).toPromise()).resolves.toBeInstanceOf(
ElasticsearchConfig
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/elasticsearch_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export class ElasticsearchService
};

return {
config$: this.config$,
legacy: {
config$: this.config$,
client: this.legacyClient,
createClient: this.createLegacyCustomClient,
},
Expand Down
16 changes: 9 additions & 7 deletions src/core/server/elasticsearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ import { ServiceStatus } from '../status';
* @public
*/
export interface ElasticsearchServiceSetup {
/**
* Provide direct access to the current elasticsearch configuration.
*
* @deprecated this will be removed in a later version.
*/
readonly config$: Observable<ElasticsearchConfig>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • I could have kept legacy.config$ and expose it on the public contract instead, but now that this is going to be consumed by KP plugins, I thought it was better on top level. Also, that would allow to totally get rid of esSetup.legacy when we remove the legacy client

  • flagged it as deprecated. Not sure if it's the right move.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to keep it under legacy namespace to make it even more explicit that we are going to remove it. @joshdover any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecation tags are easy to miss (they're really only present in intellisense right now since we don't have any linter warnings for using deprecated APIs). Given that, I also prefer keeping it under the legacy namespace to make it clear that this will be removed in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Related, this new feature in TS v4 / VSCode will make deprecated APIs more apparent: https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-rc/#deprecated-support


/**
* @deprecated
* Use {@link ElasticsearchServiceStart.legacy} instead.
*
* */
*/
legacy: {
/**
* @deprecated
Expand Down Expand Up @@ -82,11 +88,7 @@ export interface ElasticsearchServiceSetup {
}

/** @internal */
export interface InternalElasticsearchServiceSetup {
// Required for the BWC with the legacy Kibana only.
readonly legacy: ElasticsearchServiceSetup['legacy'] & {
readonly config$: Observable<ElasticsearchConfig>;
};
export interface InternalElasticsearchServiceSetup extends ElasticsearchServiceSetup {
esNodesCompatibility$: Observable<NodesVersionCompatibility>;
status$: Observable<ServiceStatus<ElasticsearchStatusMeta>>;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export class LegacyService implements CoreService {
capabilities: setupDeps.core.capabilities,
context: setupDeps.core.context,
elasticsearch: {
config$: setupDeps.core.elasticsearch.config$,
legacy: {
client: setupDeps.core.elasticsearch.legacy.client,
createClient: setupDeps.core.elasticsearch.legacy.createClient,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
createContextContainer: deps.context.createContextContainer,
},
elasticsearch: {
config$: deps.elasticsearch.config$,
legacy: deps.elasticsearch.legacy,
},
http: {
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ export class ElasticsearchConfig {

// @public (undocumented)
export interface ElasticsearchServiceSetup {
// @deprecated
readonly config$: Observable<ElasticsearchConfig>;
// @deprecated (undocumented)
legacy: {
readonly createClient: (type: string, clientConfig?: Partial<LegacyElasticsearchClientConfig>) => ILegacyCustomClusterClient;
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/console_legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function (kibana: any) {
id: 'console_legacy',

async init(server: any) {
_legacyEsConfig = await server.newPlatform.__internals.elasticsearch.legacy.config$
_legacyEsConfig = await server.newPlatform.__internals.elasticsearch.config$
.pipe(first())
.toPromise();
},
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (kibana) {
const adminCluster = new Cluster(client);
const dataCluster = new Cluster(client);

const esConfig = await server.newPlatform.__internals.elasticsearch.legacy.config$
const esConfig = await server.newPlatform.__internals.elasticsearch.config$
.pipe(first())
.toPromise();

Expand Down