mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Switch implicit server.log behavior with tmpl to logWithMetadata (#29002)
* Changing the optimizer's use to logWithMetadata * Switching ensureEsVersion to logWithMetadata * Changing pid logging to use logWithMetadata * Changing server/plugins to use logWithMetadata * Changing saved objects onBeforeWrite to logWithMetata * Changing server/status to server.logWithMetadata * Changing ui settings to use logWithMetadata * Removing _.template's usage from within log_format * Fixing initializing plugin log message * Fixing ensureEsVersion tests * Fixing health check tests * Fixing a few more forgotten tests
This commit is contained in:
parent
e7c28fda29
commit
ece86f6002
23 changed files with 112 additions and 120 deletions
|
@ -34,6 +34,7 @@ describe('plugins/elasticsearch', () => {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
server = {
|
server = {
|
||||||
log: sinon.stub(),
|
log: sinon.stub(),
|
||||||
|
logWithMetadata: sinon.stub(),
|
||||||
plugins: {
|
plugins: {
|
||||||
elasticsearch: {
|
elasticsearch: {
|
||||||
getCluster: sinon.stub().withArgs('admin').returns({ callWithInternalUser: sinon.stub() }),
|
getCluster: sinon.stub().withArgs('admin').returns({ callWithInternalUser: sinon.stub() }),
|
||||||
|
@ -120,17 +121,17 @@ describe('plugins/elasticsearch', () => {
|
||||||
it('warns if a node is only off by a patch version', async () => {
|
it('warns if a node is only off by a patch version', async () => {
|
||||||
setNodes('5.1.1');
|
setNodes('5.1.1');
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 2);
|
sinon.assert.callCount(server.logWithMetadata, 2);
|
||||||
expect(server.log.getCall(0).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(0).args[0]).to.contain('debug');
|
||||||
expect(server.log.getCall(1).args[0]).to.contain('warning');
|
expect(server.logWithMetadata.getCall(1).args[0]).to.contain('warning');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('warns if a node is off by a patch version and without http publish address', async () => {
|
it('warns if a node is off by a patch version and without http publish address', async () => {
|
||||||
setNodeWithoutHTTP('5.1.1');
|
setNodeWithoutHTTP('5.1.1');
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 2);
|
sinon.assert.callCount(server.logWithMetadata, 2);
|
||||||
expect(server.log.getCall(0).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(0).args[0]).to.contain('debug');
|
||||||
expect(server.log.getCall(1).args[0]).to.contain('warning');
|
expect(server.logWithMetadata.getCall(1).args[0]).to.contain('warning');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('errors if a node incompatible and without http publish address', async () => {
|
it('errors if a node incompatible and without http publish address', async () => {
|
||||||
|
@ -147,28 +148,28 @@ describe('plugins/elasticsearch', () => {
|
||||||
setNodes('5.1.1');
|
setNodes('5.1.1');
|
||||||
|
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 2);
|
sinon.assert.callCount(server.logWithMetadata, 2);
|
||||||
expect(server.log.getCall(0).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(0).args[0]).to.contain('debug');
|
||||||
expect(server.log.getCall(1).args[0]).to.contain('warning');
|
expect(server.logWithMetadata.getCall(1).args[0]).to.contain('warning');
|
||||||
|
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 3);
|
sinon.assert.callCount(server.logWithMetadata, 3);
|
||||||
expect(server.log.getCall(2).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(2).args[0]).to.contain('debug');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('warns again if the node list changes', async () => {
|
it('warns again if the node list changes', async () => {
|
||||||
setNodes('5.1.1');
|
setNodes('5.1.1');
|
||||||
|
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 2);
|
sinon.assert.callCount(server.logWithMetadata, 2);
|
||||||
expect(server.log.getCall(0).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(0).args[0]).to.contain('debug');
|
||||||
expect(server.log.getCall(1).args[0]).to.contain('warning');
|
expect(server.logWithMetadata.getCall(1).args[0]).to.contain('warning');
|
||||||
|
|
||||||
setNodes('5.1.2');
|
setNodes('5.1.2');
|
||||||
await ensureEsVersion(server, KIBANA_VERSION);
|
await ensureEsVersion(server, KIBANA_VERSION);
|
||||||
sinon.assert.callCount(server.log, 4);
|
sinon.assert.callCount(server.logWithMetadata, 4);
|
||||||
expect(server.log.getCall(2).args[0]).to.contain('debug');
|
expect(server.logWithMetadata.getCall(2).args[0]).to.contain('debug');
|
||||||
expect(server.log.getCall(3).args[0]).to.contain('warning');
|
expect(server.logWithMetadata.getCall(3).args[0]).to.contain('warning');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe('plugins/elasticsearch', () => {
|
||||||
|
|
||||||
// Setup the server mock
|
// Setup the server mock
|
||||||
server = {
|
server = {
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
info: { port: 5601 },
|
info: { port: 5601 },
|
||||||
config: function () { return { get, set }; },
|
config: function () { return { get, set }; },
|
||||||
plugins: {
|
plugins: {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export function ensureEsVersion(server, kibanaVersion) {
|
||||||
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin');
|
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin');
|
||||||
const isProd = server.config().get('env.prod');
|
const isProd = server.config().get('env.prod');
|
||||||
|
|
||||||
server.log(['plugin', 'debug'], 'Checking Elasticsearch version');
|
server.logWithMetadata(['plugin', 'debug'], 'Checking Elasticsearch version');
|
||||||
return callWithInternalUser('nodes.info', {
|
return callWithInternalUser('nodes.info', {
|
||||||
filterPath: [
|
filterPath: [
|
||||||
'nodes.*.version',
|
'nodes.*.version',
|
||||||
|
@ -92,12 +92,11 @@ export function ensureEsVersion(server, kibanaVersion) {
|
||||||
const warningNodeNames = getHumanizedNodeNames(simplifiedNodes).join(', ');
|
const warningNodeNames = getHumanizedNodeNames(simplifiedNodes).join(', ');
|
||||||
if (lastWarnedNodesForServer.get(server) !== warningNodeNames) {
|
if (lastWarnedNodesForServer.get(server) !== warningNodeNames) {
|
||||||
lastWarnedNodesForServer.set(server, warningNodeNames);
|
lastWarnedNodesForServer.set(server, warningNodeNames);
|
||||||
server.log(['warning'], {
|
server.logWithMetadata(['warning'],
|
||||||
tmpl: (
|
|
||||||
`You're running Kibana ${kibanaVersion} with some different versions of ` +
|
`You're running Kibana ${kibanaVersion} with some different versions of ` +
|
||||||
'Elasticsearch. Update Kibana or Elasticsearch to the same ' +
|
'Elasticsearch. Update Kibana or Elasticsearch to the same ' +
|
||||||
`version to prevent compatibility issues: ${warningNodeNames}`
|
`version to prevent compatibility issues: ${warningNodeNames}`,
|
||||||
),
|
{
|
||||||
kibanaVersion,
|
kibanaVersion,
|
||||||
nodes: simplifiedNodes,
|
nodes: simplifiedNodes,
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,7 +46,7 @@ const STATS_WARNINGS_FILTER = new RegExp([
|
||||||
|
|
||||||
export default class BaseOptimizer {
|
export default class BaseOptimizer {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
this.log = opts.log || (() => null);
|
this.logWithMetadata = opts.logWithMetadata || (() => null);
|
||||||
this.uiBundles = opts.uiBundles;
|
this.uiBundles = opts.uiBundles;
|
||||||
this.profile = opts.profile || false;
|
this.profile = opts.profile || false;
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ export default class BaseOptimizer {
|
||||||
new DynamicDllPlugin({
|
new DynamicDllPlugin({
|
||||||
uiBundles: this.uiBundles,
|
uiBundles: this.uiBundles,
|
||||||
threadLoaderPoolConfig: this.getThreadLoaderPoolConfig(),
|
threadLoaderPoolConfig: this.getThreadLoaderPoolConfig(),
|
||||||
log: this.log
|
logWithMetadata: this.logWithMetadata
|
||||||
}),
|
}),
|
||||||
|
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
|
|
|
@ -51,13 +51,13 @@ export class DllCompiler {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(uiBundles, threadLoaderPoolConfig, log) {
|
constructor(uiBundles, threadLoaderPoolConfig, logWithMetadata) {
|
||||||
this.rawDllConfig = DllCompiler.getRawDllConfig(
|
this.rawDllConfig = DllCompiler.getRawDllConfig(
|
||||||
uiBundles,
|
uiBundles,
|
||||||
uiBundles.getCacheDirectory('babel'),
|
uiBundles.getCacheDirectory('babel'),
|
||||||
threadLoaderPoolConfig
|
threadLoaderPoolConfig
|
||||||
);
|
);
|
||||||
this.log = log || (() => null);
|
this.logWithMetadata = logWithMetadata || (() => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
@ -182,7 +182,7 @@ export class DllCompiler {
|
||||||
|
|
||||||
async runWebpack(config) {
|
async runWebpack(config) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.log(['info', 'optimize:dynamic_dll_plugin'], 'Client vendors dll compilation started');
|
this.logWithMetadata(['info', 'optimize:dynamic_dll_plugin'], 'Client vendors dll compilation started');
|
||||||
|
|
||||||
webpack(config, (err, stats) => {
|
webpack(config, (err, stats) => {
|
||||||
// If a critical error occurs or we have
|
// If a critical error occurs or we have
|
||||||
|
@ -197,7 +197,7 @@ export class DllCompiler {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (webpackErrors) {
|
if (webpackErrors) {
|
||||||
this.log(
|
this.logWithMetadata(
|
||||||
['fatal', 'optimize:dynamic_dll_plugin'],
|
['fatal', 'optimize:dynamic_dll_plugin'],
|
||||||
`Client vendors dll compilation failed`
|
`Client vendors dll compilation failed`
|
||||||
);
|
);
|
||||||
|
@ -205,7 +205,7 @@ export class DllCompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise let it proceed
|
// Otherwise let it proceed
|
||||||
this.log(
|
this.logWithMetadata(
|
||||||
['info', 'optimize:dynamic_dll_plugin'],
|
['info', 'optimize:dynamic_dll_plugin'],
|
||||||
`Client vendors dll compilation finished with success`
|
`Client vendors dll compilation finished with success`
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,9 +40,9 @@ function inPluginNodeModules(checkPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DynamicDllPlugin {
|
export class DynamicDllPlugin {
|
||||||
constructor({ uiBundles, threadLoaderPoolConfig, log, maxCompilations = 1 }) {
|
constructor({ uiBundles, threadLoaderPoolConfig, logWithMetadata, maxCompilations = 1 }) {
|
||||||
this.log = log || (() => null);
|
this.logWithMetadata = logWithMetadata || (() => null);
|
||||||
this.dllCompiler = new DllCompiler(uiBundles, threadLoaderPoolConfig, log);
|
this.dllCompiler = new DllCompiler(uiBundles, threadLoaderPoolConfig, logWithMetadata);
|
||||||
this.entryPaths = '';
|
this.entryPaths = '';
|
||||||
this.afterCompilationEntryPaths = '';
|
this.afterCompilationEntryPaths = '';
|
||||||
this.maxCompilations = maxCompilations;
|
this.maxCompilations = maxCompilations;
|
||||||
|
@ -92,7 +92,7 @@ export class DynamicDllPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerTasksHooks(compiler) {
|
registerTasksHooks(compiler) {
|
||||||
this.log(['info', 'optimize:dynamic_dll_plugin'], 'Started dynamic dll plugin tasks');
|
this.logWithMetadata(['info', 'optimize:dynamic_dll_plugin'], 'Started dynamic dll plugin tasks');
|
||||||
this.registerBeforeCompileHook(compiler);
|
this.registerBeforeCompileHook(compiler);
|
||||||
this.registerCompilationHook(compiler);
|
this.registerCompilationHook(compiler);
|
||||||
this.registerDoneHook(compiler);
|
this.registerDoneHook(compiler);
|
||||||
|
@ -231,7 +231,7 @@ export class DynamicDllPlugin {
|
||||||
// Only run this info log in the first performed dll compilation
|
// Only run this info log in the first performed dll compilation
|
||||||
// per each execution run
|
// per each execution run
|
||||||
if (this.performedCompilations === 0) {
|
if (this.performedCompilations === 0) {
|
||||||
this.log(
|
this.logWithMetadata(
|
||||||
['info', 'optimize:dynamic_dll_plugin'],
|
['info', 'optimize:dynamic_dll_plugin'],
|
||||||
compilation.needsDLLCompilation
|
compilation.needsDLLCompilation
|
||||||
? 'Need to compile the client vendors dll'
|
? 'Need to compile the client vendors dll'
|
||||||
|
@ -269,7 +269,7 @@ export class DynamicDllPlugin {
|
||||||
if (this.forceDLLCreationFlag) {
|
if (this.forceDLLCreationFlag) {
|
||||||
this.forceDLLCreationFlag = false;
|
this.forceDLLCreationFlag = false;
|
||||||
}
|
}
|
||||||
this.log(['info', 'optimize:dynamic_dll_plugin'], 'Finished all dynamic dll plugin tasks');
|
this.logWithMetadata(['info', 'optimize:dynamic_dll_plugin'], 'Finished all dynamic dll plugin tasks');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default async (kbnServer, server, config) => {
|
||||||
|
|
||||||
// only require the FsOptimizer when we need to
|
// only require the FsOptimizer when we need to
|
||||||
const optimizer = new FsOptimizer({
|
const optimizer = new FsOptimizer({
|
||||||
log: (tags, data) => server.log(tags, data),
|
logWithMetadata: (tags, message, metadata) => server.logWithMetadata(tags, message, metadata),
|
||||||
uiBundles,
|
uiBundles,
|
||||||
profile: config.get('optimize.profile'),
|
profile: config.get('optimize.profile'),
|
||||||
sourceMaps: config.get('optimize.sourceMaps'),
|
sourceMaps: config.get('optimize.sourceMaps'),
|
||||||
|
|
|
@ -25,16 +25,16 @@ import { DllCompiler } from '../dynamic_dll_plugin';
|
||||||
import { WatchCache } from './watch_cache';
|
import { WatchCache } from './watch_cache';
|
||||||
|
|
||||||
export default async (kbnServer, kibanaHapiServer, config) => {
|
export default async (kbnServer, kibanaHapiServer, config) => {
|
||||||
const log = (tags, data) => kibanaHapiServer.log(tags, data);
|
const logWithMetadata = (tags, message, metadata) => kibanaHapiServer.logWithMetadata(tags, message, metadata);
|
||||||
|
|
||||||
const watchOptimizer = new WatchOptimizer({
|
const watchOptimizer = new WatchOptimizer({
|
||||||
log,
|
logWithMetadata,
|
||||||
uiBundles: kbnServer.uiBundles,
|
uiBundles: kbnServer.uiBundles,
|
||||||
profile: config.get('optimize.profile'),
|
profile: config.get('optimize.profile'),
|
||||||
sourceMaps: config.get('optimize.sourceMaps'),
|
sourceMaps: config.get('optimize.sourceMaps'),
|
||||||
prebuild: config.get('optimize.watchPrebuild'),
|
prebuild: config.get('optimize.watchPrebuild'),
|
||||||
watchCache: new WatchCache({
|
watchCache: new WatchCache({
|
||||||
log,
|
logWithMetadata,
|
||||||
outputPath: config.get('path.data'),
|
outputPath: config.get('path.data'),
|
||||||
dllsPath: DllCompiler.getRawDllConfig().outputPath,
|
dllsPath: DllCompiler.getRawDllConfig().outputPath,
|
||||||
cachePath: resolve(kbnServer.uiBundles.getCacheDirectory(), '../'),
|
cachePath: resolve(kbnServer.uiBundles.getCacheDirectory(), '../'),
|
||||||
|
|
|
@ -31,7 +31,7 @@ const readAsync = promisify(readFile);
|
||||||
const writeAsync = promisify(writeFile);
|
const writeAsync = promisify(writeFile);
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
log: (tags: string[], data: string) => void;
|
logWithMetadata: (tags: string[], message: string, metadata?: { [key: string]: any }) => void;
|
||||||
outputPath: string;
|
outputPath: string;
|
||||||
dllsPath: string;
|
dllsPath: string;
|
||||||
cachePath: string;
|
cachePath: string;
|
||||||
|
@ -43,7 +43,7 @@ interface WatchCacheStateContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WatchCache {
|
export class WatchCache {
|
||||||
private readonly log: Params['log'];
|
private readonly logWithMetadata: Params['logWithMetadata'];
|
||||||
private readonly outputPath: Params['outputPath'];
|
private readonly outputPath: Params['outputPath'];
|
||||||
private readonly dllsPath: Params['dllsPath'];
|
private readonly dllsPath: Params['dllsPath'];
|
||||||
private readonly cachePath: Params['cachePath'];
|
private readonly cachePath: Params['cachePath'];
|
||||||
|
@ -53,7 +53,7 @@ export class WatchCache {
|
||||||
private isInitialized: boolean;
|
private isInitialized: boolean;
|
||||||
|
|
||||||
constructor(params: Params) {
|
constructor(params: Params) {
|
||||||
this.log = params.log;
|
this.logWithMetadata = params.logWithMetadata;
|
||||||
this.outputPath = params.outputPath;
|
this.outputPath = params.outputPath;
|
||||||
this.dllsPath = params.dllsPath;
|
this.dllsPath = params.dllsPath;
|
||||||
this.cachePath = params.cachePath;
|
this.cachePath = params.cachePath;
|
||||||
|
@ -87,7 +87,7 @@ export class WatchCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reset() {
|
public async reset() {
|
||||||
this.log(['info', 'optimize:watch_cache'], 'The optimizer watch cache will reset');
|
this.logWithMetadata(['info', 'optimize:watch_cache'], 'The optimizer watch cache will reset');
|
||||||
|
|
||||||
// start by deleting the state file to lower the
|
// start by deleting the state file to lower the
|
||||||
// amount of time that another process might be able to
|
// amount of time that another process might be able to
|
||||||
|
@ -116,7 +116,7 @@ export class WatchCache {
|
||||||
// re-write new cache state file
|
// re-write new cache state file
|
||||||
await this.write();
|
await this.write();
|
||||||
|
|
||||||
this.log(['info', 'optimize:watch_cache'], 'The optimizer watch cache has reset');
|
this.logWithMetadata(['info', 'optimize:watch_cache'], 'The optimizer watch cache has reset');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async buildShaWithMultipleFiles(filePaths: string[]) {
|
private async buildShaWithMultipleFiles(filePaths: string[]) {
|
||||||
|
|
|
@ -156,16 +156,14 @@ export default class WatchOptimizer extends BaseOptimizer {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case STATUS.RUNNING:
|
case STATUS.RUNNING:
|
||||||
if (!this.initialBuildComplete) {
|
if (!this.initialBuildComplete) {
|
||||||
this.log(['info', 'optimize'], {
|
this.logWithMetadata(['info', 'optimize'], `Optimization started`, {
|
||||||
tmpl: 'Optimization started',
|
|
||||||
bundles: this.uiBundles.getIds()
|
bundles: this.uiBundles.getIds()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS.SUCCESS:
|
case STATUS.SUCCESS:
|
||||||
this.log(['info', 'optimize'], {
|
this.logWithMetadata(['info', 'optimize'], `Optimization success in ${seconds} seconds`, {
|
||||||
tmpl: 'Optimization <%= status %> in <%= seconds %> seconds',
|
|
||||||
bundles: this.uiBundles.getIds(),
|
bundles: this.uiBundles.getIds(),
|
||||||
status: 'success',
|
status: 'success',
|
||||||
seconds
|
seconds
|
||||||
|
@ -176,8 +174,7 @@ export default class WatchOptimizer extends BaseOptimizer {
|
||||||
// errors during initialization to the server, unlike the rest of the
|
// errors during initialization to the server, unlike the rest of the
|
||||||
// errors produced here. Lets not muddy the console with extra errors
|
// errors produced here. Lets not muddy the console with extra errors
|
||||||
if (!this.initializing) {
|
if (!this.initializing) {
|
||||||
this.log(['fatal', 'optimize'], {
|
this.logWithMetadata(['fatal', 'optimize'], `Optimization failed in ${seconds} seconds${error}`, {
|
||||||
tmpl: 'Optimization <%= status %> in <%= seconds %> seconds<%= err %>',
|
|
||||||
bundles: this.uiBundles.getIds(),
|
bundles: this.uiBundles.getIds(),
|
||||||
status: 'failed',
|
status: 'failed',
|
||||||
seconds,
|
seconds,
|
||||||
|
@ -187,7 +184,7 @@ export default class WatchOptimizer extends BaseOptimizer {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS.FATAL:
|
case STATUS.FATAL:
|
||||||
this.log('fatal', error);
|
this.logWithMetadata('fatal', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,11 +162,6 @@ export default class TransformObjStream extends Stream.Transform {
|
||||||
else if (logWithMetadata.isLogEvent(event.data)) {
|
else if (logWithMetadata.isLogEvent(event.data)) {
|
||||||
_.assign(data, logWithMetadata.getLogEventData(event.data));
|
_.assign(data, logWithMetadata.getLogEventData(event.data));
|
||||||
}
|
}
|
||||||
else if (_.isPlainObject(event.data) && event.data.tmpl) {
|
|
||||||
_.assign(data, event.data);
|
|
||||||
data.tmpl = undefined;
|
|
||||||
data.message = _.template(event.data.tmpl)(event.data);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
data.message = _.isString(event.data) ? event.data : inspect(event.data);
|
data.message = _.isString(event.data) ? event.data : inspect(event.data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,24 +33,23 @@ export default Promise.method(function (kbnServer, server, config) {
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
if (err.code !== 'EEXIST') throw err;
|
if (err.code !== 'EEXIST') throw err;
|
||||||
|
|
||||||
const log = {
|
const message = `pid file already exists at ${path}`;
|
||||||
tmpl: 'pid file already exists at <%= path %>',
|
const metadata = {
|
||||||
path: path,
|
path: path,
|
||||||
pid: pid
|
pid: pid
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.get('pid.exclusive')) {
|
if (config.get('pid.exclusive')) {
|
||||||
throw Boom.internal(_.template(log.tmpl)(log), log);
|
throw Boom.internal(message, { message, ...metadata });
|
||||||
} else {
|
} else {
|
||||||
server.log(['pid', 'warning'], log);
|
server.log(['pid', 'warning'], message, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeFile(path, pid);
|
return writeFile(path, pid);
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
|
|
||||||
server.log(['pid', 'debug'], {
|
server.logWithMetadata(['pid', 'debug'], `wrote pid file to ${path}`, {
|
||||||
tmpl: 'wrote pid file to <%= path %>',
|
|
||||||
path: path,
|
path: path,
|
||||||
pid: pid
|
pid: pid
|
||||||
});
|
});
|
||||||
|
|
|
@ -66,8 +66,7 @@ export class Plugin {
|
||||||
this._server = server;
|
this._server = server;
|
||||||
this._options = options;
|
this._options = options;
|
||||||
|
|
||||||
server.log(['plugins', 'debug'], {
|
server.logWithMetadata(['plugins', 'debug'], `Initializing plugin ${this.toString()}`, {
|
||||||
tmpl: 'Initializing plugin <%= plugin.toString() %>',
|
|
||||||
plugin: this
|
plugin: this
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,16 @@ export async function scanMixin(kbnServer, server, config) {
|
||||||
const logging$ = Rx.merge(
|
const logging$ = Rx.merge(
|
||||||
pack$.pipe(
|
pack$.pipe(
|
||||||
tap(definition => {
|
tap(definition => {
|
||||||
server.log(['plugin', 'debug'], {
|
const path = definition.getPath();
|
||||||
tmpl: 'Found plugin at <%= path %>',
|
server.logWithMetadata(['plugin', 'debug'], `Found plugin at ${path}`, {
|
||||||
path: definition.getPath()
|
path
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
invalidDirectoryError$.pipe(
|
invalidDirectoryError$.pipe(
|
||||||
tap(error => {
|
tap(error => {
|
||||||
server.log(['plugin', 'warning'], {
|
server.logWithMetadata(['plugin', 'warning'], `${error.code}: Unable to scan directory for plugins "${error.path}"`, {
|
||||||
tmpl: '<%= err.code %>: Unable to scan directory for plugins "<%= dir %>"',
|
|
||||||
err: error,
|
err: error,
|
||||||
dir: error.path
|
dir: error.path
|
||||||
});
|
});
|
||||||
|
@ -57,8 +56,7 @@ export async function scanMixin(kbnServer, server, config) {
|
||||||
|
|
||||||
invalidPackError$.pipe(
|
invalidPackError$.pipe(
|
||||||
tap(error => {
|
tap(error => {
|
||||||
server.log(['plugin', 'warning'], {
|
server.logWithMetadata(['plugin', 'warning'], `Skipping non-plugin directory at ${error.path}`, {
|
||||||
tmpl: 'Skipping non-plugin directory at <%= path %>',
|
|
||||||
path: error.path
|
path: error.path
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -49,8 +49,10 @@ export function createSavedObjectsService(server, schema, serializer, migrator)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
server.log(['debug', 'savedObjects'], {
|
server.logWithMetadata(
|
||||||
tmpl: 'Attempt to write indexTemplate for SavedObjects index failed: <%= err.message %>',
|
['debug', 'savedObjects'],
|
||||||
|
`Attempt to write indexTemplate for SavedObjects index failed: ${error.message}`,
|
||||||
|
{
|
||||||
es: {
|
es: {
|
||||||
resp: error.body,
|
resp: error.body,
|
||||||
status: error.status,
|
status: error.status,
|
||||||
|
@ -59,7 +61,8 @@ export function createSavedObjectsService(server, schema, serializer, migrator)
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stack: error.stack,
|
stack: error.stack,
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// We reject with `es.ServiceUnavailable` because writing an index
|
// We reject with `es.ServiceUnavailable` because writing an index
|
||||||
// template is a very simple operation so if we get an error here
|
// template is a very simple operation so if we get an error here
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe('ServerStatus class', function () {
|
||||||
let serverStatus;
|
let serverStatus;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
server = { expose: sinon.stub(), log: sinon.stub() };
|
server = { expose: sinon.stub(), logWithMetadata: sinon.stub() };
|
||||||
serverStatus = new ServerStatus(server);
|
serverStatus = new ServerStatus(server);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,15 @@ export default class Status extends EventEmitter {
|
||||||
this.state === 'red' ? 'error' : 'info'
|
this.state === 'red' ? 'error' : 'info'
|
||||||
];
|
];
|
||||||
|
|
||||||
server.log(tags, {
|
server.logWithMetadata(tags,
|
||||||
tmpl: 'Status changed from <%= prevState %> to <%= state %><%= message ? " - " + message : "" %>',
|
`Status changed from ${ previous } to ${this.state}${ this.message ? ' - ' + this.message : '' }`,
|
||||||
|
{
|
||||||
state: this.state,
|
state: this.state,
|
||||||
message: this.message,
|
message: this.message,
|
||||||
prevState: previous,
|
prevState: previous,
|
||||||
prevMsg: previousMsg
|
prevMsg: previousMsg
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe('Status class', function () {
|
||||||
let serverStatus;
|
let serverStatus;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
server = { expose: sinon.stub(), log: sinon.stub() };
|
server = { expose: sinon.stub(), logWithMetadata: sinon.stub() };
|
||||||
serverStatus = new ServerStatus(server);
|
serverStatus = new ServerStatus(server);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe('createOrUpgradeSavedConfig()', () => {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version: '5.4.0',
|
version: '5.4.0',
|
||||||
buildNum: 54099,
|
buildNum: 54099,
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const config540 = await savedObjectsClient.get('config', '5.4.0');
|
const config540 = await savedObjectsClient.get('config', '5.4.0');
|
||||||
|
@ -104,7 +104,7 @@ describe('createOrUpgradeSavedConfig()', () => {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version: '5.4.1',
|
version: '5.4.1',
|
||||||
buildNum: 54199,
|
buildNum: 54199,
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const config541 = await savedObjectsClient.get('config', '5.4.1');
|
const config541 = await savedObjectsClient.get('config', '5.4.1');
|
||||||
|
@ -130,7 +130,7 @@ describe('createOrUpgradeSavedConfig()', () => {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version: '7.0.0-rc1',
|
version: '7.0.0-rc1',
|
||||||
buildNum: 70010,
|
buildNum: 70010,
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const config700rc1 = await savedObjectsClient.get('config', '7.0.0-rc1');
|
const config700rc1 = await savedObjectsClient.get('config', '7.0.0-rc1');
|
||||||
|
@ -157,7 +157,7 @@ describe('createOrUpgradeSavedConfig()', () => {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version: '7.0.0',
|
version: '7.0.0',
|
||||||
buildNum: 70099,
|
buildNum: 70099,
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const config700 = await savedObjectsClient.get('config', '7.0.0');
|
const config700 = await savedObjectsClient.get('config', '7.0.0');
|
||||||
|
@ -185,7 +185,7 @@ describe('createOrUpgradeSavedConfig()', () => {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version: '6.2.3-rc1',
|
version: '6.2.3-rc1',
|
||||||
buildNum: 62310,
|
buildNum: 62310,
|
||||||
log: sinon.stub(),
|
logWithMetadata: sinon.stub(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const config623rc1 = await savedObjectsClient.get('config', '6.2.3-rc1');
|
const config623rc1 = await savedObjectsClient.get('config', '6.2.3-rc1');
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
const buildNum = chance.integer({ min: 1000, max: 5000 });
|
const buildNum = chance.integer({ min: 1000, max: 5000 });
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
const log = sinon.stub();
|
const logWithMetadata = sinon.stub();
|
||||||
const getUpgradeableConfig = sandbox.stub(getUpgradeableConfigNS, 'getUpgradeableConfig');
|
const getUpgradeableConfig = sandbox.stub(getUpgradeableConfigNS, 'getUpgradeableConfig');
|
||||||
const savedObjectsClient = {
|
const savedObjectsClient = {
|
||||||
create: sinon.stub().callsFake(async (type, attributes, options = {}) => ({
|
create: sinon.stub().callsFake(async (type, attributes, options = {}) => ({
|
||||||
|
@ -50,7 +50,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version,
|
version,
|
||||||
buildNum,
|
buildNum,
|
||||||
log,
|
logWithMetadata,
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buildNum,
|
buildNum,
|
||||||
log,
|
logWithMetadata,
|
||||||
run,
|
run,
|
||||||
version,
|
version,
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
|
@ -120,17 +120,17 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log a message for upgrades', async () => {
|
it('should log a message for upgrades', async () => {
|
||||||
const { getUpgradeableConfig, log, run } = setup();
|
const { getUpgradeableConfig, logWithMetadata, run } = setup();
|
||||||
|
|
||||||
getUpgradeableConfig
|
getUpgradeableConfig
|
||||||
.returns({ id: prevVersion, attributes: { buildNum: buildNum - 100 } });
|
.returns({ id: prevVersion, attributes: { buildNum: buildNum - 100 } });
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
sinon.assert.calledOnce(log);
|
sinon.assert.calledOnce(logWithMetadata);
|
||||||
sinon.assert.calledWithExactly(log,
|
sinon.assert.calledWithExactly(logWithMetadata,
|
||||||
['plugin', 'elasticsearch'],
|
['plugin', 'elasticsearch'],
|
||||||
|
sinon.match('Upgrade'),
|
||||||
sinon.match({
|
sinon.match({
|
||||||
tmpl: sinon.match('Upgrade'),
|
|
||||||
prevVersion,
|
prevVersion,
|
||||||
newVersion: version,
|
newVersion: version,
|
||||||
})
|
})
|
||||||
|
@ -138,7 +138,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not log when upgrade fails', async () => {
|
it('does not log when upgrade fails', async () => {
|
||||||
const { getUpgradeableConfig, log, run, savedObjectsClient } = setup();
|
const { getUpgradeableConfig, logWithMetadata, run, savedObjectsClient } = setup();
|
||||||
|
|
||||||
getUpgradeableConfig
|
getUpgradeableConfig
|
||||||
.returns({ id: prevVersion, attributes: { buildNum: buildNum - 100 } });
|
.returns({ id: prevVersion, attributes: { buildNum: buildNum - 100 } });
|
||||||
|
@ -154,7 +154,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
|
||||||
expect(error.message).to.be('foo');
|
expect(error.message).to.be('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
sinon.assert.notCalled(log);
|
sinon.assert.notCalled(logWithMetadata);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ export async function createOrUpgradeSavedConfig(options) {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
version,
|
version,
|
||||||
buildNum,
|
buildNum,
|
||||||
log,
|
logWithMetadata,
|
||||||
onWriteError,
|
onWriteError,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@ export async function createOrUpgradeSavedConfig(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (upgradeableConfig) {
|
if (upgradeableConfig) {
|
||||||
log(['plugin', 'elasticsearch'], {
|
logWithMetadata(['plugin', 'elasticsearch'], `Upgrade config from ${upgradeableConfig.id} to ${version}`, {
|
||||||
tmpl: 'Upgrade config from <%= prevVersion %> to <%= newVersion %>',
|
|
||||||
prevVersion: upgradeableConfig.id,
|
prevVersion: upgradeableConfig.id,
|
||||||
newVersion: version
|
newVersion: version
|
||||||
});
|
});
|
||||||
|
|
|
@ -46,8 +46,8 @@ export class UiSettingsService {
|
||||||
// we use a function for getDefaults() so that defaults can be different in
|
// we use a function for getDefaults() so that defaults can be different in
|
||||||
// different scenarios, and so they can change over time
|
// different scenarios, and so they can change over time
|
||||||
getDefaults = () => ({}),
|
getDefaults = () => ({}),
|
||||||
// function that accepts log messages in the same format as server.log
|
// function that accepts log messages in the same format as server.logWithMetadata
|
||||||
log = () => {},
|
logWithMetadata = () => {},
|
||||||
overrides = {},
|
overrides = {},
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export class UiSettingsService {
|
||||||
this._savedObjectsClient = savedObjectsClient;
|
this._savedObjectsClient = savedObjectsClient;
|
||||||
this._getDefaults = getDefaults;
|
this._getDefaults = getDefaults;
|
||||||
this._overrides = overrides;
|
this._overrides = overrides;
|
||||||
this._log = log;
|
this._logWithMetadata = logWithMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDefaults() {
|
async getDefaults() {
|
||||||
|
@ -157,7 +157,7 @@ export class UiSettingsService {
|
||||||
savedObjectsClient: this._savedObjectsClient,
|
savedObjectsClient: this._savedObjectsClient,
|
||||||
version: this._id,
|
version: this._id,
|
||||||
buildNum: this._buildNum,
|
buildNum: this._buildNum,
|
||||||
log: this._log,
|
logWithMetadata: this._logWithMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this._write({
|
await this._write({
|
||||||
|
@ -195,7 +195,7 @@ export class UiSettingsService {
|
||||||
savedObjectsClient: this._savedObjectsClient,
|
savedObjectsClient: this._savedObjectsClient,
|
||||||
version: this._id,
|
version: this._id,
|
||||||
buildNum: this._buildNum,
|
buildNum: this._buildNum,
|
||||||
log: this._log,
|
logWithMetadata: this._logWithMetadata,
|
||||||
onWriteError(error, attributes) {
|
onWriteError(error, attributes) {
|
||||||
if (isNotAuthorizedError(error) || isForbiddenError(error)) {
|
if (isNotAuthorizedError(error) || isForbiddenError(error)) {
|
||||||
return attributes;
|
return attributes;
|
||||||
|
|
|
@ -47,6 +47,6 @@ export function uiSettingsServiceFactory(server, options) {
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
getDefaults,
|
getDefaults,
|
||||||
overrides,
|
overrides,
|
||||||
log: (...args) => server.log(...args),
|
logWithMetadata: (...args) => server.logWithMetadata(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue