mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-16 00:06:40 +01:00
cdfba8f7b1
When an application updates metrics for a toggle we now stores the timestamp on the toggle when it was last seen used by an application. This will make it much easier to detect toggles not in use anymore. closes #642
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const Controller = require('../controller');
|
|
const { clientMetricsSchema } = require('./metrics-schema');
|
|
|
|
class ClientMetricsController extends Controller {
|
|
constructor(
|
|
{ clientMetricsStore, clientInstanceStore, featureToggleStore },
|
|
getLogger,
|
|
) {
|
|
super();
|
|
this.logger = getLogger('/api/client/metrics');
|
|
this.clientMetricsStore = clientMetricsStore;
|
|
this.clientInstanceStore = clientInstanceStore;
|
|
this.featureToggleStore = featureToggleStore;
|
|
|
|
this.post('/', this.registerMetrics);
|
|
}
|
|
|
|
async registerMetrics(req, res) {
|
|
const data = req.body;
|
|
const clientIp = req.ip;
|
|
|
|
const { error, value } = clientMetricsSchema.validate(data);
|
|
|
|
if (error) {
|
|
this.logger.warn('Invalid metrics posted', error);
|
|
return res.status(400).json(error);
|
|
}
|
|
|
|
try {
|
|
const toggleNames = Object.keys(value.bucket.toggles);
|
|
await this.featureToggleStore.lastSeenToggles(toggleNames);
|
|
await this.clientMetricsStore.insert(value);
|
|
await this.clientInstanceStore.insert({
|
|
appName: value.appName,
|
|
instanceId: value.instanceId,
|
|
clientIp,
|
|
});
|
|
return res.status(202).end();
|
|
} catch (e) {
|
|
this.logger.error('failed to store metrics', e);
|
|
return res.status(500).end();
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = ClientMetricsController;
|