Skip to content

Commit

Permalink
Send /wsapi/stage_* events to the KPI backend.
Browse files Browse the repository at this point in the history
* Add tests in tests/kpi-test.js to ensure both staging and completion events are added to the queue.

fixes mozilla#3920
  • Loading branch information
Shane Tomlinson committed Oct 10, 2013
1 parent 5ff73a0 commit f6d8545
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/logging/transports/filters/metrics.js
Expand Up @@ -12,13 +12,11 @@ const coarse = require('../../../coarse_user_agent_parser');
var MessageMatches = {
'signin': true,
'verify': true
'complete_email_confirmation.success': true,
'complete_reset.success': true,
'complete_transition.success': true,
'complete_user_creation.success': true
};

var RegExpMatches = [
/complete_(?:[^\.]+)\.success/,
/stage_(?:[^\.]+)\.success/,
/^metrics\.report\./
];

Expand Down
6 changes: 5 additions & 1 deletion lib/logging/transports/metrics-kpi.js
Expand Up @@ -29,7 +29,6 @@ MetricsKpiggybankTransport.prototype.log
if ( ! filter.test(msg)) return callback(null, true);
if ( ! config.get('kpi_send_metrics')) return callback(null, true);


var entry = toEntry(msg, meta);
this.queue.push(entry);

Expand All @@ -40,10 +39,15 @@ MetricsKpiggybankTransport.prototype.log
callback(null, true);
};

MetricsKpiggybankTransport.prototype.getQueue = function() {
return this.queue;
};

function isQueueFull() {
return this.queue.length >= MetricsKpiggybankTransport.BATCH_SIZE;
}


function clearQueue() {
var kpis = this.queue;
this.queue = [];
Expand Down
1 change: 1 addition & 0 deletions lib/wsapi/stage_email.js
Expand Up @@ -91,6 +91,7 @@ exports.process = function(req, res) {

res.json({ success: true });
// let's now kick out a verification email!
logger.info('stage_email.success');
email.sendConfirmationEmail(req.params.email, req.params.site, secret, langContext,
req.params.backgroundColor, req.params.siteLogo);
});
Expand Down
2 changes: 2 additions & 0 deletions lib/wsapi/stage_reset.js
Expand Up @@ -71,6 +71,8 @@ exports.process = function(req, res) {

res.json({ success: true });

logger.info('stage_reset.success');

// let's now kick out a verification email!
email.sendForgotPasswordEmail(req.params.email, req.params.site, secret, langContext,
req.params.backgroundColor, req.params.siteLogo);
Expand Down
2 changes: 2 additions & 0 deletions lib/wsapi/stage_reverify.js
Expand Up @@ -56,6 +56,8 @@ exports.process = function(req, res) {
req.session.pendingReverification = secret;

res.json({ success: true });
logger.info('stage_reverify.success');

// let's now kick out a verification email!
email.sendConfirmationEmail(req.params.email, req.params.site, secret, langContext,
req.params.backgroundColor, req.params.siteLogo);
Expand Down
2 changes: 2 additions & 0 deletions lib/wsapi/stage_transition.js
Expand Up @@ -81,6 +81,8 @@ exports.process = function(req, res) {

res.json({ success: true });

logger.info('stage_transition.success');

// let's now kick out a verification email!
email.sendTransitionEmail(req.params.email, req.params.site, secret, langContext,
req.params.backgroundColor, req.params.siteLogo);
Expand Down
1 change: 1 addition & 0 deletions lib/wsapi/stage_user.js
Expand Up @@ -109,6 +109,7 @@ exports.process = function(req, res) {
req.session.pendingCreation = secret;

res.json({ success: true });
logger.info('stage_user.success');

// let's now kick out a verification email!
email.sendNewUserEmail(req.params.email, req.params.site, secret, langContext,
Expand Down
48 changes: 47 additions & 1 deletion tests/kpi-test.js
Expand Up @@ -12,7 +12,7 @@ const config = require('../lib/configuration');
const kpi_data = require('../lib/kpi_data');
const HttpMock = require('./lib/http-mock');
const logger = require('../lib/logging/logging').logger;

const KpiTransport = require('../lib/logging/transports/metrics-kpi');

require('./lib/test_env');

Expand Down Expand Up @@ -133,6 +133,52 @@ suite.addBatch({
}
});

function noOp() {}

suite.addBatch({
"staging and verification events": {
topic: function() {
this.origSendMetricsValue = config.get('kpi_send_metrics');
this.expectedEvents = [
'stage_email.success',
'stage_reset.success',
'stage_reverify.success',
'stage_transition.success',
'stage_user.success',
'complete_email_confirmation.success',
'complete_reset.success',
'complete_transition.success',
'complete_user_creation.success'
];
config.set('kpi_send_metrics', true);

var kpiTransport = new KpiTransport();

this.expectedEvents.forEach(function(event) {
kpiTransport.log('info', event, null, noOp);
});

return kpiTransport.getQueue();
},
"are added to the KPI queue": function(queue) {
var expectedEvents = this.expectedEvents;

// The test here is a bit backwards. Take the original set of events to
// test and remove the events that have been added to the queue. Hope
// that none remain.
queue.forEach(function(kpi) {
var eventName = kpi.event_name;
var index = expectedEvents.indexOf(eventName);
expectedEvents.splice(index, 1);
});
assert.equal(expectedEvents.length, 0);
},
"reset kpi_send_metrics": function() {
config.set('kpi_send_metrics', this.origSendMetricsValue);
}
}
});

start_stop.addShutdownBatches(suite);

// run or export the suite.
Expand Down

0 comments on commit f6d8545

Please sign in to comment.