diff --git a/services/document-updater/app/js/DocumentManager.js b/services/document-updater/app/js/DocumentManager.js index 8ff285c5ff..4af82ae586 100644 --- a/services/document-updater/app/js/DocumentManager.js +++ b/services/document-updater/app/js/DocumentManager.js @@ -222,6 +222,13 @@ module.exports = DocumentManager = { user_id: userId, }, } + // Keep track of external updates, whether they are for live documents + // (flush) or unloaded documents (evict), and whether the update is a no-op. + Metrics.inc('external-update', 1, { + status: op.length > 0 ? 'diff' : 'noop', + method: alreadyLoaded ? 'flush' : 'evict', + path: source, + }) UpdateManager.applyUpdate(projectId, docId, update, error => { if (error) { return callback(error) diff --git a/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js b/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js index f4203f5997..e65e8bd96c 100644 --- a/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js +++ b/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js @@ -9,6 +9,7 @@ describe('DocumentManager', function () { tk.freeze(new Date()) this.Metrics = { Timer: class Timer {}, + inc: sinon.stub(), } this.Metrics.Timer.prototype.done = sinon.stub() @@ -42,6 +43,7 @@ describe('DocumentManager', function () { this.unflushedTime = Date.now() this.lastUpdatedAt = Date.now() this.lastUpdatedBy = 'last-author-id' + this.source = 'external-source' }) afterEach(function () { @@ -517,6 +519,16 @@ describe('DocumentManager', function () { .should.equal(true) }) + it('should increment the external update metric', function () { + this.Metrics.inc + .calledWith('external-update', 1, { + status: 'diff', + method: 'flush', + path: this.source, + }) + .should.equal(true) + }) + it('should flush the doc to Mongo', function () { this.DocumentManager.flushDocIfLoaded .calledWith(this.project_id, this.doc_id) @@ -568,6 +580,16 @@ describe('DocumentManager', function () { .should.equal(true) }) + it('should increment the external update metric', function () { + this.Metrics.inc + .calledWith('external-update', 1, { + status: 'diff', + method: 'evict', + path: this.source, + }) + .should.equal(true) + }) + it('should not flush the project history', function () { this.HistoryManager.flushProjectChangesAsync .calledWithExactly(this.project_id)