mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
commit
0afef17629
@ -3,7 +3,7 @@
|
|||||||
const { test } = require('ava');
|
const { test } = require('ava');
|
||||||
const UnleashClientMetrics = require('./index');
|
const UnleashClientMetrics = require('./index');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const sinon = require('sinon');
|
const lolex = require('lolex');
|
||||||
|
|
||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ test('should work without state', t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.cb('data should expire', t => {
|
test.cb('data should expire', t => {
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = lolex.install();
|
||||||
|
|
||||||
const store = new EventEmitter();
|
const store = new EventEmitter();
|
||||||
const metrics = new UnleashClientMetrics(store);
|
const metrics = new UnleashClientMetrics(store);
|
||||||
@ -59,7 +59,7 @@ test.cb('data should expire', t => {
|
|||||||
t.true(lastMinExpires === 1);
|
t.true(lastMinExpires === 1);
|
||||||
t.true(lastHourExpires === 1);
|
t.true(lastHourExpires === 1);
|
||||||
|
|
||||||
clock.restore();
|
clock.uninstall();
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ test('should handle a lot of toggles', t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should have correct values for lastMinute', t => {
|
test('should have correct values for lastMinute', t => {
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = lolex.install();
|
||||||
|
|
||||||
const store = new EventEmitter();
|
const store = new EventEmitter();
|
||||||
const metrics = new UnleashClientMetrics(store);
|
const metrics = new UnleashClientMetrics(store);
|
||||||
@ -251,11 +251,11 @@ test('should have correct values for lastMinute', t => {
|
|||||||
t.deepEqual(c.lastMinute.toggle, { yes: 0, no: 0 });
|
t.deepEqual(c.lastMinute.toggle, { yes: 0, no: 0 });
|
||||||
|
|
||||||
metrics.destroy();
|
metrics.destroy();
|
||||||
clock.restore();
|
clock.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should have correct values for lastHour', t => {
|
test('should have correct values for lastHour', t => {
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = lolex.install();
|
||||||
|
|
||||||
const store = new EventEmitter();
|
const store = new EventEmitter();
|
||||||
const metrics = new UnleashClientMetrics(store);
|
const metrics = new UnleashClientMetrics(store);
|
||||||
@ -333,7 +333,7 @@ test('should have correct values for lastHour', t => {
|
|||||||
t.deepEqual(c.lastHour.toggle, { yes: 0, no: 0 });
|
t.deepEqual(c.lastHour.toggle, { yes: 0, no: 0 });
|
||||||
|
|
||||||
metrics.destroy();
|
metrics.destroy();
|
||||||
clock.restore();
|
clock.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not fail when toggle metrics is missing yes/no field', t => {
|
test('should not fail when toggle metrics is missing yes/no field', t => {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const { test } = require('ava');
|
const { test } = require('ava');
|
||||||
const TTLList = require('./ttl-list');
|
const TTLList = require('./ttl-list');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const sinon = require('sinon');
|
const lolex = require('lolex');
|
||||||
|
|
||||||
test.cb('should emit expire', t => {
|
test.cb('should emit expire', t => {
|
||||||
const list = new TTLList({
|
const list = new TTLList({
|
||||||
@ -22,7 +22,7 @@ test.cb('should emit expire', t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.cb('should slice off list', t => {
|
test.cb('should slice off list', t => {
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = lolex.install();
|
||||||
|
|
||||||
const list = new TTLList({
|
const list = new TTLList({
|
||||||
interval: 10,
|
interval: 10,
|
||||||
@ -55,8 +55,7 @@ test.cb('should slice off list', t => {
|
|||||||
t.true(expired.length === 4);
|
t.true(expired.length === 4);
|
||||||
|
|
||||||
list.destroy();
|
list.destroy();
|
||||||
clock.restore();
|
clock.uninstall();
|
||||||
sinon.restore();
|
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { test } = require('ava');
|
const { test } = require('ava');
|
||||||
const ClientMetricStore = require('./client-metrics-store');
|
const ClientMetricStore = require('./client-metrics-store');
|
||||||
const sinon = require('sinon');
|
const lolex = require('lolex');
|
||||||
|
|
||||||
function getMockDb() {
|
function getMockDb() {
|
||||||
const list = [
|
const list = [
|
||||||
@ -38,7 +38,7 @@ test.cb('should call database on startup', t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.cb('should poll for updates', t => {
|
test.cb('should poll for updates', t => {
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = lolex.install();
|
||||||
|
|
||||||
const mock = getMockDb();
|
const mock = getMockDb();
|
||||||
const store = new ClientMetricStore(mock, 100);
|
const store = new ClientMetricStore(mock, 100);
|
||||||
@ -55,7 +55,7 @@ test.cb('should poll for updates', t => {
|
|||||||
t.true(metrics.length === 4);
|
t.true(metrics.length === 4);
|
||||||
t.true(store.highestIdSeen === 4);
|
t.true(store.highestIdSeen === 4);
|
||||||
store.destroy();
|
store.destroy();
|
||||||
clock.restore();
|
clock.uninstall();
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -8,8 +8,10 @@ exports.startMonitoring = (enable, eventBus) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = require('prom-client');
|
const client = require('prom-client');
|
||||||
|
const gcStats = require('prometheus-gc-stats');
|
||||||
|
|
||||||
client.collectDefaultMetrics();
|
client.collectDefaultMetrics();
|
||||||
|
gcStats()();
|
||||||
|
|
||||||
const requestDuration = new client.Summary({
|
const requestDuration = new client.Summary({
|
||||||
name: 'http_request_duration_milliseconds',
|
name: 'http_request_duration_milliseconds',
|
||||||
|
@ -19,6 +19,6 @@ test('should collect metrics for requests', t => {
|
|||||||
const metrics = prometheusRegister.metrics();
|
const metrics = prometheusRegister.metrics();
|
||||||
t.regex(
|
t.regex(
|
||||||
metrics,
|
metrics,
|
||||||
/http_request_duration_milliseconds{quantile="0.99",status="200",method="GET",path="somePath"} 1337/
|
/http_request_duration_milliseconds{quantile="0\.99",path="somePath",method="GET",status="200"} 1337/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,8 @@
|
|||||||
"moment": "^2.15.2",
|
"moment": "^2.15.2",
|
||||||
"parse-database-url": "^0.3.0",
|
"parse-database-url": "^0.3.0",
|
||||||
"pg": "^6.4.2",
|
"pg": "^6.4.2",
|
||||||
"prom-client": "^9.1.1",
|
"prom-client": "^10.0.4",
|
||||||
|
"prometheus-gc-stats": "^0.5.0",
|
||||||
"response-time": "^2.3.2",
|
"response-time": "^2.3.2",
|
||||||
"serve-favicon": "^2.3.0",
|
"serve-favicon": "^2.3.0",
|
||||||
"unleash-frontend": "^3.0.0-alpha.1",
|
"unleash-frontend": "^3.0.0-alpha.1",
|
||||||
@ -82,17 +83,17 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^8.0.4",
|
"@types/node": "^8.0.4",
|
||||||
"ava": "^0.20.0",
|
"ava": "^0.22.0",
|
||||||
"coveralls": "^2.11.16",
|
"coveralls": "^2.11.16",
|
||||||
"eslint": "^4.1.1",
|
"eslint": "^4.1.1",
|
||||||
"eslint-config-finn": "^2.0.0",
|
"eslint-config-finn": "^2.0.0",
|
||||||
"eslint-config-finn-prettier": "^3.0.0",
|
"eslint-config-finn-prettier": "^3.0.0",
|
||||||
"husky": "^0.14.1",
|
"husky": "^0.14.1",
|
||||||
"lint-staged": "^4.0.0",
|
"lint-staged": "^4.0.0",
|
||||||
|
"lolex": "^2.1.2",
|
||||||
"nyc": "^11.0.3",
|
"nyc": "^11.0.3",
|
||||||
"prettier": "^1.5.2",
|
"prettier": "^1.5.2",
|
||||||
"proxyquire": "^1.7.11",
|
"proxyquire": "^1.7.11",
|
||||||
"sinon": "^2.3.5",
|
|
||||||
"superagent": "^3.5.0",
|
"superagent": "^3.5.0",
|
||||||
"supertest": "^3.0.0",
|
"supertest": "^3.0.0",
|
||||||
"supervisor": "^0.12.0"
|
"supervisor": "^0.12.0"
|
||||||
|
@ -24,8 +24,8 @@ done
|
|||||||
|
|
||||||
export TEST_DATABASE_URL=postgres://postgres:$POSTGRES_PASSWORD@$database_host:$PGPORT/postgres
|
export TEST_DATABASE_URL=postgres://postgres:$POSTGRES_PASSWORD@$database_host:$PGPORT/postgres
|
||||||
|
|
||||||
npm install
|
yarn
|
||||||
DATABASE_URL=$TEST_DATABASE_URL ./node_modules/.bin/db-migrate up
|
DATABASE_URL=$TEST_DATABASE_URL ./node_modules/.bin/db-migrate up
|
||||||
npm test
|
yarn test
|
||||||
docker stop $HASH
|
docker stop $HASH
|
||||||
docker rm $HASH
|
docker rm $HASH
|
||||||
|
Loading…
Reference in New Issue
Block a user