From e67c5462542e6a1b575dc69b83b47e8e1e5f0392 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 17 Mar 2017 09:47:45 +0000 Subject: [PATCH] Upgrade metrics --- services/notifications/app.coffee | 1 - .../notifications/app/coffee/Notifications.coffee | 15 ++++++++++++++- .../test/unit/coffee/NotificationsTests.coffee | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/services/notifications/app.coffee b/services/notifications/app.coffee index 4a8136cb92..dca9f683c0 100644 --- a/services/notifications/app.coffee +++ b/services/notifications/app.coffee @@ -9,7 +9,6 @@ db = mongojs(Settings.mongo.url, ['notifications']) Path = require("path") metrics = require("metrics-sharelatex") metrics.initialize("notifications") -metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger) metrics.memory.monitor(logger) HealthCheckController = require("./app/js/HealthCheckController") diff --git a/services/notifications/app/coffee/Notifications.coffee b/services/notifications/app/coffee/Notifications.coffee index eb6b68aad2..78459df411 100644 --- a/services/notifications/app/coffee/Notifications.coffee +++ b/services/notifications/app/coffee/Notifications.coffee @@ -3,8 +3,9 @@ logger = require('logger-sharelatex') mongojs = require('mongojs') db = mongojs(Settings.mongo?.url, ['notifications']) ObjectId = require("mongojs").ObjectId +metrics = require('metrics-sharelatex') -module.exports = +module.exports = Notifications = getUserNotifications: (user_id, callback = (err, notifications)->)-> query = @@ -79,3 +80,15 @@ module.exports = searchOps = key: notification_key db.notifications.remove searchOps, {justOne: true}, callback + + +metrics.timeAsyncMethod( + Notifications, 'getUserNotifications', + 'Notifications.getUserNotifications', + logger +) +metrics.timeAsyncMethod( + Notifications, 'addNotification', + 'Notifications.addNotification', + logger +) diff --git a/services/notifications/test/unit/coffee/NotificationsTests.coffee b/services/notifications/test/unit/coffee/NotificationsTests.coffee index d6cd5f4d4a..c238bda119 100644 --- a/services/notifications/test/unit/coffee/NotificationsTests.coffee +++ b/services/notifications/test/unit/coffee/NotificationsTests.coffee @@ -36,6 +36,7 @@ describe 'Notifications Tests', -> } 'settings-sharelatex': {} 'mongojs':@mongojs + 'metrics-sharelatex': {timeAsyncMethod: sinon.stub()} @stubbedNotification = {user_id: ObjectId(user_id), key:"notification-key", messageOpts:"some info", templateKey:"template-key"} @stubbedNotificationArray = [@stubbedNotification]