Last active
February 23, 2021 05:59
-
-
Save manjeshpv/106dc2e05d4b9f252dc9f3f41afccb59 to your computer and use it in GitHub Desktop.
Without Restart Dynamically enable/disable debug in runtime via API [NOT IDEAL if u running pm2 cluster mode]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug'); | |
const log = debug('namespace1') | |
const express = require('express'); | |
const app = express(); | |
app.get('/', (req, res) => { | |
log('Homepage loading') | |
res.json({ title: 'Homepage' }); | |
}) | |
app.get('/enable', (req, res) => { | |
if(!req.query.tag) return res.json({ | |
message: 'req.query.tag missing' | |
}) | |
// - Enable Debug Namespace | |
debug.enable(req.query.tag); | |
log(`Enabled debug namespace: ${req.query.tag} in runtime`). | |
res.json({ | |
status: debug.enabled(req.query.tag) | |
}) | |
}) | |
app.get('/disable', (req, res) => { | |
log('Disabling debug dynamically in runtime'). | |
debug.disable(); | |
res.json({ status: debug.enabled(req.query.tag || '*') }) | |
}) | |
app.listen(8090, () => { | |
console.log('express listeing at http://localhost:8090') | |
}) |
comments by @yogesum
- Service is run in cluster mode. This will not work
- For each one we need to hit
- Better would be passing signal to each worker via command line or some endpoint which gets served by master worker
Another way to control is using flagr. That will provide us with way to update flag on Flagr Server UI and only authenticated user will be able to do it
@yogesum flagr solution looks like solving the issue of
- PM2 Cluster or Nodejs Cluster
- Multiple Physical app servers behind load balancer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Docs
on first terminal
on second terminal