From e879f9c742250127dbdcdaf1c0b82c9a82e28f83 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 16 Mar 2017 16:46:58 +0000 Subject: [PATCH 1/5] Upgrade metrics --- services/docstore/app.coffee | 1 - .../docstore/app/coffee/MongoManager.coffee | 41 ++++++++++++++++++- .../test/unit/coffee/MongoManagerTests.coffee | 3 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/services/docstore/app.coffee b/services/docstore/app.coffee index e41593cd4c..f81b4f3ea8 100644 --- a/services/docstore/app.coffee +++ b/services/docstore/app.coffee @@ -9,7 +9,6 @@ Path = require "path" Metrics.initialize("docstore") logger.initialize("docstore") -Metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger) Metrics.event_loop?.monitor(logger) app = express() diff --git a/services/docstore/app/coffee/MongoManager.coffee b/services/docstore/app/coffee/MongoManager.coffee index fe6f06e8cb..a39c8fb4d9 100644 --- a/services/docstore/app/coffee/MongoManager.coffee +++ b/services/docstore/app/coffee/MongoManager.coffee @@ -1,4 +1,6 @@ {db, ObjectId} = require "./mongojs" +logger = require 'logger-sharelatex' +metrics = require 'metrics-sharelatex' module.exports = MongoManager = @@ -67,4 +69,41 @@ module.exports = MongoManager = $set: version: version }, { upsert: true - }, callback \ No newline at end of file + }, callback + + +metrics.timeAsyncMethod( + MongoManager, 'findDoc', + 'MongoManager.findDoc', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'getProjectsDocs', + 'MongoManager.getProjectsDocs', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'getArchivedProjectDocs', + 'MongoManager.getArchivedProjectDocs', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'upsertIntoDocCollection', + 'MongoManager.upsertIntoDocCollection', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'markDocAsArchived', + 'MongoManager.markDocAsArchived', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'getDocVersion', + 'MongoManager.getDocVersion', + logger +) +metrics.timeAsyncMethod( + MongoManager, 'setDocVersion', + 'MongoManager.setDocVersion', + logger +) diff --git a/services/docstore/test/unit/coffee/MongoManagerTests.coffee b/services/docstore/test/unit/coffee/MongoManagerTests.coffee index b65de2cde9..29ca1e958b 100644 --- a/services/docstore/test/unit/coffee/MongoManagerTests.coffee +++ b/services/docstore/test/unit/coffee/MongoManagerTests.coffee @@ -11,6 +11,7 @@ describe "MongoManager", -> "./mongojs": db: @db = { docs: {}, docOps: {} } ObjectId: ObjectId + 'metrics-sharelatex': {timeAsyncMethod: sinon.stub()} @project_id = ObjectId().toString() @doc_id = ObjectId().toString() @callback = sinon.stub() @@ -151,4 +152,4 @@ describe "MongoManager", -> .should.equal true it "should call the callback", -> - @callback.called.should.equal true \ No newline at end of file + @callback.called.should.equal true From bc37c844ea84d385096dac78110236c76edf250c Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 17 Mar 2017 15:27:36 +0000 Subject: [PATCH 2/5] update to new metrics api --- .../docstore/app/coffee/MongoManager.coffee | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/services/docstore/app/coffee/MongoManager.coffee b/services/docstore/app/coffee/MongoManager.coffee index a39c8fb4d9..27d9bd163e 100644 --- a/services/docstore/app/coffee/MongoManager.coffee +++ b/services/docstore/app/coffee/MongoManager.coffee @@ -72,38 +72,13 @@ module.exports = MongoManager = }, callback -metrics.timeAsyncMethod( - MongoManager, 'findDoc', - 'MongoManager.findDoc', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'getProjectsDocs', - 'MongoManager.getProjectsDocs', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'getArchivedProjectDocs', - 'MongoManager.getArchivedProjectDocs', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'upsertIntoDocCollection', - 'MongoManager.upsertIntoDocCollection', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'markDocAsArchived', - 'MongoManager.markDocAsArchived', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'getDocVersion', - 'MongoManager.getDocVersion', - logger -) -metrics.timeAsyncMethod( - MongoManager, 'setDocVersion', - 'MongoManager.setDocVersion', - logger -) +[ + 'findDoc', + 'getProjectsDocs', + 'getArchivedProjectDocs', + 'upsertIntoDocCollection', + 'markDocAsArchived', + 'getDocVersion', + 'setDocVersion' +].map (method) -> + metrics.timeAsyncMethod(MongoManager, method, 'mongo.MongoManager', logger) From ce01b39967ee63dab4652c0042827b9ed3713731 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 21 Mar 2017 13:48:21 +0000 Subject: [PATCH 3/5] Update metrics version to 1.7.0 --- services/docstore/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/docstore/package.json b/services/docstore/package.json index d603ce0313..27ec9a72c2 100644 --- a/services/docstore/package.json +++ b/services/docstore/package.json @@ -10,7 +10,7 @@ "dependencies": { "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.4.0", - "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.1.0", + "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.0", "mongojs": "0.18.2", "express": "~4.1.1", "underscore": "~1.6.0", From f7bc400f225a593441ffe948dcc43e3a84ed4270 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 31 Mar 2017 11:18:31 +0100 Subject: [PATCH 4/5] upgrade to most recent metrics --- services/docstore/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/docstore/package.json b/services/docstore/package.json index 27ec9a72c2..dacc42948e 100644 --- a/services/docstore/package.json +++ b/services/docstore/package.json @@ -10,7 +10,7 @@ "dependencies": { "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.4.0", - "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.0", + "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1", "mongojs": "0.18.2", "express": "~4.1.1", "underscore": "~1.6.0", From b14039715f9c265f1c396092b70250f5a9439c03 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 31 Mar 2017 11:25:23 +0100 Subject: [PATCH 5/5] Stub out logger in tests --- services/docstore/test/unit/coffee/MongoManagerTests.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/services/docstore/test/unit/coffee/MongoManagerTests.coffee b/services/docstore/test/unit/coffee/MongoManagerTests.coffee index 29ca1e958b..1a264bf0d2 100644 --- a/services/docstore/test/unit/coffee/MongoManagerTests.coffee +++ b/services/docstore/test/unit/coffee/MongoManagerTests.coffee @@ -12,6 +12,7 @@ describe "MongoManager", -> db: @db = { docs: {}, docOps: {} } ObjectId: ObjectId 'metrics-sharelatex': {timeAsyncMethod: sinon.stub()} + 'logger-sharelatex': {log: ()->} @project_id = ObjectId().toString() @doc_id = ObjectId().toString() @callback = sinon.stub()