Compare commits

...

1 Commits

Author SHA1 Message Date
Jonathan Gramain 192ba81275 [wip] ZENKO-1520 stub for prom metrics endpoint in HealthProbeServer 2019-04-24 19:11:29 -07:00
1 changed files with 14 additions and 14 deletions

View File

@ -24,10 +24,6 @@ function sendSuccess(res, log, msg) {
res.end(message); res.end(message);
} }
function constructEndpoints(ns, path) {
return `/${ns}/${path}`;
}
function checkStub(log) { // eslint-disable-line function checkStub(log) { // eslint-disable-line
return true; return true;
} }
@ -38,17 +34,14 @@ class HealthProbeServer extends httpServer {
super(params.port, logging); super(params.port, logging);
this.logging = logging; this.logging = logging;
this.setBindAddress(params.bindAddress || 'localhost'); this.setBindAddress(params.bindAddress || 'localhost');
this._namespace = params.namespace || '_/health';
const livenessURI = constructEndpoints(this._namespace,
params.livenessURI || 'liveness');
const readinessURI = constructEndpoints(this._namespace,
params.readinessURI || 'readiness');
// hooking our request processing function by calling the // hooking our request processing function by calling the
// parent's method for that // parent's method for that
this.onRequest(this._onRequest); this.onRequest(this._onRequest);
this._reqHandlers = {}; this._reqHandlers = {
this._reqHandlers[livenessURI] = this._onLiveness.bind(this); '/_/health/liveness': this._onLiveness.bind(this),
this._reqHandlers[readinessURI] = this._onReadiness.bind(this); '/_/health/readiness': this._onReadiness.bind(this),
'/_/monitoring/metrics': this._onMetrics.bind(this),
};
this._livenessCheck = params.livenessCheck || checkStub; this._livenessCheck = params.livenessCheck || checkStub;
this._readinessCheck = params.readinessCheck || checkStub; this._readinessCheck = params.readinessCheck || checkStub;
} }
@ -68,8 +61,7 @@ class HealthProbeServer extends httpServer {
if (req.method !== 'GET') { if (req.method !== 'GET') {
sendError(res, log, errors.MethodNotAllowed); sendError(res, log, errors.MethodNotAllowed);
} }
if (req.url.startsWith(`/${this._namespace}`) && if (req.url in this._reqHandlers) {
req.url in this._reqHandlers) {
this._reqHandlers[req.url](req, res, log); this._reqHandlers[req.url](req, res, log);
} else { } else {
sendError(res, log, errors.InvalidURI); sendError(res, log, errors.InvalidURI);
@ -92,6 +84,14 @@ class HealthProbeServer extends httpServer {
} }
} }
_onMetrics(req, res, log) {
log.debug('metrics request received');
res.writeHead(200);
res.end(
'# HELP lifecycle_batches Number of lifecycle batches started\n' +
'# TYPE lifecycle_batches counter\n' +
'lifecycle_batches 42\n');
}
} }
module.exports = HealthProbeServer; module.exports = HealthProbeServer;