mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Simplify metrics: We only need timings as it includes counts for free
This commit is contained in:
parent
e075917136
commit
471518b41d
@ -12,7 +12,7 @@ const routes = require('./routes');
|
||||
const path = require('path');
|
||||
const errorHandler = require('errorhandler');
|
||||
|
||||
const {REQUEST_TIME, REQUEST_STATUS} = require('./events');
|
||||
const {REQUEST_TIME} = require('./events');
|
||||
|
||||
module.exports = function (config) {
|
||||
const app = express();
|
||||
@ -30,8 +30,8 @@ module.exports = function (config) {
|
||||
}
|
||||
|
||||
app.use(responseTime((req, res, time) => {
|
||||
config.eventBus.emit(REQUEST_TIME, req.path, req.method, time);
|
||||
config.eventBus.emit(REQUEST_STATUS, req.path, req.method, res.statusCode);
|
||||
const timingInfo = { path: req.path, method: req.method, statusCode: res.statusCode, time };
|
||||
config.eventBus.emit(REQUEST_TIME, timingInfo);
|
||||
}));
|
||||
|
||||
app.use(validator([]));
|
||||
|
@ -1,8 +1,3 @@
|
||||
module.exports = {
|
||||
TOGGLES_FETCH: 'toggles:fetch',
|
||||
TOGGLES_CREATE: 'toggles:create',
|
||||
CLIENT_REGISTER: 'client:register',
|
||||
CLIENT_METRICS: 'toggles:metrics',
|
||||
REQUEST_TIME: 'request_time',
|
||||
REQUEST_STATUS: 'request_status'
|
||||
}
|
@ -6,33 +6,12 @@ exports.startMonitoring = (enable, eventBus) => {
|
||||
}
|
||||
|
||||
const client = require('prom-client');
|
||||
const toggleFetch = new client.Counter('toggles_fetch_counter', 'Number of fetch toggles request');
|
||||
|
||||
const requestDuration = new client.Summary('http_request_duration_milliseconds', 'App response time', ['uri', 'method'], {
|
||||
const requestDuration = new client.Summary('http_request_duration_milliseconds', 'App response time', ['path', 'method', 'status'], {
|
||||
percentiles: [0.1, 0.5, 0.9, 0.99],
|
||||
});
|
||||
const requestCount = new client.Counter('http_requests_total', 'HTTP request duration', ['uri', 'method', 'status']);
|
||||
|
||||
const clientRegister = new client.Counter('client_register_counter', 'Number client register requests');
|
||||
const clientMetrics = new client.Counter('client_metrics_counter', 'Number client metrics requests');
|
||||
|
||||
eventBus.on(events.TOGGLES_FETCH, () => {
|
||||
toggleFetch.inc();
|
||||
});
|
||||
|
||||
eventBus.on(events.CLIENT_REGISTER, () => {
|
||||
clientRegister.inc();
|
||||
});
|
||||
|
||||
eventBus.on(events.CLIENT_METRICS, () => {
|
||||
clientMetrics.inc();
|
||||
});
|
||||
|
||||
eventBus.on(events.REQUEST_TIME, (uri, method, time) => {
|
||||
requestDuration.labels(uri, method).observe(time);
|
||||
});
|
||||
|
||||
eventBus.on(events.REQUEST_STATUS, (uri, method, status) => {
|
||||
requestCount.labels(uri, method, status).inc();
|
||||
eventBus.on(events.REQUEST_TIME, ({path, method, time, statusCode}) => {
|
||||
requestDuration.labels(path, method, statusCode).observe(time);
|
||||
});
|
||||
};
|
16
lib/metrics.test.js
Normal file
16
lib/metrics.test.js
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
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 });
|
||||
|
||||
const metrics = prometheusRegister.metrics();
|
||||
t.regex(metrics, /http_request_duration_milliseconds{quantile="0.99",status="200",method="GET",path="somePath"} 1337/)
|
||||
|
||||
});
|
@ -8,8 +8,6 @@ const ValidationError = require('../error/validation-error.js');
|
||||
const validateRequest = require('../error/validate-request');
|
||||
const extractUser = require('../extract-user');
|
||||
|
||||
const { TOGGLES_FETCH } = require('../events');
|
||||
|
||||
const legacyFeatureMapper = require('../data-helper/legacy-feature-mapper');
|
||||
const version = 1;
|
||||
|
||||
@ -39,11 +37,8 @@ const handleErrors = (req, res, error) => {
|
||||
|
||||
module.exports = function (app, config) {
|
||||
const { featureToggleStore, eventStore } = config.stores;
|
||||
const { eventBus } = config;
|
||||
|
||||
app.get('/features', (req, res) => {
|
||||
eventBus.emit(TOGGLES_FETCH);
|
||||
|
||||
featureToggleStore.getFeatures()
|
||||
.then((features) => features.map(legacyFeatureMapper.addOldFields))
|
||||
.then(features => res.json({ version, features }));
|
||||
|
@ -4,7 +4,6 @@ const logger = require('../logger');
|
||||
const ClientMetrics = require('../client-metrics');
|
||||
const joi = require('joi');
|
||||
const { clientMetricsSchema, clientRegisterSchema } = require('./metrics-schema');
|
||||
const { CLIENT_REGISTER, CLIENT_METRICS } = require('../events');
|
||||
const { catchLogAndSendErrorResponse } = require('./route-utils');
|
||||
|
||||
module.exports = function (app, config) {
|
||||
@ -14,8 +13,6 @@ module.exports = function (app, config) {
|
||||
clientInstanceStore,
|
||||
} = config.stores;
|
||||
|
||||
const { eventBus } = config;
|
||||
|
||||
const metrics = new ClientMetrics(clientMetricsStore);
|
||||
|
||||
app.get('/client/seen-toggles', (req, res) => {
|
||||
@ -36,8 +33,6 @@ module.exports = function (app, config) {
|
||||
return res.status(400).json(err);
|
||||
}
|
||||
|
||||
eventBus.emit(CLIENT_METRICS);
|
||||
|
||||
clientMetricsStore
|
||||
.insert(cleaned)
|
||||
.then(() => clientInstanceStore.insert({
|
||||
@ -60,8 +55,6 @@ module.exports = function (app, config) {
|
||||
return res.status(400).json(err);
|
||||
}
|
||||
|
||||
eventBus.emit(CLIENT_REGISTER);
|
||||
|
||||
clientStrategyStore
|
||||
.insert(cleaned.appName, cleaned.strategies)
|
||||
.then(() => clientInstanceStore.insert({
|
||||
|
Loading…
Reference in New Issue
Block a user