Skip to content

Commit 5c9c473

Browse files
CLDSRV-717: Prometheus use aggregate registry
for cluster mode
1 parent 00f5cf8 commit 5c9c473

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

lib/utilities/monitoringHandler.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,27 @@ function writeResponse(res, error, results, cb) {
215215
});
216216
}
217217

218+
const registry = config.isCluster ? new client.AggregatorRegistry() : client.register;
219+
const getMetrics = config.isCluster ?
220+
registry.clusterMetrics.bind(registry) : registry.metrics.bind(registry);
218221

219222
async function routeHandler(req, res, cb) {
220223
if (req.method !== 'GET') {
221224
return cb(errors.BadRequest, []);
222225
}
223-
const promMetrics = await client.register.metrics();
226+
let promMetrics;
227+
try {
228+
// Catch timeout on IPC between worker and primary
229+
// prom-client has a 5s hardcoded timeout
230+
promMetrics = await getMetrics();
231+
} catch (err) {
232+
return cb(err, { message: err.toString() });
233+
}
234+
224235
const contentLen = Buffer.byteLength(promMetrics, 'utf8');
225236
res.writeHead(200, {
226237
'Content-Length': contentLen,
227-
'Content-Type': client.register.contentType,
238+
'Content-Type': registry.contentType,
228239
});
229240
res.end(promMetrics);
230241
return undefined;

0 commit comments

Comments
 (0)