(req, res, cb)
| 220 | registry.clusterMetrics.bind(registry) : registry.metrics.bind(registry); |
| 221 | |
| 222 | async function routeHandler(req, res, cb) { |
| 223 | if (req.method !== 'GET') { |
| 224 | return cb(errors.BadRequest, []); |
| 225 | } |
| 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 | |
| 235 | const contentLen = Buffer.byteLength(promMetrics, 'utf8'); |
| 236 | res.writeHead(200, { |
| 237 | 'Content-Length': contentLen, |
| 238 | 'Content-Type': registry.contentType, |
| 239 | }); |
| 240 | res.end(promMetrics); |
| 241 | return undefined; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Checks if client IP address is allowed to make http request to |
no test coverage detected