[server/config/deprecationWarnings] fix deprecation logging warnings (#17439)

* [server/config/deprecationWarnings] fix deprecation logging warnings

* typos

* explain kbn_server_worker a bit with better naming and comment

* Address review feedback
This commit is contained in:
Spencer 2018-03-30 09:35:26 -07:00 committed by GitHub
parent b64c092944
commit b78714e8d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 11 deletions

View file

@ -0,0 +1,79 @@
import { spawn } from 'child_process';
import expect from 'expect.js';
const RUN_KBN_SERVER_STARTUP = require.resolve('./fixtures/run_kbn_server_startup');
const BABEL_REGISTER = require.resolve('../../../babel-register');
const SECOND = 1000;
describe('config/deprecation warnings mixin', function () {
this.timeout(15 * SECOND);
let stdio = '';
let proc = null;
before(() => new Promise((resolve, reject) => {
proc = spawn(process.execPath, [
'-r', BABEL_REGISTER,
RUN_KBN_SERVER_STARTUP
], {
stdio: ['ignore', 'pipe', 'pipe'],
env: {
CREATE_SERVER_OPTS: JSON.stringify({
logging: {
quiet: false
},
uiSettings: {
enabled: true
}
})
}
});
proc.stdout.on('data', (chunk) => {
stdio += chunk.toString('utf8');
});
proc.stderr.on('data', (chunk) => {
stdio += chunk.toString('utf8');
});
proc.on('exit', (code) => {
proc = null;
if (code > 0) {
reject(new Error(`Kibana server exited with ${code} -- stdout:\n\n${stdio}\n`));
} else {
resolve();
}
});
}));
after(() => {
if (proc) {
proc.kill('SIGKILL');
}
});
it('logs deprecation warnings when using outdated config', async () => {
const deprecationLines = stdio
.split('\n')
.map(json => {
try {
// in dev mode kibana might log things like node.js warnings which
// are not JSON, ignore the lines that don't parse as JSON
return JSON.parse(json);
} catch (error) {
return null;
}
})
.filter(Boolean)
.filter(line => (
line.type === 'log' &&
line.tags.includes('deprecation') &&
line.tags.includes('warning')
));
expect(deprecationLines).to.have.length(1);
expect(deprecationLines[0]).to.have.property('message', 'uiSettings.enabled is deprecated and is no longer used');
});
});

View file

@ -0,0 +1,15 @@
import { createServer } from '../../../../test_utils/kbn_server';
(async function run() {
const server = createServer(JSON.parse(process.env.CREATE_SERVER_OPTS));
// We just need the server to run through startup so that it will
// log the deprecation messages. Once it has started up we close it
// to allow the process to exit naturally
try {
await server.ready();
} finally {
await server.close();
}
}());

View file

@ -1,6 +1,6 @@
import { transformDeprecations } from './transform_deprecations';
export default function (kbnServer, server) {
export function configDeprecationWarningsMixin(kbnServer, server) {
transformDeprecations(kbnServer.settings, (message) => {
server.log(['warning', 'config', 'deprecation'], message);
});

View file

@ -10,6 +10,7 @@ import { loggingMixin } from './logging';
import warningsMixin from './warnings';
import statusMixin from './status';
import pidMixin from './pid';
import { configDeprecationWarningsMixin } from './config/deprecation_warnings';
import configCompleteMixin from './config/complete';
import optimizeMixin from '../optimize';
import * as Plugins from './plugins';
@ -39,6 +40,7 @@ export default class KbnServer {
// adds methods for extending this.server
serverExtensionsMixin,
loggingMixin,
configDeprecationWarningsMixin,
warningsMixin,
statusMixin,

View file

@ -16,9 +16,6 @@ const DEFAULTS_SETTINGS = {
quiet: true
},
plugins: {},
uiSettings: {
enabled: false
},
optimize: {
enabled: false
},
@ -34,10 +31,7 @@ const DEFAULT_SETTINGS_WITH_CORE_PLUGINS = {
url: esTestConfig.getUrl(),
username: kibanaServer.username,
password: kibanaServer.password
},
uiSettings: {
enabled: true
},
}
};
/**

View file

@ -1,9 +1,7 @@
const debugInBand = process.execArgv.some(arg => {
switch (arg) {
case '--debug':
case '--debug-brk':
case '-d':
case '--inspect':
case '--inspect-brk':
return true;
}
});