From aa0a297bc9061b54927abc4c467da1ffd3619c77 Mon Sep 17 00:00:00 2001 From: Phil Booth Date: Fri, 13 Oct 2017 16:50:57 +0100 Subject: [PATCH] fix(metrics): map service event property from client id (#5583), r=@vbudhram --- server/lib/amplitude.js | 4 +++- server/lib/configuration.js | 6 ++++++ tests/server/amplitude.js | 23 +++++++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/server/lib/amplitude.js b/server/lib/amplitude.js index d195535f6d..37e9435513 100644 --- a/server/lib/amplitude.js +++ b/server/lib/amplitude.js @@ -21,6 +21,8 @@ 'use strict'; +const SERVICES = require('./configuration').get('oauth_client_id_map'); + const APP_VERSION = /^[0-9]+\.([0-9]+)\./.exec(require('../../package.json').version)[1]; const GROUPS = { @@ -232,7 +234,7 @@ function mapEntrypoint (eventCategory, data) { function mapService (eventCategory, data) { const service = marshallOptionalValue(data.service); if (service) { - return { service }; + return { service: SERVICES[service] || service }; } } diff --git a/server/lib/configuration.js b/server/lib/configuration.js index 8d95689fb1..14094ad971 100644 --- a/server/lib/configuration.js +++ b/server/lib/configuration.js @@ -344,6 +344,12 @@ const conf = module.exports = convict({ env: 'FXA_OAUTH_CLIENT_ID', format: String }, + oauth_client_id_map: { + default: {}, + doc: 'Mappings from client id to service name: { "id1": "name-1", "id2": "name-2" }', + env: 'OAUTH_CLIENT_IDS', + format: Object + }, oauth_url: { default: 'http://127.0.0.1:9010', doc: 'The url of the Firefox Account OAuth server', diff --git a/tests/server/amplitude.js b/tests/server/amplitude.js index b42bbf6c67..dec8d50328 100644 --- a/tests/server/amplitude.js +++ b/tests/server/amplitude.js @@ -7,10 +7,21 @@ define([ 'intern!object', 'intern/chai!assert', + 'intern/dojo/node!path', + 'intern/dojo/node!proxyquire', 'intern/dojo/node!sinon', - 'intern/dojo/node!../../server/lib/amplitude', 'intern/dojo/node!../../package.json', -], (registerSuite, assert, sinon, amplitude, package) => { +], (registerSuite, assert, path, proxyquire, sinon, package) => { + const amplitude = proxyquire(path.resolve('server/lib/amplitude'), { + './configuration': { + get () { + return { + '0': 'amo', + '1': 'pocket' + }; + } + } + }); const APP_VERSION = /^[0-9]+\.([0-9]+)\./.exec(package.version)[1]; registerSuite({ @@ -56,7 +67,7 @@ define([ flowBeginTime: 'qux', flowId: 'wibble', lang: 'blee', - service: 'juff', + service: '0', uid: 'soop', utm_campaign: 'melm', utm_content: 'florg', @@ -75,7 +86,7 @@ define([ event_properties: { device_id: 'bar', entrypoint: 'baz', - service: 'juff' + service: 'amo' }, event_type: 'fxa_login - forgot_submit', language: 'blee', @@ -211,7 +222,7 @@ define([ flowBeginTime: 'd', flowId: 'e', lang: 'f', - service: 'g', + service: '1', uid: 'h', utm_campaign: 'i', utm_content: 'j', @@ -228,7 +239,7 @@ define([ event_properties: { device_id: 'b', entrypoint: 'c', - service: 'g' + service: 'pocket' }, event_type: 'fxa_reg - engage', language: 'f',