From a64f890ed05afd54635600c1d56386175be386c0 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 17 Mar 2017 14:55:41 +0000 Subject: [PATCH] Upgrade metrics api --- .../Features/Project/ProjectCreationHandler.coffee | 8 +++++++- .../app/coffee/Features/Project/ProjectGetter.coffee | 6 +++++- .../web/app/coffee/Features/User/UserCreator.coffee | 10 +++++++++- .../web/app/coffee/Features/User/UserGetter.coffee | 8 ++++++-- .../web/app/coffee/Features/User/UserLocator.coffee | 7 +++++-- .../web/app/coffee/Features/User/UserUpdater.coffee | 2 +- .../coffee/Project/ProjectCreationHandlerTests.coffee | 7 ++++--- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee b/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee index a21dfc7f9e..8095a54df8 100644 --- a/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee @@ -11,7 +11,8 @@ fs = require('fs') Path = require "path" _ = require "underscore" -module.exports = +module.exports = ProjectCreationHandler = + createBlankProject : (owner_id, projectName, callback = (error, project) ->)-> metrics.inc("project-creation") logger.log owner_id:owner_id, projectName:projectName, "creating blank project" @@ -79,5 +80,10 @@ module.exports = output = _.template(template.toString(), data) callback null, output.split("\n") +metrics.timeAsyncMethod( + ProjectCreationHandler, 'createBlankProject', + 'mongo.ProjectCreationHandler', + logger +) diff --git a/services/web/app/coffee/Features/Project/ProjectGetter.coffee b/services/web/app/coffee/Features/Project/ProjectGetter.coffee index 99e269975f..6d3e17536f 100644 --- a/services/web/app/coffee/Features/Project/ProjectGetter.coffee +++ b/services/web/app/coffee/Features/Project/ProjectGetter.coffee @@ -60,4 +60,8 @@ module.exports = ProjectGetter = callback null, projects, readAndWriteProjects, readOnlyProjects -metrics.timeAsyncMethod ProjectGetter, 'getProject', 'ProjectGetter.getProject', logger +[ + 'getProject', + 'getProjectWithoutDocLines' +].map (method) -> + metrics.timeAsyncMethod(ProjectGetter, method, 'mongo.ProjectGetter', logger) diff --git a/services/web/app/coffee/Features/User/UserCreator.coffee b/services/web/app/coffee/Features/User/UserCreator.coffee index 9218a48555..0e54452684 100644 --- a/services/web/app/coffee/Features/User/UserCreator.coffee +++ b/services/web/app/coffee/Features/User/UserCreator.coffee @@ -1,8 +1,10 @@ User = require("../../models/User").User UserLocator = require("./UserLocator") logger = require("logger-sharelatex") +metrics = require('../../infrastructure/Metrics') -module.exports = + +module.exports = UserCreator = getUserOrCreateHoldingAccount: (email, callback = (err, user)->)-> self = @ @@ -36,3 +38,9 @@ module.exports = user.save (err)-> callback(err, user) + +metrics.timeAsyncMethod( + UserCreator, 'createNewUser', + 'mongo.UserCreator', + logger +) diff --git a/services/web/app/coffee/Features/User/UserGetter.coffee b/services/web/app/coffee/Features/User/UserGetter.coffee index abcacfec5c..430033cb3c 100644 --- a/services/web/app/coffee/Features/User/UserGetter.coffee +++ b/services/web/app/coffee/Features/User/UserGetter.coffee @@ -27,5 +27,9 @@ module.exports = UserGetter = db.users.find { _id: { $in: user_ids} }, projection, callback -metrics.timeAsyncMethod UserGetter, 'getUser', 'UserGetter.getUser', logger -metrics.timeAsyncMethod UserGetter, 'getUsers', 'UserGetter.getUsers', logger + +[ + 'getUser', + 'getUsers' +].map (method) -> + metrics.timeAsyncMethod UserGetter, method, 'mongo.UserGetter', logger diff --git a/services/web/app/coffee/Features/User/UserLocator.coffee b/services/web/app/coffee/Features/User/UserLocator.coffee index 5123250f8c..9166392c44 100644 --- a/services/web/app/coffee/Features/User/UserLocator.coffee +++ b/services/web/app/coffee/Features/User/UserLocator.coffee @@ -14,5 +14,8 @@ module.exports = UserLocator = findById: (_id, callback)-> db.users.findOne _id:ObjectId(_id+""), callback -metrics.timeAsyncMethod UserLocator, 'findById', 'UserLocator.findById', logger -metrics.timeAsyncMethod UserLocator, 'findByEmail', 'UserLocator.findByEmail', logger +[ + 'findById', + 'findByEmail' +].map (method) -> + metrics.timeAsyncMethod UserLocator, method, 'mongo.UserLocator', logger diff --git a/services/web/app/coffee/Features/User/UserUpdater.coffee b/services/web/app/coffee/Features/User/UserUpdater.coffee index 5fe3694abe..fd92bed077 100644 --- a/services/web/app/coffee/Features/User/UserUpdater.coffee +++ b/services/web/app/coffee/Features/User/UserUpdater.coffee @@ -30,4 +30,4 @@ module.exports = UserUpdater = callback() -metrics.timeAsyncMethod UserUpdater, 'updateUser', 'UserUpdater.updateUser', logger +metrics.timeAsyncMethod UserUpdater, 'updateUser', 'mongo.UserUpdater', logger diff --git a/services/web/test/UnitTests/coffee/Project/ProjectCreationHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectCreationHandlerTests.coffee index 38a86d1eff..d9a8813c70 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectCreationHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectCreationHandlerTests.coffee @@ -50,9 +50,10 @@ describe 'ProjectCreationHandler', -> './ProjectEntityHandler':@ProjectEntityHandler "settings-sharelatex": @Settings = {} 'logger-sharelatex': {log:->} - "../../infrastructure/Metrics": inc:-> - - + "../../infrastructure/Metrics": { + inc: ()->, + timeAsyncMethod: ()-> + } describe 'Creating a Blank project', -> beforeEach ->