Skip to content

Commit

Permalink
Fix reload logging config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Aug 22, 2019
1 parent b2cfb14 commit 6fea102
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/cli/serve/integration_tests/reload_logging_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Server logging configuration', function () {
it('should be reloadable via SIGHUP process signaling', async function () {
expect.assertions(3);

child = spawn(process.execPath, [kibanaPath, '--config', testConfigFile, '--oss'], {
child = spawn(process.execPath, [kibanaPath, '--config', testConfigFile, '--oss', '--verbose'], {
stdio: 'pipe'
});

Expand Down Expand Up @@ -114,7 +114,9 @@ describe('Server logging configuration', function () {
const data = JSON.parse(line);
sawJson = true;

if (data.tags.includes('listening')) {
// We know the sighup handler will be registered before
// root.setup() is called
if (data.message.includes('setting up root')) {
isJson = false;
setLoggingJson(false);

Expand All @@ -128,10 +130,9 @@ describe('Server logging configuration', function () {
// the switch yet, so we ignore before switching over.
} else {
// Kibana has successfully stopped logging json, so kill the server.

sawNonjson = true;

child.kill();
child && child.kill();
child = undefined;
}
})
Expand Down Expand Up @@ -178,10 +179,11 @@ describe('Server logging configuration', function () {
'--config', testConfigFile,
'--logging.dest', logPath,
'--plugins.initialize', 'false',
'--logging.json', 'false'
'--logging.json', 'false',
'--verbose'
]);

watchFileUntil(logPath, /http server running/, 2 * minute)
watchFileUntil(logPath, /starting server/, 2 * minute)
.then(() => {
// once the server is running, archive the log file and issue SIGHUP
fs.renameSync(logPath, logPathArchived);
Expand All @@ -190,8 +192,8 @@ describe('Server logging configuration', function () {
.then(() => watchFileUntil(logPath, /Reloaded logging configuration due to SIGHUP/, 10 * second))
.then(contents => {
const lines = contents.toString().split('\n');
// should be the first and only new line of the log file
expect(lines).toHaveLength(2);
// should be the first line of the new log file
expect(lines[0]).toMatch(/Reloaded logging configuration due to SIGHUP/);
child.kill();
})
.then(done, done);
Expand Down
32 changes: 16 additions & 16 deletions src/core/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ export async function bootstrap({

const root = new Root(rawConfigService.getConfig$(), env, onRootShutdown);

process.on('SIGHUP', () => {
const cliLogger = root.logger.get('cli');
cliLogger.info('Reloading logging configuration due to SIGHUP.', { tags: ['config'] });

try {
rawConfigService.reloadConfig();
} catch (err) {
return shutdown(err);
}

cliLogger.info('Reloaded logging configuration due to SIGHUP.', { tags: ['config'] });
});

process.on('SIGINT', () => shutdown());
process.on('SIGTERM', () => shutdown());

function shutdown(reason?: Error) {
rawConfigService.stop();
return root.shutdown(reason);
Expand All @@ -87,22 +103,6 @@ export async function bootstrap({
cliLogger.info('Optimization done.');
await shutdown();
}

process.on('SIGHUP', () => {
const cliLogger = root.logger.get('cli');
cliLogger.info('Reloading logging configuration due to SIGHUP.', { tags: ['config'] });

try {
rawConfigService.reloadConfig();
} catch (err) {
return shutdown(err);
}

cliLogger.info('Reloaded logging configuration due to SIGHUP.', { tags: ['config'] });
});

process.on('SIGINT', () => shutdown());
process.on('SIGTERM', () => shutdown());
}

function onRootShutdown(reason?: any) {
Expand Down
1 change: 1 addition & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class Server {
}

public async start() {
this.log.debug('starting server');
const pluginsStart = await this.plugins.start({});
const savedObjectsStart = await this.savedObjects.start({});

Expand Down

0 comments on commit 6fea102

Please sign in to comment.