diff --git a/creator-node/src/config.js b/creator-node/src/config.js index 44eb84c0131..6ee0ef1bc31 100644 --- a/creator-node/src/config.js +++ b/creator-node/src/config.js @@ -607,6 +607,12 @@ const config = convict({ env: 'enableAsyncIPFSAdd', // TODO: probably want to change this to true if only hashing logic + async ipfs add is proven worthwhile default: false + }, + healthCheckIpfsTimeoutMs: { + doc: 'Default timeout for the ipfs health check route in timing add content', + format: 'nat', + env: 'healthCheckIpfsTimeoutMs', + default: 30000 // 30s } /** diff --git a/creator-node/src/monitors/ipfs.js b/creator-node/src/monitors/ipfs.js index fceab40c61e..69aa75c1ac4 100644 --- a/creator-node/src/monitors/ipfs.js +++ b/creator-node/src/monitors/ipfs.js @@ -23,7 +23,7 @@ const getIPFSReadWriteStatus = async () => { throw new Error('Read bytes differ from written bytes') } - const duration = `${Date.now() - start}ms` + const duration = Date.now() - start return JSON.stringify({ hash, duration }) } catch (e) { diff --git a/creator-node/src/monitors/monitors.js b/creator-node/src/monitors/monitors.js index 9fd6196b5b0..f1df6de943e 100644 --- a/creator-node/src/monitors/monitors.js +++ b/creator-node/src/monitors/monitors.js @@ -163,7 +163,7 @@ const REDIS_TOTAL_MEMORY = { const IPFS_READ_WRITE_STATUS = { name: 'IPFSReadWriteStatus', func: getIPFSReadWriteStatus, - ttl: 60 * 5, + ttl: 60 * 1, type: 'json' } diff --git a/creator-node/src/routes/healthCheck.js b/creator-node/src/routes/healthCheck.js index b58601ca1c8..222c2537055 100644 --- a/creator-node/src/routes/healthCheck.js +++ b/creator-node/src/routes/healthCheck.js @@ -9,6 +9,7 @@ const { const DiskManager = require('../diskManager') const MAX_DB_CONNECTIONS = config.get('dbConnectionPoolMax') +const HEALTH_CHECK_IPFS_TIMEOUT_MS = config.get('healthCheckIpfsTimeoutMs') module.exports = function (app) { /** @@ -19,13 +20,20 @@ module.exports = function (app) { return errorResponseServerError() } + const timeout = parseInt(req.query.timeout) || HEALTH_CHECK_IPFS_TIMEOUT_MS + const [value] = await getMonitors([MONITORS.IPFS_READ_WRITE_STATUS]) if (!value) { return errorResponseServerError({ error: 'IPFS not healthy' }) } const { hash, duration } = value - return successResponse({ hash, duration }) + + if (duration > timeout) { + return errorResponseServerError({ error: `IPFS took over the specified timeout of ${timeout}ms. Time taken ${duration}ms` }) + } + + return successResponse({ hash, duration: `${duration}ms` }) })) /**