Skip to content

Commit

Permalink
added agent to server metrics (mozilla#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates authored and fzzzy committed May 3, 2019
1 parent 19ac048 commit f603f40
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Server events allow us to aggregate data about file lifecycle without collecting
* `event_properties`
* `download_count` downloads completed
* `ttl` time remaining before expiry truncated to hour
* `agent` the browser name or first 6 characters of the user agent that made the request

### Client Events

Expand Down
5 changes: 5 additions & 0 deletions server/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function statUploadEvent(data) {
size: orderOfMagnitude(data.size),
anonymous: data.anonymous
},
event_properties: {
agent: data.agent
},
event_id: 0
};
return sendBatch([event]);
Expand All @@ -61,6 +64,7 @@ function statDownloadEvent(data) {
time: truncateToHour(Date.now()),
event_type: 'server_download',
event_properties: {
agent: data.agent,
download_count: data.download_count,
ttl: data.ttl
},
Expand All @@ -80,6 +84,7 @@ function statDeleteEvent(data) {
time: truncateToHour(Date.now()),
event_type: 'server_delete',
event_properties: {
agent: data.agent,
download_count: data.download_count,
ttl: data.ttl
},
Expand Down
1 change: 1 addition & 0 deletions server/bin/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ID_REGEX = '([0-9a-fA-F]{10, 16})';
module.exports = function(app, devServer) {
const wsapp = express();
expressWs(wsapp, null, { perMessageDeflate: false });
routes(wsapp);
wsapp.ws('/api/ws', require('../routes/ws'));
wsapp.listen(8081, config.listen_address);

Expand Down
2 changes: 1 addition & 1 deletion server/bin/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ if (config.sentry_dsn) {
const app = express();

expressWs(app, null, { perMessageDeflate: false });
app.ws('/api/ws', require('../routes/ws'));
routes(app);
app.ws('/api/ws', require('../routes/ws'));

app.use(
express.static(path.resolve(__dirname, '../../dist/'), {
Expand Down
2 changes: 1 addition & 1 deletion server/bin/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const expressWs = require('express-ws');
module.exports = function(app, devServer) {
assets.setMiddleware(devServer.middleware);
expressWs(app, null, { perMessageDeflate: false });
app.ws('/api/ws', require('../routes/ws'));
routes(app);
app.ws('/api/ws', require('../routes/ws'));
tests(app);
// webpack-dev-server routes haven't been added yet
// so wait for next tick to add 404 handler
Expand Down
3 changes: 2 additions & 1 deletion server/routes/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = async function(req, res) {
ip: req.ip,
owner: meta.owner,
download_count: meta.dl,
ttl
ttl,
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
});
} catch (e) {
res.sendStatus(404);
Expand Down
3 changes: 2 additions & 1 deletion server/routes/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = async function(req, res) {
ip: req.ip,
owner: meta.owner,
download_count: dl,
ttl
ttl,
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
});
try {
if (dl >= dlimit) {
Expand Down
3 changes: 2 additions & 1 deletion server/routes/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ module.exports = function(ws, req) {
dlimit,
timeLimit,
anonymous: !user,
size: limiter.length
size: limiter.length,
agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
});
}
} catch (e) {
Expand Down

0 comments on commit f603f40

Please sign in to comment.