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
This commit is contained in:
Alexandre Bourdin 2021-09-30 17:27:27 +02:00 committed by Copybot
parent 73bc3418a2
commit 4d7e6d2707
2 changed files with 36 additions and 9 deletions

View file

@ -6,6 +6,7 @@ const Queues = require('../../infrastructure/Queues')
const uuid = require('uuid') const uuid = require('uuid')
const _ = require('lodash') const _ = require('lodash')
const { expressify } = require('../../util/promises') const { expressify } = require('../../util/promises')
const { logger } = require('logger-sharelatex')
const analyticsEventsQueue = Queues.getAnalyticsEventsQueue() const analyticsEventsQueue = Queues.getAnalyticsEventsQueue()
const analyticsEditingSessionsQueue = Queues.getAnalyticsEditingSessionsQueue() const analyticsEditingSessionsQueue = Queues.getAnalyticsEditingSessionsQueue()
@ -24,7 +25,7 @@ function identifyUser(userId, analyticsId, isNewUser) {
analyticsEventsQueue analyticsEventsQueue
.add( .add(
'identify', 'identify',
{ userId, analyticsId, isNewUser }, { userId, analyticsId, isNewUser, createdAt: new Date() },
{ delay: ONE_MINUTE_MS } { delay: ONE_MINUTE_MS }
) )
.then(() => { .then(() => {
@ -56,12 +57,21 @@ function recordEventForSession(session, event, segmentation) {
if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) { if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) {
return return
} }
logger.info({
analyticsId,
userId,
event,
segmentation,
isLoggedIn: !!userId,
createdAt: new Date(),
})
_recordEvent({ _recordEvent({
analyticsId, analyticsId,
userId, userId,
event, event,
segmentation, segmentation,
isLoggedIn: !!userId, isLoggedIn: !!userId,
createdAt: new Date(),
}) })
} }
@ -117,7 +127,12 @@ function updateEditingSession(userId, projectId, countryCode) {
event_type: 'editing-session', event_type: 'editing-session',
}) })
analyticsEditingSessionsQueue analyticsEditingSessionsQueue
.add({ userId, projectId, countryCode }) .add('editing-session', {
userId,
projectId,
countryCode,
createdAt: new Date(),
})
.then(() => { .then(() => {
Metrics.analyticsQueue.inc({ Metrics.analyticsQueue.inc({
status: 'added', status: 'added',
@ -140,7 +155,14 @@ function _recordEvent(
analyticsEventsQueue analyticsEventsQueue
.add( .add(
'event', 'event',
{ analyticsId, userId, event, segmentation, isLoggedIn }, {
analyticsId,
userId,
event,
segmentation,
isLoggedIn,
createdAt: new Date(),
},
{ delay } { delay }
) )
.then(() => { .then(() => {
@ -157,10 +179,11 @@ function _setUserProperty({ analyticsId, propertyName, propertyValue }) {
event_type: 'user-property', event_type: 'user-property',
}) })
analyticsUserPropertiesQueue analyticsUserPropertiesQueue
.add({ .add('user-property', {
analyticsId, analyticsId,
propertyName, propertyName,
propertyValue, propertyValue,
createdAt: new Date(),
}) })
.then(() => { .then(() => {
Metrics.analyticsQueue.inc({ Metrics.analyticsQueue.inc({

View file

@ -105,11 +105,15 @@ describe('AnalyticsManager', function () {
projectId, projectId,
countryCode countryCode
) )
sinon.assert.calledWithMatch(this.analyticsEditingSessionQueue.add, { sinon.assert.calledWithMatch(
userId: this.fakeUserId, this.analyticsEditingSessionQueue.add,
projectId, 'editing-session',
countryCode, {
}) userId: this.fakeUserId,
projectId,
countryCode,
}
)
}) })
}) })
}) })