From 8ac0b2539435a1268a1c3b81b55041be13d54a0d Mon Sep 17 00:00:00 2001 From: Vicky Date: Thu, 28 Oct 2021 16:29:58 -0700 Subject: [PATCH 1/3] configurable qs for ipfs add timeout --- creator-node/src/config.js | 6 ++++++ creator-node/src/routes/healthCheck.js | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/creator-node/src/config.js b/creator-node/src/config.js index 44eb84c0131..cb0ddcb8045 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: 10000 // 10s } /** diff --git a/creator-node/src/routes/healthCheck.js b/creator-node/src/routes/healthCheck.js index b58601ca1c8..3287d8160ed 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,12 +20,19 @@ module.exports = function (app) { return errorResponseServerError() } + const timeout = 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 + + if (duration > timeout) { + return errorResponseServerError({ error: `IPFS took over the specified timeout of ${timeout}ms. Time taken ${duration}ms` }) + } + return successResponse({ hash, duration }) })) From f82af669df0c019ae46c9048d744e6479741d11d Mon Sep 17 00:00:00 2001 From: Vicky Date: Thu, 28 Oct 2021 23:49:17 +0000 Subject: [PATCH 2/3] update date to be number + lower ttl to 1min --- creator-node/src/monitors/ipfs.js | 2 +- creator-node/src/monitors/monitors.js | 2 +- creator-node/src/routes/healthCheck.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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 3287d8160ed..222c2537055 100644 --- a/creator-node/src/routes/healthCheck.js +++ b/creator-node/src/routes/healthCheck.js @@ -20,7 +20,7 @@ module.exports = function (app) { return errorResponseServerError() } - const timeout = req.query.timeout || HEALTH_CHECK_IPFS_TIMEOUT_MS + const timeout = parseInt(req.query.timeout) || HEALTH_CHECK_IPFS_TIMEOUT_MS const [value] = await getMonitors([MONITORS.IPFS_READ_WRITE_STATUS]) if (!value) { @@ -33,7 +33,7 @@ module.exports = function (app) { return errorResponseServerError({ error: `IPFS took over the specified timeout of ${timeout}ms. Time taken ${duration}ms` }) } - return successResponse({ hash, duration }) + return successResponse({ hash, duration: `${duration}ms` }) })) /** From 5cc8f10e82ec37afbb7285d129e65adc08cda446 Mon Sep 17 00:00:00 2001 From: Vicky Date: Fri, 29 Oct 2021 00:00:38 +0000 Subject: [PATCH 3/3] bump health chehck ipfs timeout to 30s --- creator-node/src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/creator-node/src/config.js b/creator-node/src/config.js index cb0ddcb8045..6ee0ef1bc31 100644 --- a/creator-node/src/config.js +++ b/creator-node/src/config.js @@ -612,7 +612,7 @@ const config = convict({ doc: 'Default timeout for the ipfs health check route in timing add content', format: 'nat', env: 'healthCheckIpfsTimeoutMs', - default: 10000 // 10s + default: 30000 // 30s } /**