[Logs + Metrics UI] Fix incomplete config schema and async usa… (#58576)

This fixes the configuration file schema of the infra plugin in the new platform shim.
This commit is contained in:
Felix Stürmer 2020-02-26 12:47:18 +01:00 committed by GitHub
parent a3ca2d200e
commit 4bb6c08e26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 30 deletions

View file

@ -75,7 +75,7 @@ export function infra(kibana: any) {
config(Joi: typeof JoiNamespace) {
return getConfigSchema(Joi);
},
init(legacyServer: any) {
async init(legacyServer: any) {
const { newPlatform } = legacyServer as KbnServer;
const { core, plugins } = newPlatform.setup;
@ -98,7 +98,7 @@ export function infra(kibana: any) {
};
const infraPluginInstance = plugin(initContext);
infraPluginInstance.setup(core, pluginDeps);
await infraPluginInstance.setup(core, pluginDeps);
// NP_TODO: EVERYTHING BELOW HERE IS LEGACY

View file

@ -6,6 +6,8 @@
import { CoreSetup, PluginInitializerContext } from 'src/core/server';
import { i18n } from '@kbn/i18n';
import { Server } from 'hapi';
import { Observable } from 'rxjs';
import { shareReplay, take } from 'rxjs/operators';
import { InfraConfig } from '../../../../plugins/infra/server';
import { initInfraServer } from './infra_server';
import { InfraBackendLibs, InfraDomainLibs } from './lib/infra_types';
@ -42,30 +44,12 @@ export interface InfraPluginSetup {
) => void;
}
const DEFAULT_CONFIG: InfraConfig = {
enabled: true,
query: {
partitionSize: 75,
partitionFactor: 1.2,
},
};
export class InfraServerPlugin {
public config: InfraConfig = DEFAULT_CONFIG;
private config$: Observable<InfraConfig>;
public libs: InfraBackendLibs | undefined;
constructor(context: PluginInitializerContext) {
const config$ = context.config.create<InfraConfig>();
config$.subscribe(configValue => {
this.config = {
...DEFAULT_CONFIG,
enabled: configValue.enabled,
query: {
...DEFAULT_CONFIG.query,
...configValue.query,
},
};
});
this.config$ = context.config.create<InfraConfig>().pipe(shareReplay(1));
}
getLibs() {
@ -75,10 +59,11 @@ export class InfraServerPlugin {
return this.libs;
}
setup(core: CoreSetup, plugins: InfraServerPluginDeps) {
const framework = new KibanaFramework(core, this.config, plugins);
async setup(core: CoreSetup, plugins: InfraServerPluginDeps) {
const config = await this.config$.pipe(take(1)).toPromise();
const framework = new KibanaFramework(core, config, plugins);
const sources = new InfraSources({
config: this.config,
config,
});
const sourceStatus = new InfraSourceStatus(
new InfraElasticsearchSourceStatusAdapter(framework),
@ -102,7 +87,7 @@ export class InfraServerPlugin {
};
this.libs = {
configuration: this.config,
configuration: config,
framework,
logEntryCategoriesAnalysis,
logEntryRateAnalysis,

View file

@ -2,5 +2,6 @@
"id": "infra",
"version": "8.0.0",
"kibanaVersion": "kibana",
"server": true
"server": true,
"configPath": ["xpack", "infra"]
}

View file

@ -10,11 +10,31 @@ import { InfraPlugin } from './plugin';
export const config = {
schema: schema.object({
enabled: schema.maybe(schema.boolean()),
enabled: schema.boolean({ defaultValue: true }),
query: schema.object({
partitionSize: schema.maybe(schema.number()),
partitionFactor: schema.maybe(schema.number()),
partitionSize: schema.number({ defaultValue: 75 }),
partitionFactor: schema.number({ defaultValue: 1.2 }),
}),
sources: schema.maybe(
schema.object({
default: schema.maybe(
schema.object({
logAlias: schema.maybe(schema.string()),
metricAlias: schema.maybe(schema.string()),
fields: schema.maybe(
schema.object({
timestamp: schema.maybe(schema.string()),
message: schema.maybe(schema.arrayOf(schema.string())),
tiebreaker: schema.maybe(schema.string()),
host: schema.maybe(schema.string()),
container: schema.maybe(schema.string()),
pod: schema.maybe(schema.string()),
})
),
})
),
})
),
}),
};