Merge pull request #16536 from overleaf/bg-clsi-timeouts-add-metrics-to-filestore-readonly

Add metrics for tracking active signed URL calls in filestore readonly

GitOrigin-RevId: f366b56274ed665d753ff32de57b1a15b4ce9193
This commit is contained in:
Brian Gough 2024-01-16 15:20:39 +00:00 committed by Copybot
parent 74e7e69a3a
commit c20e1b13c8
2 changed files with 23 additions and 1 deletions

View file

@ -7,6 +7,7 @@ const FileConverter = require('./FileConverter')
const KeyBuilder = require('./KeyBuilder') const KeyBuilder = require('./KeyBuilder')
const ImageOptimiser = require('./ImageOptimiser') const ImageOptimiser = require('./ImageOptimiser')
const { ConversionError, InvalidParametersError } = require('./Errors') const { ConversionError, InvalidParametersError } = require('./Errors')
const metrics = require('@overleaf/metrics')
module.exports = { module.exports = {
insertFile: callbackify(insertFile), insertFile: callbackify(insertFile),
@ -77,6 +78,8 @@ async function getFile(bucket, key, opts) {
} }
} }
let ACTIVE_SIGNED_URL_CALLS = 0
async function getRedirectUrl(bucket, key, opts) { async function getRedirectUrl(bucket, key, opts) {
// if we're doing anything unusual with options, or the request isn't for // if we're doing anything unusual with options, or the request isn't for
// one of the default buckets, return null so that we proxy the file // one of the default buckets, return null so that we proxy the file
@ -89,7 +92,22 @@ async function getRedirectUrl(bucket, key, opts) {
Object.values(Settings.filestore.stores).includes(bucket) && Object.values(Settings.filestore.stores).includes(bucket) &&
Settings.filestore.allowRedirects Settings.filestore.allowRedirects
) { ) {
return PersistorManager.getRedirectUrl(bucket, key) // record the number of in-flight calls to generate signed URLs
metrics.gauge('active_signed_url_calls', ++ACTIVE_SIGNED_URL_CALLS, {
path: bucket,
})
try {
const timer = new metrics.Timer('signed_url_call_time', {
path: bucket,
})
const redirectUrl = await PersistorManager.getRedirectUrl(bucket, key)
timer.done()
return redirectUrl
} finally {
metrics.gauge('active_signed_url_calls', --ACTIVE_SIGNED_URL_CALLS, {
path: bucket,
})
}
} }
return null return null

View file

@ -83,6 +83,10 @@ describe('FileHandler', function () {
'./ImageOptimiser': ImageOptimiser, './ImageOptimiser': ImageOptimiser,
'@overleaf/settings': Settings, '@overleaf/settings': Settings,
'@overleaf/object-persistor': ObjectPersistor, '@overleaf/object-persistor': ObjectPersistor,
'@overleaf/metrics': {
gauge: sinon.stub(),
Timer: sinon.stub().returns({ done: sinon.stub() }),
},
fs, fs,
}, },
globals: { console }, globals: { console },