mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 17:23:48 -05:00
Merge pull request #14732 from overleaf/jpa-split-test-metrics
[web] collect metrics for split test system GitOrigin-RevId: 6440b9b9d9900cb8eac9a82ab2f62ae93d7e502a
This commit is contained in:
parent
b77f4f1379
commit
7b472bcd80
2 changed files with 46 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
const Metrics = require('@overleaf/metrics')
|
||||
const SplitTestManager = require('./SplitTestManager')
|
||||
const { CacheLoader } = require('cache-flow')
|
||||
|
||||
|
@ -9,6 +10,9 @@ class SplitTestCache extends CacheLoader {
|
|||
}
|
||||
|
||||
async load(name) {
|
||||
Metrics.inc('split_test_get_split_test_from_mongo', 1, {
|
||||
path: name,
|
||||
})
|
||||
const splitTest = await SplitTestManager.getSplitTest({
|
||||
name,
|
||||
archived: { $ne: true },
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const Metrics = require('@overleaf/metrics')
|
||||
const UserGetter = require('../User/UserGetter')
|
||||
const UserUpdater = require('../User/UserUpdater')
|
||||
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
|
@ -79,6 +80,7 @@ async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
|
|||
session: req.session,
|
||||
sync,
|
||||
})
|
||||
_collectSessionStats(req.session)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,9 +225,19 @@ async function _getAssignment(
|
|||
currentVersion
|
||||
)
|
||||
if (cachedVariant) {
|
||||
Metrics.inc('split_test_get_assignment_source', 1, { status: 'cache' })
|
||||
return _makeAssignment(splitTest, cachedVariant, currentVersion)
|
||||
}
|
||||
}
|
||||
|
||||
if (user) {
|
||||
Metrics.inc('split_test_get_assignment_source', 1, { status: 'provided' })
|
||||
} else if (userId) {
|
||||
Metrics.inc('split_test_get_assignment_source', 1, { status: 'mongo' })
|
||||
} else {
|
||||
Metrics.inc('split_test_get_assignment_source', 1, { status: 'none' })
|
||||
}
|
||||
|
||||
user = user || (userId && (await _getUser(userId)))
|
||||
const { activeForUser, selectedVariantName, phase, versionNumber } =
|
||||
await _getAssignmentMetadata(analyticsId, user, splitTest)
|
||||
|
@ -386,12 +398,18 @@ function _getCachedVariantFromSession(session, splitTestName, currentVersion) {
|
|||
}
|
||||
|
||||
async function _getUser(id) {
|
||||
return UserGetter.promises.getUser(id, {
|
||||
const user = await UserGetter.promises.getUser(id, {
|
||||
analyticsId: 1,
|
||||
splitTests: 1,
|
||||
alphaProgram: 1,
|
||||
betaProgram: 1,
|
||||
})
|
||||
Metrics.histogram(
|
||||
'split_test_get_user_from_mongo_size',
|
||||
JSON.stringify(user).length,
|
||||
[0, 100, 500, 1000, 2000, 5000, 10000, 15000, 20000, 50000, 100000]
|
||||
)
|
||||
return user
|
||||
}
|
||||
|
||||
async function _loadSplitTestInfoInLocals(locals, splitTestName) {
|
||||
|
@ -417,6 +435,29 @@ function _getNonSaasAssignment(splitTestName) {
|
|||
return DEFAULT_ASSIGNMENT
|
||||
}
|
||||
|
||||
function _collectSessionStats(session) {
|
||||
if (session.cachedSplitTestAssignments) {
|
||||
Metrics.summary(
|
||||
'split_test_session_cache_count',
|
||||
Object.keys(session.cachedSplitTestAssignments).length
|
||||
)
|
||||
Metrics.summary(
|
||||
'split_test_session_cache_size',
|
||||
JSON.stringify(session.cachedSplitTestAssignments).length
|
||||
)
|
||||
}
|
||||
if (session.splitTests) {
|
||||
Metrics.summary(
|
||||
'split_test_session_storage_count',
|
||||
Object.keys(session.splitTests).length
|
||||
)
|
||||
Metrics.summary(
|
||||
'split_test_session_storage_size',
|
||||
JSON.stringify(session.splitTests).length
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPercentile,
|
||||
getAssignment: callbackify(getAssignment),
|
||||
|
|
Loading…
Reference in a new issue