-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero Downtime reload config capability #55
Conversation
vk4u
commented
Oct 6, 2016
- Introducing ability to reload microgateway for new config without dropping messages.
- Reloading is done using IPC through sockets.
- After this change, microgateway will always be starting in cluster mode.
- Owing to this there are 3 new commands added. Status, Reload, Stop.
…dropping messages. 2. Reloading is done using IPC through sockets. 3. After this change, microgateway will always be starting in cluster mode. 4. Owing to this there are 3 new commands added. Status, Reload, Stop.
.option('-e, --env <env>', 'the environment') | ||
.option('-k, --key <key>', 'key for authenticating with Edge') | ||
.option('-s, --secret <secret>', 'secret for authenticating with Edge') | ||
.description('reoad the edgemicro cluster by pulling new configuration') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reoad
typo.
Aside from the typo this looks ok to me. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great additions, just a few comments. Nice!
} | ||
} | ||
}); | ||
run.start(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing the callback because the success/error messages are logged in the start-agent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That is true. Moreover, the callback isn't available anymore. Because the we are passing the start file to cluster.setupMaster now.
opt.args = [JSON.stringify(args)]; | ||
opt.timeout = 10; | ||
|
||
var cluster = reloadCluster(path.join(__dirname, 'start-agent.js'), opt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be declared above line 66 so that the cluster
reference is obvious. Also, please rename cluster
to something else (perhaps mgCluster) so that it is not confused with the Node cluster module. When I see a variable named cluster in Node I think var cluster = require('cluster');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Made the changes.
edgeconfig.save(config, cache); | ||
} | ||
|
||
gateway(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this does nothing, please delete line 59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Ill remove it. But just curious to know what it was doing earlier ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great question, no idea, it's been there since this odd commit
d065991
for (var i = 0; i < numWorkers; i++) { | ||
cluster.fork(); | ||
} | ||
gateway(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, please remove line 136 (even though it was already present, may as well take the chance to clean it up)
2. Credits for code inspiration added
…eload incorporated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
@@ -107,6 +106,40 @@ Gateway.prototype.start = (options) => { | |||
process.exit(0); | |||
}); | |||
|
|||
var pollInterval = config.edgemicro.config_change_poll_interval ? config.edgemicro.config_change_poll_interval : defaultPollInterval; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var pollInterval = config.edgemicro.config_change_poll_interval || defaultPollInterval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
function hasConfigChanged(oldConfig, newConfig) { | ||
// This may not be the best way to do the check. But it works for now. | ||
if (JSON.stringify(oldConfig) == JSON.stringify(newConfig)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return JSON.stringify(oldConfig) != JSON.stringify(newConfig)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…as used for testing purposes)