Skip to content

Commit

Permalink
feat: add time duration for dump config (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and dead-horse committed May 3, 2018
1 parent 73dac08 commit 824200c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.default.js
Expand Up @@ -318,6 +318,7 @@ module.exports = appInfo => {
* @property {Number} responseTimeout - response timeout, default is 60000
*/
config.clusterClient = {
maxWaitTime: 60000,
responseTimeout: 60000,
};

Expand Down
3 changes: 3 additions & 0 deletions lib/agent.js
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const ms = require('ms');
const EggApplication = require('./egg');
const AgentWorkerLoader = require('./loader').AgentWorkerLoader;

Expand All @@ -25,7 +26,9 @@ class Agent extends EggApplication {
this.loader.load();

// dump config after loaded, ensure all the dynamic modifications will be recorded
const dumpStartTime = Date.now();
this.dumpConfig();
this.coreLogger.info('[egg:core] dump config after load, %s', ms(Date.now() - dumpStartTime));

// keep agent alive even it don't have any io tasks
setInterval(() => {}, 24 * 60 * 60 * 1000);
Expand Down
4 changes: 4 additions & 0 deletions lib/application.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const fs = require('fs');
const ms = require('ms');
const graceful = require('graceful');
const http = require('http');
const cluster = require('cluster-client');
Expand Down Expand Up @@ -69,7 +70,10 @@ class Application extends EggApplication {
}

// dump config after loaded, ensure all the dynamic modifications will be recorded
const dumpStartTime = Date.now();
this.dumpConfig();
this.coreLogger.info('[egg:core] dump config after load, %s', ms(Date.now() - dumpStartTime));

this[WARN_CONFUSED_CONFIG]();
this[BIND_EVENTS]();
}
Expand Down
7 changes: 6 additions & 1 deletion lib/egg.js
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const fs = require('fs');
const ms = require('ms');
const EggCore = require('egg-core').EggCore;
const cluster = require('cluster-client');
const extend = require('extend2');
Expand Down Expand Up @@ -57,7 +58,11 @@ class EggApplication extends EggCore {

// dump config after ready, ensure all the modifications during start will be recorded
// make sure dumpConfig is the last ready callback
this.ready(() => process.nextTick(() => this.dumpConfig()));
this.ready(() => process.nextTick(() => {
const dumpStartTime = Date.now();
this.dumpConfig();
this.coreLogger.info('[egg:core] dump config after ready, %s', ms(Date.now() - dumpStartTime));
}));
this._setupTimeoutTimer();

this.console.info('[egg:core] App root: %s', this.baseDir);
Expand Down
2 changes: 1 addition & 1 deletion test/lib/cluster/app_worker.test.js
Expand Up @@ -78,7 +78,7 @@ describe('test/lib/cluster/app_worker.test.js', () => {
version[0] > 9) {
html = new RegExp(
'GET /foo bar HTTP/1.1\r\nHost: 127.0.0.1:\\d+\r\nAccept-Encoding: gzip, ' +
'deflate\r\nUser-Agent: node-superagent/3.8.2\r\nConnection: close\r\n\r\n');
'deflate\r\nUser-Agent: node-superagent/\\d+\\.\\d+\\.\\d+\r\nConnection: close\r\n\r\n');
}

// customized client error response
Expand Down
12 changes: 12 additions & 0 deletions test/lib/egg.test.js
Expand Up @@ -97,6 +97,18 @@ describe('test/lib/egg.test.js', () => {
});
app.dumpConfig();
});

it('should has log', () => {
const eggLogPath = utils.getFilepath('apps/demo/logs/demo/egg-web.log');
let content = fs.readFileSync(eggLogPath, 'utf8');
assert(/\[egg:core] dump config after load, \d+ms/.test(content));
assert(/\[egg:core] dump config after ready, \d+ms/.test(content));

const agentLogPath = utils.getFilepath('apps/demo/logs/demo/egg-agent.log');
content = fs.readFileSync(agentLogPath, 'utf8');
assert(/\[egg:core] dump config after load, \d+ms/.test(content));
assert(/\[egg:core] dump config after ready, \d+ms/.test(content));
});
});

describe('dumpConfig() dynamically', () => {
Expand Down

0 comments on commit 824200c

Please sign in to comment.