From 4d7e6d27070914571c134d88c33f5a2e3330608f Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Thu, 30 Sep 2021 17:27:27 +0200 Subject: [PATCH] Merge pull request #5080 from overleaf/ab-queues-bq-mp-retry Split analytics queues into topics to retry failed insertions for each platform independently GitOrigin-RevId: 4dacbf898359b4039b64ae07ee2dc1f8986d430b --- .../Features/Analytics/AnalyticsManager.js | 31 ++++++++++++++++--- .../src/Analytics/AnalyticsManagerTests.js | 14 ++++++--- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/services/web/app/src/Features/Analytics/AnalyticsManager.js b/services/web/app/src/Features/Analytics/AnalyticsManager.js index 7c01c28057..ed2328fd7e 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsManager.js +++ b/services/web/app/src/Features/Analytics/AnalyticsManager.js @@ -6,6 +6,7 @@ const Queues = require('../../infrastructure/Queues') const uuid = require('uuid') const _ = require('lodash') const { expressify } = require('../../util/promises') +const { logger } = require('logger-sharelatex') const analyticsEventsQueue = Queues.getAnalyticsEventsQueue() const analyticsEditingSessionsQueue = Queues.getAnalyticsEditingSessionsQueue() @@ -24,7 +25,7 @@ function identifyUser(userId, analyticsId, isNewUser) { analyticsEventsQueue .add( 'identify', - { userId, analyticsId, isNewUser }, + { userId, analyticsId, isNewUser, createdAt: new Date() }, { delay: ONE_MINUTE_MS } ) .then(() => { @@ -56,12 +57,21 @@ function recordEventForSession(session, event, segmentation) { if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) { return } + logger.info({ + analyticsId, + userId, + event, + segmentation, + isLoggedIn: !!userId, + createdAt: new Date(), + }) _recordEvent({ analyticsId, userId, event, segmentation, isLoggedIn: !!userId, + createdAt: new Date(), }) } @@ -117,7 +127,12 @@ function updateEditingSession(userId, projectId, countryCode) { event_type: 'editing-session', }) analyticsEditingSessionsQueue - .add({ userId, projectId, countryCode }) + .add('editing-session', { + userId, + projectId, + countryCode, + createdAt: new Date(), + }) .then(() => { Metrics.analyticsQueue.inc({ status: 'added', @@ -140,7 +155,14 @@ function _recordEvent( analyticsEventsQueue .add( 'event', - { analyticsId, userId, event, segmentation, isLoggedIn }, + { + analyticsId, + userId, + event, + segmentation, + isLoggedIn, + createdAt: new Date(), + }, { delay } ) .then(() => { @@ -157,10 +179,11 @@ function _setUserProperty({ analyticsId, propertyName, propertyValue }) { event_type: 'user-property', }) analyticsUserPropertiesQueue - .add({ + .add('user-property', { analyticsId, propertyName, propertyValue, + createdAt: new Date(), }) .then(() => { Metrics.analyticsQueue.inc({ diff --git a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js index d041c6e617..8e4c91601f 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js @@ -105,11 +105,15 @@ describe('AnalyticsManager', function () { projectId, countryCode ) - sinon.assert.calledWithMatch(this.analyticsEditingSessionQueue.add, { - userId: this.fakeUserId, - projectId, - countryCode, - }) + sinon.assert.calledWithMatch( + this.analyticsEditingSessionQueue.add, + 'editing-session', + { + userId: this.fakeUserId, + projectId, + countryCode, + } + ) }) }) })