From 373dbe55d3a330084f61219f88b58b673e94d2a5 Mon Sep 17 00:00:00 2001 From: Shaun Starsprung Date: Fri, 15 Jun 2018 13:34:50 -0700 Subject: [PATCH] Fixed issue where checkpoint would not advance if all logs were filtered out --- package.json | 2 +- src/processor.js | 2 +- src/stream.js | 1 + tests/lib/processor.tests.js | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ec81125..ed55665 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-log-extension-tools", - "version": "1.3.5", + "version": "1.3.6", "description": "A set of tools for logging", "main": "src/index.js", "dependencies": { diff --git a/src/processor.js b/src/processor.js index 23b1d4f..9266952 100644 --- a/src/processor.js +++ b/src/processor.js @@ -152,7 +152,7 @@ LogsProcessor.prototype.run = function(handler) { options.logger.debug('Processor run complete. Logs processed:', status.logsProcessed); } - if (status.logsProcessed > 0) { + if (checkpoint !== status.startCheckpoint) { const week = 604800000; const currentDate = new Date().getTime(); const timeDiff = currentDate - lastLogDate; diff --git a/src/stream.js b/src/stream.js index 7b85130..e128dbe 100644 --- a/src/stream.js +++ b/src/stream.js @@ -22,6 +22,7 @@ function LogsApiStream(options) { this.previousCheckpoint = options.checkpointId || null; this.lastCheckpoint = options.checkpointId || null; this.status = { + startCheckpoint: options.checkpointId || null, start: new Date(), end: null, logsProcessed: 0 diff --git a/tests/lib/processor.tests.js b/tests/lib/processor.tests.js index f1c4242..81823ff 100644 --- a/tests/lib/processor.tests.js +++ b/tests/lib/processor.tests.js @@ -247,6 +247,26 @@ describe('LogsProcessor', () => { }); }); + it('should update checkpoint even if no events match given logTypes', () => { + helpers.mocks.logs({ delay: 550, type: 'sapi' }); + + + const storage = webtaskStorage(); + const getAsync = Promise.promisify(storage.get); + + const processor = createProcessor(null, { logTypes: [ 's', 'ss' ] }, storage); + return processor.run((logs, cb) => setTimeout(cb())) + .then(() => getAsync()) + .then((storageState) => { + expect(storageState.checkpointId).to.equal('100'); + expect(storageState.logs[0].logsProcessed).to.equal(0); + expect(storageState.logs[0].checkpoint).to.equal('100'); + expect(storageState.logs[0].start).to.be.an.instanceof(Date); + expect(storageState.logs[0].end).to.be.an.instanceof(Date); + }); + }); + + it('should return report', () => { const data = { logs: [