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

[New platform] Expose NP core services and plugins contracts to the legacy server #32468

Merged
merged 10 commits into from
Mar 7, 2019
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function (kibana) {
}

const config = server.config();
const legacyEsConfig = await server.core.elasticsearch.legacy.config$.pipe(first()).toPromise();
const legacyEsConfig = await server.newPlatform.start.core.elasticsearch.legacy.config$.pipe(first()).toPromise();
const proxyConfigCollection = new ProxyConfigCollection(options.proxyConfig);
const proxyPathFilters = options.proxyFilter.map(str => new RegExp(str));

Expand Down
8 changes: 4 additions & 4 deletions src/legacy/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default function (kibana) {
// value from all observables here to be able to synchronously return and create
// cluster clients afterwards.
const [esConfig, adminCluster, dataCluster] = await combineLatest(
server.core.elasticsearch.legacy.config$,
server.core.elasticsearch.adminClient$,
server.core.elasticsearch.dataClient$
server.newPlatform.start.core.elasticsearch.legacy.config$,
server.newPlatform.start.core.elasticsearch.adminClient$,
server.newPlatform.start.core.elasticsearch.dataClient$
).pipe(
first(),
map(([config, adminClusterClient, dataClusterClient]) => [
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function (kibana) {
// We fill all the missing properties in the `clientConfig` using the default
// Elasticsearch config so that we don't depend on default values set and
// controlled by underlying Elasticsearch JS client.
const cluster = new Cluster(server.core.elasticsearch.createClient(name, {
const cluster = new Cluster(server.newPlatform.start.core.elasticsearch.createClient(name, {
...esConfig,
...clientConfig,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ describe('getEsShardTimeout', () => {
it('should return the elasticsearch.shardTimeout', async () => {
const req = {
server: {
core: {
elasticsearch: { legacy: { config$: of({ shardTimeout: moment.duration(12345) }) } }
newPlatform: {
start: {
core: {
elasticsearch: { legacy: { config$: of({ shardTimeout: moment.duration(12345) }) } }
}
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { first, map } from 'rxjs/operators';

export async function getEsShardTimeout(req) {
return await req.server.core.elasticsearch.legacy.config$.pipe(
return await req.server.newPlatform.start.core.elasticsearch.legacy.config$.pipe(
first(),
map(config => config.shardTimeout.asMilliseconds())
).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export default function () {
})
}
},
core: {
elasticsearch: {
legacy: { config$: of({ shardTimeout: moment.duration(30000) }) }
newPlatform: {
start: {
core: {
elasticsearch: {
legacy: { config$: of({ shardTimeout: moment.duration(30000) }) }
}
}
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default new Datasource('es', {
});
}

const esShardTimeout = await tlConfig.server.core.elasticsearch.legacy.config$.pipe(
const esShardTimeout = await tlConfig.server.newPlatform.start.core.elasticsearch.legacy.config$.pipe(
first(),
map(config => config.shardTimeout.asMilliseconds())
).toPromise();
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/config/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default async function (kbnServer, server, config) {
});

const unusedKeys = await getUnusedConfigKeys(
kbnServer.core.handledConfigPaths,
kbnServer.newPlatform.params.handledConfigPaths,
kbnServer.plugins,
kbnServer.disabledPluginSpecs,
kbnServer.settings,
Expand Down
4 changes: 3 additions & 1 deletion src/legacy/server/config/complete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ describe('server/config completeMixin()', function () {
};

const kbnServer = {
core: { handledConfigPaths: [] },
newPlatform: {
params: { handledConfigPaths: [] }
},
settings,
server,
config,
Expand Down
5 changes: 3 additions & 2 deletions src/legacy/server/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { Server } from 'hapi';
import KbnServer from '../kbn_server';

/**
* Exposes `kbnServer.core` through Hapi API.
* Exposes `kbnServer.newPlatform` through Hapi API.
* @param kbnServer KbnServer singleton instance.
* @param server Hapi server instance to expose `core` on.
*/
export function coreMixin(kbnServer: KbnServer, server: Server) {
server.decorate('server', 'core', kbnServer.core);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to avoid confusion I removed this escape hatch, let me know if we want to keep it and revert the commit

// we suppress type error because hapi expect a function here not an object
server.decorate('server', 'newPlatform', kbnServer.newPlatform as any);
}
2 changes: 1 addition & 1 deletion src/legacy/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { setupBasePathProvider } from './setup_base_path_provider';
import { setupXsrf } from './xsrf';

export default async function (kbnServer, server, config) {
kbnServer.server = new Hapi.Server(kbnServer.core.serverOptions);
kbnServer.server = new Hapi.Server(kbnServer.newPlatform.params.serverOptions);
server = kbnServer.server;

setupBasePathProvider(server, config);
Expand Down
20 changes: 18 additions & 2 deletions src/legacy/server/kbn_server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import { Server } from 'hapi';

import { ConfigService } from '../../core/server/config';
import { ElasticsearchServiceStart } from '../../core/server/elasticsearch';
import { HttpServerInfo } from '../../core/server/http/';
import { PluginsServiceStart } from '../../core/server/plugins/plugins_service';
import { ApmOssPlugin } from '../core_plugins/apm_oss';
import { CallClusterWithRequest, ElasticsearchPlugin } from '../core_plugins/elasticsearch';

Expand Down Expand Up @@ -53,9 +57,21 @@ declare module 'hapi' {
}

type KbnMixinFunc = (kbnServer: KbnServer, server: Server, config: any) => Promise<any> | void;

type Unpromise<T> = T extends Promise<infer U> ? U : T;
export default class KbnServer {
public readonly core: any;
public readonly newPlatform: {
start: {
core: {
elasticsearch: ElasticsearchServiceStart;
};
plugins: PluginsServiceStart;
};
stop: null;
params: {
serverOptions: HttpServerInfo;
handledConfigPaths: Unpromise<ReturnType<ConfigService['getUsedPaths']>>;
};
};
public server: Server;
public inject: Server['inject'];

Expand Down
16 changes: 15 additions & 1 deletion src/legacy/server/kbn_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ export default class KbnServer {
this.rootDir = rootDir;
this.settings = settings || {};

this.core = core;
const { plugins, elasticsearch, serverOptions, handledConfigPaths } = core;

this.newPlatform = {
start: {
core: {
elasticsearch,
},
plugins,
},
stop: null,
params: {
serverOptions,
handledConfigPaths,
},
};

this.ready = constant(this.mixin(
Plugins.waitForInitSetupMixin,
Expand Down