mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Make core logging independent from the legacy Kibana. (#21831)
This commit is contained in:
parent
351cf92d36
commit
1f7fdbfe7c
24 changed files with 322 additions and 244 deletions
|
@ -31,7 +31,7 @@ process.env.kbnWorkerType = 'managr';
|
|||
export default class ClusterManager {
|
||||
static async create(opts = {}, settings = {}) {
|
||||
const transformedSettings = transformDeprecations(settings);
|
||||
const config = await Config.withDefaultSchema(transformedSettings);
|
||||
const config = Config.withDefaultSchema(transformedSettings);
|
||||
|
||||
const basePathProxy = opts.basePath
|
||||
? await configureBasePathProxy(config)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`correctly forwards log record. 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
"one",
|
||||
"two",
|
||||
],
|
||||
"message",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
],
|
||||
Array [
|
||||
"three",
|
||||
[Error: log error],
|
||||
2012-02-01T11:22:33.044Z,
|
||||
],
|
||||
]
|
||||
`;
|
|
@ -6,6 +6,40 @@ exports[`#get correctly handles paths that do not exist in legacy config. 2`] =
|
|||
|
||||
exports[`#get correctly handles paths that do not exist in legacy config. 3`] = `"Unknown schema key: one.three"`;
|
||||
|
||||
exports[`#get correctly handles silent logging config. 1`] = `
|
||||
Object {
|
||||
"appenders": Object {
|
||||
"default": Object {
|
||||
"kind": "legacy-appender",
|
||||
"legacyLoggingConfig": Object {
|
||||
"silent": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"root": Object {
|
||||
"level": "off",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`#get correctly handles verbose file logging config with json format. 1`] = `
|
||||
Object {
|
||||
"appenders": Object {
|
||||
"default": Object {
|
||||
"kind": "legacy-appender",
|
||||
"legacyLoggingConfig": Object {
|
||||
"dest": "/some/path.log",
|
||||
"json": true,
|
||||
"verbose": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"root": Object {
|
||||
"level": "all",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`#set correctly sets values for new platform config. 1`] = `
|
||||
Object {
|
||||
"plugins": Object {
|
||||
|
|
|
@ -29,17 +29,3 @@ test('correctly returns `newPlatformProxyListener`.', () => {
|
|||
const legacyKbnServer = new LegacyKbnServer(rawKbnServer);
|
||||
expect(legacyKbnServer.newPlatformProxyListener).toBe(rawKbnServer.newPlatform.proxyListener);
|
||||
});
|
||||
|
||||
test('correctly forwards log record.', () => {
|
||||
const rawKbnServer = {
|
||||
server: { log: jest.fn() },
|
||||
};
|
||||
|
||||
const legacyKbnServer = new LegacyKbnServer(rawKbnServer);
|
||||
|
||||
const timestamp = new Date(Date.UTC(2012, 1, 1, 11, 22, 33, 44));
|
||||
legacyKbnServer.log(['one', 'two'], 'message', timestamp);
|
||||
legacyKbnServer.log('three', new Error('log error'), timestamp);
|
||||
|
||||
expect(rawKbnServer.server.log.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -68,12 +68,7 @@ describe('#get', () => {
|
|||
test('correctly handles silent logging config.', () => {
|
||||
legacyConfigMock.rawData = new Map([['logging', { silent: true }]]);
|
||||
|
||||
expect(configAdapter.get('logging')).toEqual({
|
||||
appenders: {
|
||||
default: { kind: 'legacy-appender' },
|
||||
},
|
||||
root: { level: 'off' },
|
||||
});
|
||||
expect(configAdapter.get('logging')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('correctly handles verbose file logging config with json format.', () => {
|
||||
|
@ -81,12 +76,7 @@ describe('#get', () => {
|
|||
['logging', { verbose: true, json: true, dest: '/some/path.log' }],
|
||||
]);
|
||||
|
||||
expect(configAdapter.get('logging')).toEqual({
|
||||
appenders: {
|
||||
default: { kind: 'legacy-appender' },
|
||||
},
|
||||
root: { level: 'all' },
|
||||
});
|
||||
expect(configAdapter.get('logging')).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -31,14 +31,4 @@ export class LegacyKbnServer {
|
|||
get newPlatformProxyListener() {
|
||||
return this.rawKbnServer.newPlatform.proxyListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards log request to the legacy platform.
|
||||
* @param tags A string or array of strings used to briefly identify the event.
|
||||
* @param [data] Optional string or object to log with the event.
|
||||
* @param [timestamp] Timestamp value associated with the log record.
|
||||
*/
|
||||
public log(tags: string | string[], data?: string | Error, timestamp?: Date) {
|
||||
this.rawKbnServer.server.log(tags, data, timestamp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ export interface LegacyConfig {
|
|||
* Represents logging config supported by the legacy platform.
|
||||
*/
|
||||
interface LegacyLoggingConfig {
|
||||
silent: boolean;
|
||||
verbose: boolean;
|
||||
quiet: boolean;
|
||||
dest: string;
|
||||
json: boolean;
|
||||
silent?: boolean;
|
||||
verbose?: boolean;
|
||||
quiet?: boolean;
|
||||
dest?: string;
|
||||
json?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,9 @@ export class LegacyConfigToRawConfigAdapter implements RawConfig {
|
|||
|
||||
private static transformLogging(configValue: LegacyLoggingConfig) {
|
||||
const loggingConfig = {
|
||||
appenders: { default: { kind: 'legacy-appender' } },
|
||||
appenders: {
|
||||
default: { kind: 'legacy-appender', legacyLoggingConfig: configValue },
|
||||
},
|
||||
root: { level: 'info' },
|
||||
};
|
||||
|
||||
|
|
|
@ -3,94 +3,125 @@
|
|||
exports[`\`append()\` correctly pushes records to legacy platform. 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
Array [
|
||||
"trace",
|
||||
"context-1",
|
||||
],
|
||||
"message-1",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-1",
|
||||
"level": LogLevel {
|
||||
"id": "trace",
|
||||
"value": 7,
|
||||
},
|
||||
"message": "message-1",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"debug",
|
||||
"context-2",
|
||||
],
|
||||
"message-2",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-2",
|
||||
"level": LogLevel {
|
||||
"id": "debug",
|
||||
"value": 6,
|
||||
},
|
||||
"message": "message-2",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"info",
|
||||
"context-3",
|
||||
"sub-context-3",
|
||||
],
|
||||
"message-3",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-3.sub-context-3",
|
||||
"level": LogLevel {
|
||||
"id": "info",
|
||||
"value": 5,
|
||||
},
|
||||
"message": "message-3",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"warn",
|
||||
"context-4",
|
||||
"sub-context-4",
|
||||
],
|
||||
"message-4",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-4.sub-context-4",
|
||||
"level": LogLevel {
|
||||
"id": "warn",
|
||||
"value": 4,
|
||||
},
|
||||
"message": "message-4",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"error",
|
||||
"context-5",
|
||||
],
|
||||
[Error: Some Error],
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-5",
|
||||
"error": [Error: Some Error],
|
||||
"level": LogLevel {
|
||||
"id": "error",
|
||||
"value": 3,
|
||||
},
|
||||
"message": "message-5-with-error",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"error",
|
||||
"context-6",
|
||||
],
|
||||
"message-6-with-message",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-6",
|
||||
"level": LogLevel {
|
||||
"id": "error",
|
||||
"value": 3,
|
||||
},
|
||||
"message": "message-6-with-message",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"fatal",
|
||||
"context-7",
|
||||
"sub-context-7",
|
||||
"sub-sub-context-7",
|
||||
],
|
||||
[Error: Some Fatal Error],
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-7.sub-context-7.sub-sub-context-7",
|
||||
"error": [Error: Some Fatal Error],
|
||||
"level": LogLevel {
|
||||
"id": "fatal",
|
||||
"value": 2,
|
||||
},
|
||||
"message": "message-7-with-error",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"fatal",
|
||||
"context-8",
|
||||
"sub-context-8",
|
||||
"sub-sub-context-8",
|
||||
],
|
||||
"message-8-with-message",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-8.sub-context-8.sub-sub-context-8",
|
||||
"level": LogLevel {
|
||||
"id": "fatal",
|
||||
"value": 2,
|
||||
},
|
||||
"message": "message-8-with-message",
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"info",
|
||||
"context-9",
|
||||
"sub-context-9",
|
||||
],
|
||||
"message-9-with-message",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-9.sub-context-9",
|
||||
"level": LogLevel {
|
||||
"id": "info",
|
||||
"value": 5,
|
||||
},
|
||||
"message": "message-9-with-message",
|
||||
"meta": Object {
|
||||
"someValue": 3,
|
||||
},
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
Array [
|
||||
Array [
|
||||
"info",
|
||||
"context-10",
|
||||
"sub-context-10",
|
||||
"tag1",
|
||||
"tag2",
|
||||
],
|
||||
"message-10-with-message",
|
||||
2012-02-01T11:22:33.044Z,
|
||||
Object {
|
||||
"context": "context-10.sub-context-10",
|
||||
"level": LogLevel {
|
||||
"id": "info",
|
||||
"value": 5,
|
||||
},
|
||||
"message": "message-10-with-message",
|
||||
"meta": Object {
|
||||
"tags": Array [
|
||||
"tag1",
|
||||
"tag2",
|
||||
],
|
||||
},
|
||||
"timestamp": 2012-02-01T11:22:33.044Z,
|
||||
},
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
|
|
@ -17,16 +17,21 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
jest.mock('../../legacy_logging_server');
|
||||
|
||||
import { LogLevel } from '../../../../logging/log_level';
|
||||
import { LogRecord } from '../../../../logging/log_record';
|
||||
import { LegacyKbnServer } from '../../../legacy_kbn_server';
|
||||
import { LegacyLoggingServer } from '../../legacy_logging_server';
|
||||
import { LegacyAppender } from '../legacy_appender';
|
||||
|
||||
afterEach(() => (LegacyLoggingServer as any).mockClear());
|
||||
|
||||
test('`configSchema` creates correct schema.', () => {
|
||||
const appenderSchema = LegacyAppender.configSchema;
|
||||
const validConfig = { kind: 'legacy-appender' };
|
||||
const validConfig = { kind: 'legacy-appender', legacyLoggingConfig: { verbose: true } };
|
||||
expect(appenderSchema.validate(validConfig)).toEqual({
|
||||
kind: 'legacy-appender',
|
||||
legacyLoggingConfig: { verbose: true },
|
||||
});
|
||||
|
||||
const wrongConfig = { kind: 'not-legacy-appender' };
|
||||
|
@ -102,14 +107,26 @@ test('`append()` correctly pushes records to legacy platform.', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const rawKbnServerMock = {
|
||||
server: { log: jest.fn() },
|
||||
};
|
||||
const appender = new LegacyAppender(new LegacyKbnServer(rawKbnServerMock));
|
||||
|
||||
const appender = new LegacyAppender({ verbose: true });
|
||||
for (const record of records) {
|
||||
appender.append(record);
|
||||
}
|
||||
|
||||
expect(rawKbnServerMock.server.log.mock.calls).toMatchSnapshot();
|
||||
const [mockLegacyLoggingServerInstance] = (LegacyLoggingServer as any).mock.instances;
|
||||
expect(mockLegacyLoggingServerInstance.log.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('legacy logging server is correctly created and disposed.', async () => {
|
||||
const mockRawLegacyLoggingConfig = { verbose: true };
|
||||
const appender = new LegacyAppender(mockRawLegacyLoggingConfig);
|
||||
|
||||
expect(LegacyLoggingServer).toHaveBeenCalledTimes(1);
|
||||
expect(LegacyLoggingServer).toHaveBeenCalledWith(mockRawLegacyLoggingConfig);
|
||||
|
||||
const [mockLegacyLoggingServerInstance] = (LegacyLoggingServer as any).mock.instances;
|
||||
expect(mockLegacyLoggingServerInstance.stop).not.toHaveBeenCalled();
|
||||
|
||||
await appender.dispose();
|
||||
|
||||
expect(mockLegacyLoggingServerInstance.stop).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
|
@ -18,36 +18,36 @@
|
|||
*/
|
||||
|
||||
import { schema } from '../../../config/schema';
|
||||
|
||||
import { DisposableAppender } from '../../../logging/appenders/appenders';
|
||||
import { LogRecord } from '../../../logging/log_record';
|
||||
import { LegacyKbnServer } from '../../legacy_kbn_server';
|
||||
|
||||
const { literal, object } = schema;
|
||||
import { LegacyLoggingServer } from '../legacy_logging_server';
|
||||
|
||||
/**
|
||||
* Simple appender that just forwards `LogRecord` to the legacy KbnServer log.
|
||||
* @internal
|
||||
*/
|
||||
export class LegacyAppender implements DisposableAppender {
|
||||
public static configSchema = object({
|
||||
kind: literal('legacy-appender'),
|
||||
public static configSchema = schema.object({
|
||||
kind: schema.literal('legacy-appender'),
|
||||
legacyLoggingConfig: schema.any(),
|
||||
});
|
||||
|
||||
constructor(private readonly kbnServer: LegacyKbnServer) {}
|
||||
private readonly loggingServer: LegacyLoggingServer;
|
||||
|
||||
constructor(legacyLoggingConfig: Readonly<Record<string, any>>) {
|
||||
this.loggingServer = new LegacyLoggingServer(legacyLoggingConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards `LogRecord` to the legacy platform that will layout and
|
||||
* write record to the configured destination.
|
||||
* @param record `LogRecord` instance to forward to.
|
||||
*/
|
||||
public append({ level, context, message, error, timestamp, meta = {} }: LogRecord) {
|
||||
const tags = [level.id.toLowerCase(), ...context.split('.'), ...(meta.tags || [])];
|
||||
|
||||
this.kbnServer.log(tags, error || message, timestamp);
|
||||
public append(record: LogRecord) {
|
||||
this.loggingServer.log(record);
|
||||
}
|
||||
|
||||
public async dispose() {
|
||||
// noop
|
||||
public dispose() {
|
||||
this.loggingServer.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
// @ts-ignore: implicit any for JS file
|
||||
import { Config, transformDeprecations } from '../../../../server/config';
|
||||
// @ts-ignore: implicit any for JS file
|
||||
import { setupLogging } from '../../../../server/logging';
|
||||
import { LogRecord } from '../../logging/log_record';
|
||||
|
||||
interface PluginRegisterParams {
|
||||
register: {
|
||||
register: (
|
||||
server: LegacyLoggingServer,
|
||||
options: PluginRegisterParams['options'],
|
||||
cb: () => void
|
||||
) => void;
|
||||
};
|
||||
options: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "legacy" Kibana uses Hapi server + even-better plugin to log, so we should
|
||||
* use the same approach here to make log records generated by the core to look the
|
||||
* same as the rest of the records generated by the "legacy" Kibana. But to reduce
|
||||
* overhead of having full blown Hapi server instance we create our own "light" version.
|
||||
*/
|
||||
export class LegacyLoggingServer extends EventEmitter {
|
||||
public connections = [];
|
||||
|
||||
constructor(legacyLoggingConfig: Readonly<Record<string, any>>) {
|
||||
super();
|
||||
|
||||
// We set `ops.interval` to max allowed number and `ops` filter to value
|
||||
// that doesn't exist to avoid logging of ops at all, if turned on it will be
|
||||
// logged by the "legacy" Kibana.
|
||||
const config = {
|
||||
logging: {
|
||||
...legacyLoggingConfig,
|
||||
events: {
|
||||
...legacyLoggingConfig.events,
|
||||
ops: '__no-ops__',
|
||||
},
|
||||
},
|
||||
ops: { interval: 2147483647 },
|
||||
};
|
||||
|
||||
setupLogging(this, Config.withDefaultSchema(transformDeprecations(config)));
|
||||
}
|
||||
|
||||
public register({ register: plugin, options }: PluginRegisterParams, cb: () => void) {
|
||||
plugin.register(this, options, cb);
|
||||
}
|
||||
|
||||
public log({ level, context, message, error, timestamp, meta = {} }: LogRecord) {
|
||||
this.emit('log', {
|
||||
data: error || message,
|
||||
tags: [level.id.toLowerCase(), ...context.split('.'), ...(meta.tags || [])],
|
||||
timestamp: timestamp.getMilliseconds(),
|
||||
});
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this.emit('stop');
|
||||
}
|
||||
|
||||
public expose() {
|
||||
// method is called by plugin that's being registered.
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ beforeEach(() => {
|
|||
});
|
||||
|
||||
test('`get()` returns Logger that appends records to buffer if config is not ready.', () => {
|
||||
const factory = new MutableLoggerFactory({} as any);
|
||||
const factory = new MutableLoggerFactory();
|
||||
const loggerWithoutConfig = factory.get('some-context');
|
||||
const testsLogger = factory.get('tests');
|
||||
const testsChildLogger = factory.get('tests', 'child');
|
||||
|
@ -111,7 +111,7 @@ test('`get()` returns Logger that appends records to buffer if config is not rea
|
|||
|
||||
test('`get()` returns `root` logger if context is not specified.', () => {
|
||||
const loggingConfigSchema = LoggingConfig.schema;
|
||||
const factory = new MutableLoggerFactory({} as any);
|
||||
const factory = new MutableLoggerFactory();
|
||||
const config = loggingConfigSchema.validate({
|
||||
appenders: {
|
||||
default: {
|
||||
|
@ -133,7 +133,7 @@ test('`get()` returns `root` logger if context is not specified.', () => {
|
|||
});
|
||||
|
||||
test('`close()` disposes all resources used by appenders.', async () => {
|
||||
const factory = new MutableLoggerFactory({} as any);
|
||||
const factory = new MutableLoggerFactory();
|
||||
|
||||
const loggingConfigSchema = LoggingConfig.schema;
|
||||
const config = new LoggingConfig(
|
||||
|
|
|
@ -43,7 +43,7 @@ let service: LoggingService;
|
|||
let updateConfigMock: jest.Mock<(config: LoggingConfig) => void>;
|
||||
|
||||
beforeEach(() => {
|
||||
factory = new MutableLoggerFactory({} as any);
|
||||
factory = new MutableLoggerFactory();
|
||||
updateConfigMock = jest.spyOn(factory, 'updateConfig').mockImplementation(() => {
|
||||
// noop
|
||||
});
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`\`create()\` fails to create legacy appender if kbnServer is not provided. 1`] = `"Legacy appender requires kbnServer."`;
|
|
@ -22,9 +22,7 @@ jest.mock('../../layouts/layouts', () => {
|
|||
const { schema } = require('../../../config/schema');
|
||||
return {
|
||||
Layouts: {
|
||||
configSchema: schema.object({
|
||||
kind: schema.literal('mock'),
|
||||
}),
|
||||
configSchema: schema.object({ kind: schema.literal('mock') }),
|
||||
create: mockCreateLayout,
|
||||
},
|
||||
};
|
||||
|
@ -75,48 +73,23 @@ test('`configSchema` creates correct schema.', () => {
|
|||
test('`create()` creates correct appender.', () => {
|
||||
mockCreateLayout.mockReturnValue({ format: () => '' });
|
||||
|
||||
const consoleAppender = Appenders.create(
|
||||
{
|
||||
kind: 'console',
|
||||
layout: {
|
||||
highlight: true,
|
||||
kind: 'pattern',
|
||||
pattern: '',
|
||||
},
|
||||
},
|
||||
{} as any
|
||||
);
|
||||
const consoleAppender = Appenders.create({
|
||||
kind: 'console',
|
||||
layout: { highlight: true, kind: 'pattern', pattern: '' },
|
||||
});
|
||||
expect(consoleAppender).toBeInstanceOf(ConsoleAppender);
|
||||
|
||||
const fileAppender = Appenders.create(
|
||||
{
|
||||
kind: 'file',
|
||||
layout: {
|
||||
highlight: true,
|
||||
kind: 'pattern',
|
||||
pattern: '',
|
||||
},
|
||||
path: 'path',
|
||||
},
|
||||
{} as any
|
||||
);
|
||||
const fileAppender = Appenders.create({
|
||||
kind: 'file',
|
||||
layout: { highlight: true, kind: 'pattern', pattern: '' },
|
||||
path: 'path',
|
||||
});
|
||||
expect(fileAppender).toBeInstanceOf(FileAppender);
|
||||
});
|
||||
|
||||
test('`create()` fails to create legacy appender if kbnServer is not provided.', () => {
|
||||
expect(() => {
|
||||
Appenders.create({ kind: 'legacy-appender' }, {
|
||||
getLegacyKbnServer() {
|
||||
// noop
|
||||
},
|
||||
} as any);
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('`create()` creates legacy appender if kbnServer is provided.', () => {
|
||||
const legacyAppender = Appenders.create({ kind: 'legacy-appender' }, {
|
||||
getLegacyKbnServer: () => ({}),
|
||||
} as any);
|
||||
const legacyAppender = Appenders.create({
|
||||
kind: 'legacy-appender',
|
||||
legacyLoggingConfig: { verbose: true },
|
||||
});
|
||||
|
||||
expect(legacyAppender).toBeInstanceOf(LegacyAppender);
|
||||
});
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
import { schema, TypeOf } from '../../config/schema';
|
||||
|
||||
import { assertNever } from '../../../utils';
|
||||
import { Env } from '../../config';
|
||||
import { LegacyAppender } from '../../legacy_compat/logging/appenders/legacy_appender';
|
||||
import { Layouts } from '../layouts/layouts';
|
||||
import { LogRecord } from '../log_record';
|
||||
|
@ -62,10 +61,9 @@ export class Appenders {
|
|||
/**
|
||||
* Factory method that creates specific `Appender` instances based on the passed `config` parameter.
|
||||
* @param config Configuration specific to a particular `Appender` implementation.
|
||||
* @param env Current environment that is required by some appenders.
|
||||
* @returns Fully constructed `Appender` instance.
|
||||
*/
|
||||
public static create(config: AppenderConfigType, env: Env): DisposableAppender {
|
||||
public static create(config: AppenderConfigType): DisposableAppender {
|
||||
switch (config.kind) {
|
||||
case 'console':
|
||||
return new ConsoleAppender(Layouts.create(config.layout));
|
||||
|
@ -74,11 +72,7 @@ export class Appenders {
|
|||
return new FileAppender(Layouts.create(config.layout), config.path);
|
||||
|
||||
case 'legacy-appender':
|
||||
const legacyKbnServer = env.getLegacyKbnServer();
|
||||
if (legacyKbnServer === undefined) {
|
||||
throw new Error('Legacy appender requires kbnServer.');
|
||||
}
|
||||
return new LegacyAppender(legacyKbnServer);
|
||||
return new LegacyAppender(config.legacyLoggingConfig);
|
||||
|
||||
default:
|
||||
return assertNever(config);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { Env } from '../config';
|
||||
import { Appenders, DisposableAppender } from './appenders/appenders';
|
||||
import { BufferAppender } from './appenders/buffer/buffer_appender';
|
||||
import { LogLevel } from './log_level';
|
||||
|
@ -45,8 +44,6 @@ export class MutableLoggerFactory implements LoggerFactory {
|
|||
private readonly bufferAppender = new BufferAppender();
|
||||
private readonly loggers: Map<string, LoggerAdapter> = new Map();
|
||||
|
||||
constructor(private readonly env: Env) {}
|
||||
|
||||
public get(...contextParts: string[]): Logger {
|
||||
const context = LoggingConfig.getLoggerContext(contextParts);
|
||||
if (this.loggers.has(context)) {
|
||||
|
@ -76,7 +73,7 @@ export class MutableLoggerFactory implements LoggerFactory {
|
|||
this.appenders.clear();
|
||||
|
||||
for (const [appenderKey, appenderConfig] of config.appenders.entries()) {
|
||||
this.appenders.set(appenderKey, Appenders.create(appenderConfig, this.env));
|
||||
this.appenders.set(appenderKey, Appenders.create(appenderConfig));
|
||||
}
|
||||
|
||||
for (const [loggerKey, loggerAdapter] of this.loggers.entries()) {
|
||||
|
|
|
@ -46,7 +46,7 @@ export class Root {
|
|||
// noop
|
||||
}
|
||||
) {
|
||||
const loggerFactory = new MutableLoggerFactory(env);
|
||||
const loggerFactory = new MutableLoggerFactory();
|
||||
this.loggingService = new LoggingService(loggerFactory);
|
||||
this.logger = loggerFactory;
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ import {
|
|||
isInvalidPackError,
|
||||
} from './errors';
|
||||
|
||||
async function defaultConfig(settings) {
|
||||
return await Config.withDefaultSchema(
|
||||
function defaultConfig(settings) {
|
||||
return Config.withDefaultSchema(
|
||||
transformDeprecations(settings)
|
||||
);
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ function groupSpecsById(specs) {
|
|||
* using Kibana's defaults, settings, and config service
|
||||
*
|
||||
* @param {Object} settings
|
||||
* @param {ConfigService} [config] when supplied **it is mutated** to include
|
||||
* the config from discovered plugin specs
|
||||
* @param {ConfigService} [configToMutate] when supplied **it is mutated** to
|
||||
* include the config from discovered plugin specs
|
||||
* @return {Object<name,Rx>}
|
||||
*/
|
||||
export function findPluginSpecs(settings, configToMutate) {
|
||||
|
@ -104,7 +104,7 @@ export function findPluginSpecs(settings, configToMutate) {
|
|||
return configToMutate;
|
||||
}
|
||||
|
||||
return await defaultConfig(settings);
|
||||
return defaultConfig(settings);
|
||||
})
|
||||
.pipe(shareReplay());
|
||||
|
||||
|
|
|
@ -96,21 +96,21 @@ describe('plugin discovery/extend config service', () => {
|
|||
});
|
||||
|
||||
it('adds the schema for a plugin spec to its config prefix', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
expect(config.has('foo.bar.baz')).to.be(false);
|
||||
await extendConfigService(pluginSpec, config);
|
||||
expect(config.has('foo.bar.baz')).to.be(true);
|
||||
});
|
||||
|
||||
it('initializes it with the default settings', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
await extendConfigService(pluginSpec, config);
|
||||
expect(config.get('foo.bar.baz.enabled')).to.be(true);
|
||||
expect(config.get('foo.bar.baz.test')).to.be('bonk');
|
||||
});
|
||||
|
||||
it('initializes it with values from root settings if defined', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
await extendConfigService(pluginSpec, config, {
|
||||
foo: {
|
||||
bar: {
|
||||
|
@ -125,7 +125,7 @@ describe('plugin discovery/extend config service', () => {
|
|||
});
|
||||
|
||||
it('throws if root settings are invalid', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
try {
|
||||
await extendConfigService(pluginSpec, config, {
|
||||
foo: {
|
||||
|
@ -145,7 +145,7 @@ describe('plugin discovery/extend config service', () => {
|
|||
});
|
||||
|
||||
it('calls logDeprecation() with deprecation messages', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
const logDeprecation = sinon.stub();
|
||||
await extendConfigService(pluginSpec, config, {
|
||||
foo: {
|
||||
|
@ -161,7 +161,7 @@ describe('plugin discovery/extend config service', () => {
|
|||
});
|
||||
|
||||
it('uses settings after transforming deprecations', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
await extendConfigService(pluginSpec, config, {
|
||||
foo: {
|
||||
bar: {
|
||||
|
@ -177,7 +177,7 @@ describe('plugin discovery/extend config service', () => {
|
|||
|
||||
describe('disableConfigExtension()', () => {
|
||||
it('removes added config', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
await extendConfigService(pluginSpec, config);
|
||||
expect(config.has('foo.bar.baz.test')).to.be(true);
|
||||
await disableConfigExtension(pluginSpec, config);
|
||||
|
@ -185,7 +185,7 @@ describe('plugin discovery/extend config service', () => {
|
|||
});
|
||||
|
||||
it('leaves {configPrefix}.enabled config', async () => {
|
||||
const config = await Config.withDefaultSchema();
|
||||
const config = Config.withDefaultSchema();
|
||||
expect(config.has('foo.bar.baz.enabled')).to.be(false);
|
||||
await extendConfigService(pluginSpec, config);
|
||||
expect(config.get('foo.bar.baz.enabled')).to.be(true);
|
||||
|
|
|
@ -28,8 +28,8 @@ const schemaExts = Symbol('Schema Extensions');
|
|||
const vals = Symbol('config values');
|
||||
|
||||
export class Config {
|
||||
static async withDefaultSchema(settings = {}) {
|
||||
const defaultSchema = await createDefaultSchema();
|
||||
static withDefaultSchema(settings = {}) {
|
||||
const defaultSchema = createDefaultSchema();
|
||||
return new Config(defaultSchema, settings);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import os from 'os';
|
|||
import { fromRoot } from '../../utils';
|
||||
import { getData } from '../path';
|
||||
|
||||
export default async () => Joi.object({
|
||||
export default () => Joi.object({
|
||||
pkg: Joi.object({
|
||||
version: Joi.string().default(Joi.ref('$version')),
|
||||
branch: Joi.string().default(Joi.ref('$branch')),
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { Config } from './config';
|
||||
import { transformDeprecations } from './transform_deprecations';
|
||||
|
||||
export default async function (kbnServer) {
|
||||
export default function (kbnServer) {
|
||||
const settings = transformDeprecations(kbnServer.settings);
|
||||
kbnServer.config = await Config.withDefaultSchema(settings);
|
||||
kbnServer.config = Config.withDefaultSchema(settings);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ import { uiSettingsMixin } from '../ui_settings_mixin';
|
|||
describe('uiSettingsMixin()', () => {
|
||||
const sandbox = sinon.createSandbox();
|
||||
|
||||
async function setup() {
|
||||
const config = await Config.withDefaultSchema({
|
||||
function setup() {
|
||||
const config = Config.withDefaultSchema({
|
||||
uiSettings: {
|
||||
overrides: {
|
||||
foo: 'bar'
|
||||
|
@ -89,8 +89,8 @@ describe('uiSettingsMixin()', () => {
|
|||
afterEach(() => sandbox.restore());
|
||||
|
||||
describe('server.uiSettingsServiceFactory()', () => {
|
||||
it('decorates server with "uiSettingsServiceFactory"', async () => {
|
||||
const { decorations } = await setup();
|
||||
it('decorates server with "uiSettingsServiceFactory"', () => {
|
||||
const { decorations } = setup();
|
||||
expect(decorations.server).to.have.property('uiSettingsServiceFactory').a('function');
|
||||
|
||||
sandbox.stub(uiSettingsServiceFactoryNS, 'uiSettingsServiceFactory');
|
||||
|
@ -99,8 +99,8 @@ describe('uiSettingsMixin()', () => {
|
|||
sinon.assert.calledOnce(uiSettingsServiceFactory);
|
||||
});
|
||||
|
||||
it('passes `server` and `options` argument to factory', async () => {
|
||||
const { decorations, server } = await setup();
|
||||
it('passes `server` and `options` argument to factory', () => {
|
||||
const { decorations, server } = setup();
|
||||
expect(decorations.server).to.have.property('uiSettingsServiceFactory').a('function');
|
||||
|
||||
sandbox.stub(uiSettingsServiceFactoryNS, 'uiSettingsServiceFactory');
|
||||
|
@ -120,8 +120,8 @@ describe('uiSettingsMixin()', () => {
|
|||
});
|
||||
|
||||
describe('request.getUiSettingsService()', () => {
|
||||
it('exposes "getUiSettingsService" on requests', async () => {
|
||||
const { decorations } = await setup();
|
||||
it('exposes "getUiSettingsService" on requests', () => {
|
||||
const { decorations } = setup();
|
||||
expect(decorations.request).to.have.property('getUiSettingsService').a('function');
|
||||
|
||||
sandbox.stub(getUiSettingsServiceForRequestNS, 'getUiSettingsServiceForRequest');
|
||||
|
@ -130,8 +130,8 @@ describe('uiSettingsMixin()', () => {
|
|||
sinon.assert.calledOnce(getUiSettingsServiceForRequest);
|
||||
});
|
||||
|
||||
it('passes request to getUiSettingsServiceForRequest', async () => {
|
||||
const { server, decorations } = await setup();
|
||||
it('passes request to getUiSettingsServiceForRequest', () => {
|
||||
const { server, decorations } = setup();
|
||||
expect(decorations.request).to.have.property('getUiSettingsService').a('function');
|
||||
|
||||
sandbox.stub(getUiSettingsServiceForRequestNS, 'getUiSettingsServiceForRequest');
|
||||
|
@ -143,8 +143,8 @@ describe('uiSettingsMixin()', () => {
|
|||
});
|
||||
|
||||
describe('server.uiSettings()', () => {
|
||||
it('throws an error, links to pr', async () => {
|
||||
const { decorations } = await setup();
|
||||
it('throws an error, links to pr', () => {
|
||||
const { decorations } = setup();
|
||||
expect(decorations.server).to.have.property('uiSettings').a('function');
|
||||
expect(() => {
|
||||
decorations.server.uiSettings();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue