diff --git a/lib/client-metrics/index.js b/lib/client-metrics/index.js index 3be23879f6..be25954b9b 100644 --- a/lib/client-metrics/index.js +++ b/lib/client-metrics/index.js @@ -47,17 +47,17 @@ module.exports = class UnleashClientMetrics { return this.apps[appName] ? Object.keys(this.apps[appName].seenToggles) : []; } - getAppsFromToggleName (toggleName) { - const apps = []; + getSeenAppsPerToggle () { + const toggles = {}; Object.keys(this.apps).forEach(appName => { - const seenToggles = Object.keys(this.apps[appName].seenToggles); - if (seenToggles.includes(toggleName)) { - apps.push({ - appName, - }); - } + Object.keys(this.apps[appName].seenToggles).forEach((seenToggleName) => { + if (!toggles[seenToggleName]) { + toggles[seenToggleName] = []; + } + toggles[seenToggleName].push(appName); + }); }); - return apps; + return toggles; } getTogglesMetrics () { diff --git a/lib/routes/metrics.js b/lib/routes/metrics.js index 9510032d88..81298ad910 100644 --- a/lib/routes/metrics.js +++ b/lib/routes/metrics.js @@ -20,8 +20,8 @@ module.exports = function (app, config) { res.json(seenAppToggles); }); - app.get('/client/seen-apps/:name', (req, res) => { - const seenApps = metrics.getAppsFromToggleName(req.params.name); + app.get('/client/seen-apps', (req, res) => { + const seenApps = metrics.getSeenAppsPerToggle(); res.json(seenApps); });