2016-12-04 14:09:37 +01:00
|
|
|
'use strict';
|
2016-12-01 18:10:25 +01:00
|
|
|
|
|
|
|
const test = require('ava');
|
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
const { REQUEST_TIME } = require('./events');
|
|
|
|
const { startMonitoring } = require('./metrics');
|
|
|
|
const prometheusRegister = require('prom-client/lib/register');
|
|
|
|
|
|
|
|
test('should collect metrics for requests', t => {
|
|
|
|
startMonitoring(true, eventBus);
|
|
|
|
eventBus.emit(REQUEST_TIME, { path: 'somePath', method: 'GET', statusCode: 200, time: 1337 });
|
2016-12-04 14:09:37 +01:00
|
|
|
|
2016-12-01 18:10:25 +01:00
|
|
|
const metrics = prometheusRegister.metrics();
|
2016-12-04 14:09:37 +01:00
|
|
|
t.regex(metrics, /http_request_duration_milliseconds{quantile="0.99",status="200",method="GET",path="somePath"} 1337/);
|
|
|
|
});
|