From c20e1b13c8d4984f19f9aa2a94422975aebe54af Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 16 Jan 2024 15:20:39 +0000 Subject: [PATCH] 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 --- services/filestore/app/js/FileHandler.js | 20 ++++++++++++++++++- .../test/unit/js/FileHandlerTests.js | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/services/filestore/app/js/FileHandler.js b/services/filestore/app/js/FileHandler.js index f6446679d3..bcdc601677 100644 --- a/services/filestore/app/js/FileHandler.js +++ b/services/filestore/app/js/FileHandler.js @@ -7,6 +7,7 @@ const FileConverter = require('./FileConverter') const KeyBuilder = require('./KeyBuilder') const ImageOptimiser = require('./ImageOptimiser') const { ConversionError, InvalidParametersError } = require('./Errors') +const metrics = require('@overleaf/metrics') module.exports = { 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) { // 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 @@ -89,7 +92,22 @@ async function getRedirectUrl(bucket, key, opts) { Object.values(Settings.filestore.stores).includes(bucket) && 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 diff --git a/services/filestore/test/unit/js/FileHandlerTests.js b/services/filestore/test/unit/js/FileHandlerTests.js index 8158557ce5..d4899dd20a 100644 --- a/services/filestore/test/unit/js/FileHandlerTests.js +++ b/services/filestore/test/unit/js/FileHandlerTests.js @@ -83,6 +83,10 @@ describe('FileHandler', function () { './ImageOptimiser': ImageOptimiser, '@overleaf/settings': Settings, '@overleaf/object-persistor': ObjectPersistor, + '@overleaf/metrics': { + gauge: sinon.stub(), + Timer: sinon.stub().returns({ done: sinon.stub() }), + }, fs, }, globals: { console },