Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #412 from 3box/release/v1.14.26
Browse files Browse the repository at this point in the history
Release/v1.14.26
  • Loading branch information
zachferland authored Jul 17, 2020
2 parents c06d891 + 7dcbf8f commit e0b1080
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 47 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

### v1.14.26 - 2020-07-17
* chore: healthcheck mem/cpu limit config, default low
* feat: healthcheck enable

### v1.14.25 - 2020-07-08
* feat: s3 cache ttl opt, 60 secs

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3box-pinning-node",
"version": "1.14.25",
"version": "1.14.26",
"description": "IPFS Node that runs OrbitDB under the hood",
"main": "src/node.js",
"scripts": {
Expand Down
60 changes: 30 additions & 30 deletions src/__tests__/healthcheckService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@ describe('HealthcheckService', () => {

beforeEach(() => {
isOnlineMock = jest.spyOn(pinning.ipfs, 'isOnline').mockReturnValue(true)
cpuFreeMock.mockImplementation(cb => cb(0.8)) // eslint-disable-line standard/no-callback-literal
freememPercentageMock.mockReturnValue(0.8)
cpuFreeMock.mockImplementation(cb => cb(0.6)) // eslint-disable-line standard/no-callback-literal
freememPercentageMock.mockReturnValue(0.85)
})

afterEach(() => {
jest.resetModules()
isOnlineMock.mockRestore()
})

// it('should return a failure if IPFS isn\'t online', async (done) => {
// isOnlineMock.mockReturnValue(false)
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })

// it('should return a failure on low cpu', async (done) => {
// cpuFreeMock.mockImplementation(cb => cb(0.01)) // eslint-disable-line standard/no-callback-literal
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })

// it('should return a failure on low memory', async (done) => {
// freememPercentageMock.mockReturnValue(0.01)
//
// request(healthcheckService.app)
// .get('/healthcheck')
// .expect(503)
// .end(done)
// })

it('should return a succes if memory, cpu and IPFS status are OK', async (done) => {
it('should return a failure if IPFS isn\'t online', async (done) => {
isOnlineMock.mockReturnValue(false)

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})

it('should return a failure on low cpu', async (done) => {
cpuFreeMock.mockImplementation(cb => cb(0.01)) // eslint-disable-line standard/no-callback-literal

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})

it('should return a failure on low memory', async (done) => {
freememPercentageMock.mockReturnValue(0.01)

request(healthcheckService.app)
.get('/healthcheck')
.expect(503)
.end(done)
})

it('should return a success if memory, cpu and IPFS status are OK', async (done) => {
request(healthcheckService.app)
.get('/healthcheck')
.expect(200)
Expand Down
18 changes: 10 additions & 8 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ class Analytics {

// backwards compatible, pindb for dbs with address links not in rootstore
trackPinDBAddress (address) {
const data = {}
data.event = 'pin_db_address'
data.properties = { address_hash: hash(address) }
this._track(data, hash(address))
// Temporary
// const data = {}
// data.event = 'pin_db_address'
// data.properties = { address_hash: hash(address) }
// this._track(data, hash(address))
}

trackSyncDB (odbAddress) {
const data = {}
data.event = 'sync_db'
data.properties = { address: odbAddress }
this._track(data)
// Temporary
// const data = {}
// data.event = 'sync_db'
// data.properties = { address: odbAddress }
// this._track(data)
}

trackInfraMetrics () {
Expand Down
23 changes: 15 additions & 8 deletions src/healthcheckService.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
const express = require('express')
// const os = require('os-utils')
const os = require('os-utils')

const { createLogger } = require('./logger')

const HEALTH_CPU_LIMIT_PERCENT = (process.env.HEALTH_CPU_LIMIT || 50) / 100
// Temporarily Low Default, Mem Leak
const HEALTH_MEM_LIMIT_PERCENT = (process.env.HEALTH_MEM_LIMIT || 20) / 100

class HealthcheckService {
constructor (pinning, port) {
this.pinning = pinning
this.port = port
this.logger = createLogger({ name: 'healthcheckService' })

this.app = express()

this.app.get('/healthcheck', this.healthcheckHandler.bind(this))
}

async healthcheckHandler (req, res, next) {
// if (!this.pinning.ipfs.isOnline()) return res.status(503).send()
// const cpuFree = await new Promise((resolve, reject) => os.cpuFree(resolve))
// const memFree = os.freememPercentage()
// if (cpuFree < 0.05 || memFree < 0.20) return res.status(503).send()
// if (memFree < 0.20) return res.status(503).send()
if (!this.pinning.ipfs.isOnline()) {
return res.status(503).send()
}

const cpu = 1 - (await new Promise((resolve, reject) => os.cpuFree(resolve)))
const mem = 1 - os.freememPercentage()

if (cpu > HEALTH_CPU_LIMIT_PERCENT || mem > HEALTH_MEM_LIMIT_PERCENT) {
return res.status(503).send()
}
return res.status(200).send()
}

Expand Down

0 comments on commit e0b1080

Please sign in to comment.