* Calls each client's healthcheck and translates responses to * InternalError message if appropriate * @param {boolean} flightCheckOnStartUp - whether client check is a flight * check on startup. If performing a flight check, behavior is: * - return an error to halt start-up if there is any err
(flightCheckOnStartUp, log, cb)
| 41 | * @return {undefined} |
| 42 | */ |
| 43 | function clientCheck(flightCheckOnStartUp, log, cb) { |
| 44 | const clients = [ |
| 45 | data, |
| 46 | metadata, |
| 47 | vault, |
| 48 | kms, |
| 49 | ]; |
| 50 | const clientTasks = []; |
| 51 | clients.forEach(client => { |
| 52 | if (typeof client.checkHealth === 'function') { |
| 53 | clientTasks.push(done => { |
| 54 | client.checkHealth(log, done, flightCheckOnStartUp); |
| 55 | }); |
| 56 | } |
| 57 | }); |
| 58 | async.parallel(clientTasks, (err, results) => { |
| 59 | // obj will be an object of the healthcheck results of |
| 60 | // every backends. No errors were returned directly to |
| 61 | // async.parallel in order to complete the check, so a |
| 62 | // manual check makes S3 return 500 error if any backend failed |
| 63 | // other than aws_s3 or azure |
| 64 | // Check if any client has ALL its backends/locations failing. |
| 65 | // Each result in the array represents one client (data, metadata, vault, kms) |
| 66 | // with its backend locations as keys. |
| 67 | // If ALL backend/locations of ANY client have errors, the overall check fails. |
| 68 | const { obj, fail } = results.reduce((acc, clientResult) => { |
| 69 | Object.assign(acc.obj, clientResult); |
| 70 | |
| 71 | // Check if ALL backends/locations of this client have errors |
| 72 | const keys = Object.keys(clientResult); |
| 73 | // eslint-disable-next-line no-param-reassign |
| 74 | acc.fail ||= keys.length > 0 && keys.every(k => |
| 75 | // if there is an error from an external backend, |
| 76 | // only return a 500 if it is on startup |
| 77 | // (flightCheckOnStartUp set to true) |
| 78 | clientResult[k].error && (flightCheckOnStartUp || !clientResult[k].external) |
| 79 | ); |
| 80 | |
| 81 | return acc; |
| 82 | }, { obj: {}, fail: false }); |
| 83 | if (fail) { |
| 84 | return cb(errors.InternalError, obj); |
| 85 | } |
| 86 | return cb(null, obj); |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | function routeHandler(deep, req, res, log, statsClient, cb) { |
| 91 | if (!isHealthy()) { |
no test coverage detected