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 _ = 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({

View file

@ -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,
}
)
})
})
})