Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(metrics): add locale to flow events
Browse files Browse the repository at this point in the history
#6021
r=vbudhram
  • Loading branch information
philbooth committed Apr 5, 2018
1 parent bd97464 commit 433cba7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions server/lib/flow-event.js
Expand Up @@ -235,6 +235,7 @@ function logFlowEvent (event, data, request) {
flow_id: data.flowId, //eslint-disable-line camelcase
flow_time: Math.floor(event.flowTime), //eslint-disable-line camelcase
hostname: HOSTNAME,
locale: request.locale,
op: 'flowEvent',
pid: process.pid,
time: new Date(event.time).toISOString(),
Expand Down
20 changes: 12 additions & 8 deletions tests/server/flow-event.js
Expand Up @@ -35,7 +35,8 @@ registerSuite('flow-event', {
request: {
headers: {
'user-agent': 'bar'
}
},
locale: 'en'
},
time: 1479127399349
};
Expand Down Expand Up @@ -92,6 +93,7 @@ registerSuite('flow-event', {
flow_id: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
flow_time: 0,
hostname: os.hostname(),
locale: 'en',
migration: 'sync11',
op: 'flowEvent',
pid: process.pid,
Expand All @@ -109,22 +111,22 @@ registerSuite('flow-event', {

'second call to process.stderr.write was correct': () => {
const arg = JSON.parse(process.stderr.write.args[1][0]);
assert.lengthOf(Object.keys(arg), 17);
assert.lengthOf(Object.keys(arg), 18);
assert.equal(arg.event, 'flow.signup.view');
assert.equal(arg.flow_time, 5);
assert.equal(arg.time, new Date(mocks.time - 995).toISOString());
},

'third call to process.stderr.write was correct': () => {
const arg = JSON.parse(process.stderr.write.args[2][0]);
assert.lengthOf(Object.keys(arg), 17);
assert.lengthOf(Object.keys(arg), 18);
assert.equal(arg.event, 'flow.signup.good-offset-now');
assert.equal(arg.time, new Date(mocks.time).toISOString());
},

'fourth call to process.stderr.write was correct': () => {
const arg = JSON.parse(process.stderr.write.args[3][0]);
assert.lengthOf(Object.keys(arg), 17);
assert.lengthOf(Object.keys(arg), 18);
assert.equal(arg.event, 'flow.signup.good-offset-oldest');
assert.equal(arg.time, new Date(mocks.time - config.flow_id_expiry).toISOString());
},
Expand Down Expand Up @@ -396,6 +398,7 @@ registerSuite('flow-event', {
const timeSinceFlowBegin = 1000;
const flowBeginTime = mocks.time - timeSinceFlowBegin;
flowMetricsValidateResult = true;
mocks.request.locale = 'ar';
flowEvent(mocks.request, {
events: [
{offset: 0, type: 'flow.begin'}
Expand All @@ -410,6 +413,7 @@ registerSuite('flow-event', {
'process.stderr.write was called once': () => {
assert.equal(process.stderr.write.callCount, 1);
const arg = JSON.parse(process.stderr.write.args[0][0]);
assert.equal(arg.locale, 'ar');
assert.isUndefined(arg.context);
assert.isUndefined(arg.entrypoint);
assert.isUndefined(arg.migration);
Expand Down Expand Up @@ -813,7 +817,7 @@ registerSuite('flow-event', {
'process.stderr.write was called correctly': () => {
assert.equal(process.stderr.write.callCount, 1);
const arg = JSON.parse(process.stderr.write.args[0][0]);
assert.lengthOf(Object.keys(arg), 16);
assert.lengthOf(Object.keys(arg), 17);
assert.isUndefined(arg.utm_campaign); //eslint-disable-line camelcase
}
}
Expand All @@ -830,7 +834,7 @@ registerSuite('flow-event', {
'process.stderr.write was called correctly': () => {
assert.equal(process.stderr.write.callCount, 1);
const arg = JSON.parse(process.stderr.write.args[0][0]);
assert.lengthOf(Object.keys(arg), 16);
assert.lengthOf(Object.keys(arg), 17);
assert.isUndefined(arg.utm_content); //eslint-disable-line camelcase
}
}
Expand All @@ -847,7 +851,7 @@ registerSuite('flow-event', {
'process.stderr.write was called correctly': () => {
assert.equal(process.stderr.write.callCount, 1);
const arg = JSON.parse(process.stderr.write.args[0][0]);
assert.lengthOf(Object.keys(arg), 16);
assert.lengthOf(Object.keys(arg), 17);
assert.isUndefined(arg.utm_medium); //eslint-disable-line camelcase
}
}
Expand All @@ -864,7 +868,7 @@ registerSuite('flow-event', {
'process.stderr.write was called correctly': () => {
assert.equal(process.stderr.write.callCount, 1);
const arg = JSON.parse(process.stderr.write.args[0][0]);
assert.lengthOf(Object.keys(arg), 16);
assert.lengthOf(Object.keys(arg), 17);
assert.isUndefined(arg.utm_source); //eslint-disable-line camelcase
}
}
Expand Down

0 comments on commit 433cba7

Please sign in to comment.