Skip to content

Commit acb39fb

Browse files
CLDSRV-717: Prometheus use aggregate registry
for cluster mode
1 parent 3a1731c commit acb39fb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/utilities/monitoringHandler.js

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

218+
const workers = process.env.S3BACKEND === 'mem' ? 1 : config.clusters || 1;
219+
const isCluster = workers > 1;
220+
const registry = isCluster ? new client.AggregatorRegistry() : client.register;
221+
const getMetrics = isCluster ?
222+
registry.clusterMetrics.bind(registry) : registry.metrics.bind(registry);
218223

219224
async function routeHandler(req, res, cb) {
220225
if (req.method !== 'GET') {
221226
return cb(errors.BadRequest, []);
222227
}
223-
const promMetrics = await client.register.metrics();
228+
let promMetrics;
229+
try {
230+
// Catch timeout on IPC between worker and primary
231+
// prom-client has a 5s hardcoded timeout
232+
promMetrics = await getMetrics();
233+
} catch (err) {
234+
return cb(err, { message: err.toString() });
235+
}
236+
224237
const contentLen = Buffer.byteLength(promMetrics, 'utf8');
225238
res.writeHead(200, {
226239
'Content-Length': contentLen,
227-
'Content-Type': client.register.contentType,
240+
'Content-Type': registry.contentType,
228241
});
229242
res.end(promMetrics);
230243
return undefined;

0 commit comments

Comments
 (0)