From 64fc6ef2e3f9b51228435ec48f35084b684c2156 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 17 Mar 2017 09:31:12 +0000 Subject: [PATCH] Upgrade metrics --- services/contacts/app.coffee | 1 - .../contacts/app/coffee/ContactManager.coffee | 16 +++++++++++++++- .../test/unit/coffee/ContactsManagerTests.coffee | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/services/contacts/app.coffee b/services/contacts/app.coffee index 2f267ca35f..4e5cc35d4e 100644 --- a/services/contacts/app.coffee +++ b/services/contacts/app.coffee @@ -9,7 +9,6 @@ Path = require "path" Metrics.initialize("contacts") logger.initialize("contacts") -Metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger) Metrics.event_loop?.monitor(logger) app = express() diff --git a/services/contacts/app/coffee/ContactManager.coffee b/services/contacts/app/coffee/ContactManager.coffee index 918518fcf4..79e9d79196 100644 --- a/services/contacts/app/coffee/ContactManager.coffee +++ b/services/contacts/app/coffee/ContactManager.coffee @@ -1,4 +1,6 @@ {db, ObjectId} = require "./mongojs" +logger = require('logger-sharelatex') +metrics = require('metrics-sharelatex') module.exports = ContactManager = touchContact: (user_id, contact_id, callback = (error) ->) -> @@ -27,4 +29,16 @@ module.exports = ContactManager = user_id: user_id }, (error, user) -> return callback(error) if error? - callback null, user?.contacts \ No newline at end of file + callback null, user?.contacts + +metrics.timeAsyncMethod( + ContactManager, 'touchContact', + 'ContactManager.touchContact', + logger +) + +metrics.timeAsyncMethod( + ContactManager, 'getContacts', + 'ContactManager.getContacts', + logger +) diff --git a/services/contacts/test/unit/coffee/ContactsManagerTests.coffee b/services/contacts/test/unit/coffee/ContactsManagerTests.coffee index a6a20f6501..fd089faa56 100644 --- a/services/contacts/test/unit/coffee/ContactsManagerTests.coffee +++ b/services/contacts/test/unit/coffee/ContactsManagerTests.coffee @@ -14,7 +14,9 @@ describe "ContactManager", -> "./mongojs": { db: @db = contacts: {} ObjectId: ObjectId - } + }, + 'logger-sharelatex': {log: sinon.stub()}, + 'metrics-sharelatex': {timeAsyncMethod: sinon.stub()} @user_id = ObjectId().toString() @contact_id = ObjectId().toString() @callback = sinon.stub()