Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions creator-node/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/monitors/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/monitors/monitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
10 changes: 9 additions & 1 deletion creator-node/src/routes/healthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/**
Expand All @@ -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` })
}))

/**
Expand Down