mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
parent
a9674a9ddd
commit
bc359c2b82
@ -5,4 +5,15 @@
|
||||
Unleash uses prometheus internally to collect metrics. These are
|
||||
available on the given url if the `serverMetrics` option is enabled (default=true).
|
||||
|
||||
[Read more about Prometheus](https://prometheus.io/)
|
||||
[Read more about Prometheus](https://prometheus.io/)
|
||||
|
||||
## Annotations
|
||||
|
||||
Unleash will automatically count all updates for all toggles under the metric name `feature_toggle_update_total`, and the toggle name is will be set as a label value. This information can be used to create annotations in grafana for everytime a feature toggle is changed.
|
||||
|
||||
You can use this query in grafana to achive this:
|
||||
|
||||
```
|
||||
delta(feature_toggle_update_total{toggle="Demo"}[1m]) != bool 0?
|
||||
```
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const events = require('./events');
|
||||
const {
|
||||
FEATURE_CREATED,
|
||||
FEATURE_UPDATED,
|
||||
FEATURE_ARCHIVED,
|
||||
FEATURE_REVIVED,
|
||||
} = require('./event-type');
|
||||
|
||||
exports.startMonitoring = (enable, eventBus) => {
|
||||
exports.startMonitoring = (enable, eventBus, eventStore) => {
|
||||
if (!enable) {
|
||||
return;
|
||||
}
|
||||
@ -19,8 +25,26 @@ exports.startMonitoring = (enable, eventBus) => {
|
||||
labelNames: ['path', 'method', 'status'],
|
||||
percentiles: [0.1, 0.5, 0.9, 0.99],
|
||||
});
|
||||
const featureToggleUpdateTotal = new client.Counter({
|
||||
name: 'feature_toggle_update_total',
|
||||
help: 'Number of times a toggle has been updated',
|
||||
labelNames: ['toggle'],
|
||||
});
|
||||
|
||||
eventBus.on(events.REQUEST_TIME, ({ path, method, time, statusCode }) => {
|
||||
requestDuration.labels(path, method, statusCode).observe(time);
|
||||
});
|
||||
|
||||
eventStore.on(FEATURE_CREATED, ({ data }) => {
|
||||
featureToggleUpdateTotal.labels(data.name).inc();
|
||||
});
|
||||
eventStore.on(FEATURE_UPDATED, ({ data }) => {
|
||||
featureToggleUpdateTotal.labels(data.name).inc();
|
||||
});
|
||||
eventStore.on(FEATURE_ARCHIVED, ({ data }) => {
|
||||
featureToggleUpdateTotal.labels(data.name).inc();
|
||||
});
|
||||
eventStore.on(FEATURE_REVIVED, ({ data }) => {
|
||||
featureToggleUpdateTotal.labels(data.name).inc();
|
||||
});
|
||||
};
|
||||
|
@ -3,12 +3,17 @@
|
||||
const { test } = require('ava');
|
||||
const { EventEmitter } = require('events');
|
||||
const eventBus = new EventEmitter();
|
||||
const eventStore = new EventEmitter();
|
||||
const { REQUEST_TIME } = require('./events');
|
||||
const { FEATURE_UPDATED } = require('./event-type');
|
||||
const { startMonitoring } = require('./metrics');
|
||||
const { register: prometheusRegister } = require('prom-client');
|
||||
|
||||
test.before(() => {
|
||||
startMonitoring(true, eventBus, eventStore);
|
||||
});
|
||||
|
||||
test('should collect metrics for requests', t => {
|
||||
startMonitoring(true, eventBus);
|
||||
eventBus.emit(REQUEST_TIME, {
|
||||
path: 'somePath',
|
||||
method: 'GET',
|
||||
@ -22,3 +27,12 @@ test('should collect metrics for requests', t => {
|
||||
/http_request_duration_milliseconds{quantile="0\.99",path="somePath",method="GET",status="200"} 1337/
|
||||
);
|
||||
});
|
||||
|
||||
test('should collect metrics for updated toggles', t => {
|
||||
eventStore.emit(FEATURE_UPDATED, {
|
||||
data: { name: 'TestToggle' },
|
||||
});
|
||||
|
||||
const metrics = prometheusRegister.metrics();
|
||||
t.regex(metrics, /feature_toggle_update_total{toggle="TestToggle"} 1/);
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ function createApp(options) {
|
||||
);
|
||||
|
||||
const app = getApp(config);
|
||||
startMonitoring(options.serverMetrics, eventBus);
|
||||
startMonitoring(options.serverMetrics, eventBus, stores.eventStore);
|
||||
|
||||
const server = app.listen({ port: options.port, host: options.host }, () =>
|
||||
logger.info(`Unleash started on port ${server.address().port}`)
|
||||
|
Loading…
Reference in New Issue
Block a user