Skip to content

Commit

Permalink
shim WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Sep 11, 2019
1 parent 1dc5f3d commit a6540f5
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
29 changes: 26 additions & 3 deletions x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import { i18n } from '@kbn/i18n';
import JoiNamespace from 'joi';
import { resolve } from 'path';

import { getConfigSchema, initServerWithKibana } from './server/kibana.index';
import { PluginInitializerContext } from 'src/core/server';
import KbnServer from 'src/legacy/server/kbn_server';
import { Observable } from 'rxjs';
import { getConfigSchema } from './server/kibana.index';
import { savedObjectMappings } from './server/saved_objects';
import { plugin } from './server/new_platform_index';

const APP_ID = 'infra';
const logsSampleDataLinkLabel = i18n.translate('xpack.infra.sampleDataLinkLabel', {
Expand Down Expand Up @@ -71,7 +74,27 @@ export function infra(kibana: any) {
return getConfigSchema(Joi);
},
init(server: any) {
initServerWithKibana(server);
// convert hapi instance to KbnServer
// `kbnServer.server` is the same hapi instance
// `kbnServer.newPlatform` has important values
const kbnServer = (server as unknown) as KbnServer;
const { core } = kbnServer.newPlatform.setup;

const getConfig$ = <T>() =>
new Observable<T>(observer => {
observer.next(server.config().get('xpack.infra'));
});

const initContext = {
config: {
create: getConfig$,
createIfExists: getConfig$,
},
} as PluginInitializerContext;

plugin(initContext).setup(core);

// NP_TODO: How do we move this to new platform?
server.addAppLinksToSampleDataset('logs', [
{
path: `/app/${APP_ID}#/logs`,
Expand Down
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/infra/server/kibana.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import JoiNamespace from 'joi';
import { initInfraServer } from './infra_server';
import { compose } from './lib/compose/kibana';
import { UsageCollector } from './usage/usage_collector';
import { InternalCoreSetup } from '../../../../../src/core/server';

export interface KbnServer extends Server {
usage: any;
}

export const initServerWithKibana = (kbnServer: KbnServer) => {
export const initServerWithKibana = (core: InternalCoreSetup) => {
const libs = compose(kbnServer);
initInfraServer(libs);

// NP_TODO how do we replace this?
kbnServer.expose(
'defineInternalSourceConfiguration',
libs.sources.defineInternalSourceConfiguration.bind(libs.sources)
Expand Down
15 changes: 15 additions & 0 deletions x-pack/legacy/plugins/infra/server/new_platform_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from 'src/core/server';
import { InfraServerPlugin, config, InfraConfig } from './new_platform_plugin';

// NP_TODO: kibana NP needs "config" to be exported from here, I think?
export { config, InfraConfig };

export function plugin(context: PluginInitializerContext) {
return new InfraServerPlugin(context);
}
52 changes: 52 additions & 0 deletions x-pack/legacy/plugins/infra/server/new_platform_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { InternalCoreSetup, PluginInitializerContext } from 'src/core/server';
import { Observable } from 'rxjs';
import { schema, TypeOf } from '@kbn/config-schema';
import { initServerWithKibana } from './kibana.index';

export const config = {
schema: schema.object({
enabled: schema.boolean(),
query: schema.object({
partitionSize: schema.maybe(schema.number()),
partitionFactor: schema.maybe(schema.number()),
}),
}),
};

export type InfraConfig = TypeOf<typeof config.schema>;

const DEFAULT_CONFIG: InfraConfig = {
enabled: true,
query: {
partitionSize: 75,
partitionFactor: 1.2,
},
};

export class InfraServerPlugin {
public config$: Observable<InfraConfig>;
public config: InfraConfig = DEFAULT_CONFIG;

constructor(context: PluginInitializerContext) {
this.config$ = context.config.create<InfraConfig>();
this.config$.subscribe(configValue => {
this.config = {
...DEFAULT_CONFIG,
enabled: configValue.enabled,
query: {
...DEFAULT_CONFIG.query,
...configValue.query,
},
};
});
}

setup(core: InternalCoreSetup) {
initServerWithKibana(core);
}
}

0 comments on commit a6540f5

Please sign in to comment.