From e9938d9a5bdfacde85db2c280b073c0fc3d3ab6b Mon Sep 17 00:00:00 2001 From: sveisvei Date: Mon, 5 Dec 2016 13:27:08 +0100 Subject: [PATCH] add getAppsFromToggleName --- lib/client-metrics/index.js | 13 +++++++++++++ lib/routes/metrics.js | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/lib/client-metrics/index.js b/lib/client-metrics/index.js index 26189e61fd..3be23879f6 100644 --- a/lib/client-metrics/index.js +++ b/lib/client-metrics/index.js @@ -47,6 +47,19 @@ module.exports = class UnleashClientMetrics { return this.apps[appName] ? Object.keys(this.apps[appName].seenToggles) : []; } + getAppsFromToggleName (toggleName) { + const apps = []; + Object.keys(this.apps).forEach(appName => { + const seenToggles = Object.keys(this.apps[appName].seenToggles); + if (seenToggles.includes(toggleName)) { + apps.push({ + appName, + }); + } + }); + return apps; + } + getTogglesMetrics () { return { lastHour: this.lastHourProjection.getProjection(), diff --git a/lib/routes/metrics.js b/lib/routes/metrics.js index 1e420a9b45..9510032d88 100644 --- a/lib/routes/metrics.js +++ b/lib/routes/metrics.js @@ -20,6 +20,11 @@ module.exports = function (app, config) { res.json(seenAppToggles); }); + app.get('/client/seen-apps/:name', (req, res) => { + const seenApps = metrics.getAppsFromToggleName(req.params.name); + res.json(seenApps); + }); + app.get('/client/metrics/feature-toggles', (req, res) => { res.json(metrics.getTogglesMetrics()); });