Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(metrics): health check #274

Merged
merged 3 commits into from
Aug 13, 2020
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
12 changes: 5 additions & 7 deletions __tests__/server/middleware/healthCheck.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ jest.mock('holocron', () => ({
getModule: jest.fn(),
}));

jest.mock('pidusage', () => ({
stat: jest.fn(),
}));
jest.mock('pidusage', () => jest.fn());

jest.mock('../../../src/server/utils/stateConfig', () => ({
getClientStateConfig: jest.fn(() => ({
Expand Down Expand Up @@ -150,7 +148,7 @@ describe('healthCheck', () => {

describe('middleware', () => {
it('should return a 200 when all is good', async () => {
pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, {
pidusage.mockImplementationOnce((pid, cb) => cb(undefined, {
cpu: 80,
memory: 1.4e9,
}));
Expand All @@ -165,7 +163,7 @@ describe('healthCheck', () => {
});

it('should return a 207 when the module map is not healthy', async () => {
pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, {
pidusage.mockImplementationOnce((pid, cb) => cb(undefined, {
cpu: 80,
memory: 1.4e9,
}));
Expand All @@ -180,7 +178,7 @@ describe('healthCheck', () => {
});

it('should return a 503 when any threshold has been passed', async () => {
pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, {
pidusage.mockImplementationOnce((pid, cb) => cb(undefined, {
cpu: 80.1,
memory: 1.4e9,
}));
Expand All @@ -195,7 +193,7 @@ describe('healthCheck', () => {
});

it('should return a 500 if it can\'t get the stats', async () => {
pidusage.stat.mockImplementationOnce((pid, cb) => cb(new Error('no stats')));
pidusage.mockImplementationOnce((pid, cb) => cb(new Error('no stats')));
getModule.mockReturnValueOnce(() => 0);
getModuleMapHealth.mockReturnValueOnce(true);
await healthCheck(req, res);
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/healthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getModule } from 'holocron';
import { getClientStateConfig } from '../utils/stateConfig';
import { getModuleMapHealth } from '../utils/pollModuleMap';

const getProcessStats = (pid) => promisify((cb) => pidusage.stat(pid, cb))();
const getProcessStats = (pid) => promisify((cb) => pidusage(pid, cb))();

export const getTickDelay = () => new Promise((resolve) => {
const time = process.hrtime();
Expand Down