Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ This document describes changes between each past release.
- No changes yet.


0.19.3 (2016-02-12)
-------------------

- Add a way to log the loop-client versions in use. (#362)


0.19.2 (2016-01-07)
-------------------

Expand Down
3 changes: 2 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"hekaMetrics": {
"activated": false,
"debug": false,
"level": "DEBUG"
"level": "DEBUG",
"fmt": "pretty"
}
}
2 changes: 1 addition & 1 deletion loop/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = function(conf, logError, storage, statsdClient) {
var hawkIdHmac = hmac(tokenId, conf.get("hawkIdSecret"));
storage.setHawkSession(hawkIdHmac, authKey, function(err) {
if (statsdClient && err === null) {
statsdClient.count('loop.activated-users', 1);
statsdClient.increment('loop.activated-users');
}
callback(err);
});
Expand Down
4 changes: 2 additions & 2 deletions loop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var express = require('express');
var bodyParser = require('body-parser');
var raven = require('raven');
var cors = require('cors');
var StatsdClient = require('statsd-node').client;
var StatsdClient = require('node-statsd');

var PubSub = require('./pubsub');

Expand Down Expand Up @@ -142,7 +142,7 @@ if (conf.get("fxaOAuth").activated !== false) {

var rooms = require("./routes/rooms");
rooms(apiRouter, conf, logError, storage, filestorage, auth, validators, tokBox,
simplePush, notifications);
simplePush, notifications, statsdClient);

var session = require("./routes/session");
session(apiRouter, conf, storage, auth);
Expand Down
9 changes: 4 additions & 5 deletions loop/routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ module.exports = function(app, conf, logError, storage, tokBox, statsdClient) {
var pushStatus = (!error && statusCodes.every(isSuccess));
returnStatus(storageStatus, tokboxError, pushStatus, verifierStatus);
if (statsdClient !== undefined) {
statsdClient.count('loop.simplepush.call', 1);
var counter_push_status_counter;
var tag;
if (pushStatus) {
counter_push_status_counter = 'loop.simplepush.call.heartbeat.success';
tag = 'success';
} else {
counter_push_status_counter = 'loop.simplepush.call.heartbeat.failures';
tag = 'failure';
}
statsdClient.count(counter_push_status_counter, 1);
statsdClient.increment('loop.simplepush.call.heartbeat', 1, [tag]);
}
});
});
Expand Down
54 changes: 51 additions & 3 deletions loop/routes/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var decrypt = require('../encrypt').decrypt;
var encrypt = require('../encrypt').encrypt;
var errors = require('../errno.json');
var getUserAccount = require('../utils').getUserAccount;
var hekaLogger = require('../logger').hekaLogger;
var sendError = require('../utils').sendError;
var tokenlib = require('../tokenlib');
var time = require('../utils').time;
Expand All @@ -20,7 +21,7 @@ var hmac = require('../hmac');


module.exports = function (apiRouter, conf, logError, storage, filestorage, auth,
validators, tokBox, simplePush, notifications) {
validators, tokBox, simplePush, notifications, statsdClient) {

var roomsConf = conf.get("rooms");

Expand Down Expand Up @@ -331,14 +332,14 @@ module.exports = function (apiRouter, conf, logError, storage, filestorage, auth
/**
* Do an action on a room.
*
* Actions are "join", "leave", "refresh".
* Actions are "join", "leave", "refresh", "status", "logDomain".
**/
apiRouter.post('/rooms/:token', validators.validateRoomToken,
auth.authenticateWithHawkOrToken,
function(req, res) {
var participantHmac = req.hawkIdHmac || req.participantTokenHmac;
var roomOwnerHmac = req.roomStorageData.roomOwnerHmac;
var ROOM_ACTIONS = ["join", "refresh", "status", "leave"];
var ROOM_ACTIONS = ["join", "refresh", "status", "leave", "logDomain"];
var action = req.body.action;
var code;

Expand Down Expand Up @@ -529,6 +530,51 @@ module.exports = function (apiRouter, conf, logError, storage, filestorage, auth
});
});
});
},
handleLogDomain: function(req, res) {
// Log whitelisted domain count in statsd.
validators.requireParams('domains')(
req, res, function() {
var domains = req.body.domains;
var validDomains = domains.filter(function(domain) {
return domain.hasOwnProperty("domain") && domain.hasOwnProperty("count");
});

if (validDomains.length !== domains.length) {
sendError(res, 400, errors.INVALID_PARAMETERS,
"Domains must be a list of objects with both a " +
"``domain`` and ``count`` property.");
return;
}

storage.getRoomParticipant(req.token, participantHmac,
function(err, participant) {
if (res.serverError(err)) return;
if (participant === null) {
sendError(res, 400, errors.NOT_ROOM_PARTICIPANT,
"Can't update status for a room you aren't in.");
return;
}

if (conf.get('hekaMetrics').activated === true) {
req.body.domains.forEach(function(domain) {
var line = {
domain: domain.domain,
count: domain.count
};
hekaLogger.info('domains.counters', line);

if (statsdClient !== undefined) {
statsdClient.increment(
"loop.room.shared_domains",
domain.count);
}

});
}
res.status(204).json();
});
});
}
};

Expand All @@ -540,6 +586,8 @@ module.exports = function (apiRouter, conf, logError, storage, filestorage, auth
handlers.handleUpdateStatus(req, res);
} else if (action === "leave") {
handlers.handleLeave(req, res);
} else if (action === "logDomain") {
handlers.handleLogDomain(req, res);
}
});

Expand Down
18 changes: 6 additions & 12 deletions loop/simplepush.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ SimplePush.prototype = {
var self = this;

urls.forEach(function(simplePushUrl) {
if (self.statsdClient !== undefined) {
self.statsdClient.count("loop.simplepush.call", 1);
self.statsdClient.count("loop.simplepush.call." + reason, 1);
}
request.put({
url: simplePushUrl,
form: { version: version }
}, function(err) {
var status = 'success';
if (err) {
self.logError(err);
status = 'failure';
}
if (self.statsdClient !== undefined) {
if (err) {
self.logError(err);
self.statsdClient.count("loop.simplepush.call.failures", 1);
self.statsdClient.count("loop.simplepush.call." + reason + ".failures", 1);
} else {
self.statsdClient.count("loop.simplepush.call.success", 1);
self.statsdClient.count("loop.simplepush.call." + reason + ".success", 1);
}
self.statsdClient.increment("loop.simplepush.call", 1, [reason, status]);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion loop/tokbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TokBox.prototype = {
return;
}
if (self.statsdClient !== undefined) {
self.statsdClient.count("loop.tokbox.createSession.count", 1);
self.statsdClient.increment("loop.tokbox.createSession.count");
self.statsdClient.timing(
'loop.tokbox.createSession',
Date.now() - startTime
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mozilla-loop-server",
"description": "The Mozilla Loop (WebRTC App) server",
"version": "0.19.2",
"version": "0.20.0-dev",
"author": "Mozilla (https://mozilla.org/)",
"homepage": "https://github.com/mozilla-services/loop-server/",
"bugs": "https://bugzilla.mozilla.org/enter_bug.cgi?product=Loop&component=Server",
Expand Down Expand Up @@ -37,7 +37,7 @@
"redis": "0.12.1",
"request": "2.45.0",
"sodium": "1.0.13",
"statsd-node": "0.2.3",
"node-statsd": "0.1.1",
"strftime": "0.8.2",
"urlsafe-base64": "1.0.0",
"ws": "1.0.1",
Expand Down
31 changes: 12 additions & 19 deletions test/functional_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function runOnPrefix(apiPrefix) {
}
});

sandbox.stub(statsdClient, "count");
sandbox.stub(statsdClient, "increment");

supertest(app)
.get(apiPrefix + '/__heartbeat__')
Expand All @@ -406,10 +406,8 @@ function runOnPrefix(apiPrefix) {
'push': false,
'fxaVerifier': true
});
assert.calledTwice(statsdClient.count);
assert.calledWithExactly(statsdClient.count, "loop.simplepush.call", 1);
assert.calledWithExactly(statsdClient.count,
"loop.simplepush.call.heartbeat.failures", 1);
assert.calledOnce(statsdClient.increment);
assert.calledWithExactly(statsdClient.increment, "loop.simplepush.call.heartbeat", 1, ['failure']);
done();
});
});
Expand Down Expand Up @@ -464,7 +462,7 @@ function runOnPrefix(apiPrefix) {
callback(null, {statusCode: 200});
});

sandbox.stub(statsdClient, "count");
sandbox.stub(statsdClient, "increment");

supertest(app)
.get(apiPrefix + '/__heartbeat__')
Expand All @@ -477,11 +475,8 @@ function runOnPrefix(apiPrefix) {
'push': true,
'fxaVerifier': true
});
assert.calledTwice(statsdClient.count);
assert.calledWithExactly(statsdClient.count, "loop.simplepush.call", 1);
assert.calledWithExactly(statsdClient.count,
"loop.simplepush.call.heartbeat.success", 1);

assert.calledOnce(statsdClient.increment);
assert.calledWithExactly(statsdClient.increment, "loop.simplepush.call.heartbeat", 1, ['success']);
done();
});
});
Expand Down Expand Up @@ -778,33 +773,31 @@ function runOnPrefix(apiPrefix) {
});

it("should count new users if the session is created", function(done) {
sandbox.stub(statsdClient, "count");
sandbox.stub(statsdClient, "increment");
supertest(app)
.post(apiPrefix + '/registration')
.type('json')
.send({
'simplePushURL': pushURL
}).expect(200).end(function(err) {
if (err) throw err;
assert.calledOnce(statsdClient.count);
assert.calledOnce(statsdClient.increment);
assert.calledWithExactly(
statsdClient.count,
"loop.activated-users",
1
);
statsdClient.increment,
"loop.activated-users");
done();
});
});

it("shouldn't count a new user if the session already exists",
function(done) {
sandbox.stub(statsdClient, "count");
sandbox.stub(statsdClient, "increment");
jsonReq
.send({
'simple_push_url': pushURL
}).expect(200).end(function(err) {
if (err) throw err;
assert.notCalled(statsdClient.count);
assert.notCalled(statsdClient.increment);
done();
});
});
Expand Down
9 changes: 4 additions & 5 deletions test/fxa_oauth_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,16 @@ describe('/fxa-oauth', function () {
});

it("should count new users if the session is created", function(done) {
sandbox.stub(statsdClient, "count");
sandbox.stub(statsdClient, "increment");
supertest(app)
.post(apiPrefix + '/fxa-oauth/params')
.type('json')
.send({}).expect(200).end(function(err) {
if (err) throw err;
assert.calledOnce(statsdClient.count);
assert.calledOnce(statsdClient.increment);
assert.calledWithExactly(
statsdClient.count,
"loop.activated-users",
1
statsdClient.increment,
"loop.activated-users"
);
done();
});
Expand Down
Loading