From c87e70d15a6b91ff141cf08d261f15b06208d7c7 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 20 Jul 2022 09:33:44 +0100 Subject: [PATCH] Merge pull request #8946 from overleaf/jpa-pdf-caching-status [clsi] add a single metric to describe the status of pdf caching GitOrigin-RevId: c755b3c45ebb02296083a65e3753622787108776 --- services/clsi/app/js/ContentCacheMetrics.js | 6 ------ services/clsi/app/js/OutputCacheManager.js | 18 +++++++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/services/clsi/app/js/ContentCacheMetrics.js b/services/clsi/app/js/ContentCacheMetrics.js index e22e93ea9c..fd24fb431b 100644 --- a/services/clsi/app/js/ContentCacheMetrics.js +++ b/services/clsi/app/js/ContentCacheMetrics.js @@ -19,12 +19,6 @@ function getSystemLoad() { const ONE_MB = 1024 * 1024 function emitPdfStats(stats, timings, request) { - if (stats['pdf-caching-timed-out']) { - Metrics.inc('pdf-caching-timed-out', 1, request.metricsOpts) - } - if (stats['pdf-caching-queue-limit-reached']) { - Metrics.inc('pdf-caching-queue-limit-reached', 1, request.metricsOpts) - } if (timings['compute-pdf-caching']) { emitPdfCachingStats(stats, timings, request) } else { diff --git a/services/clsi/app/js/OutputCacheManager.js b/services/clsi/app/js/OutputCacheManager.js index 5654ef5893..2e1448b836 100644 --- a/services/clsi/app/js/OutputCacheManager.js +++ b/services/clsi/app/js/OutputCacheManager.js @@ -196,7 +196,11 @@ module.exports = OutputCacheManager = { outputFiles, compileDir, outputDir, - err => { + (err, status) => { + Metrics.inc('pdf-caching-status', 1, { + status, + ...request.metricsOpts, + }) if (err) { logger.warn( { err, outputDir, stats, timings }, @@ -372,7 +376,7 @@ module.exports = OutputCacheManager = { const cacheRoot = Path.join(outputDir, OutputCacheManager.CONTENT_SUBDIR) // check if content dir exists OutputCacheManager.ensureContentDir(cacheRoot, function (err, contentDir) { - if (err) return callback(err) + if (err) return callback(err, 'content-dir-unavailable') const outputFile = outputFiles.find(x => x.path === 'output.pdf') if (outputFile) { @@ -396,7 +400,7 @@ module.exports = OutputCacheManager = { if (err && err instanceof QueueLimitReachedError) { logger.warn({ err, outputDir }, 'pdf caching queue limit reached') stats['pdf-caching-queue-limit-reached'] = 1 - return callback(null) + return callback(null, 'queue-limit') } if (err && err instanceof TimedOutError) { logger.warn( @@ -404,9 +408,9 @@ module.exports = OutputCacheManager = { 'pdf caching timed out' ) stats['pdf-caching-timed-out'] = 1 - return callback(null) + return callback(null, 'timed-out') } - if (err) return callback(err) + if (err) return callback(err, 'failed') const [ contentRanges, newContentRanges, @@ -435,11 +439,11 @@ module.exports = OutputCacheManager = { 0 ) stats['pdf-caching-reclaimed-space'] = reclaimedSpace - callback(null) + callback(null, 'success') } ) } else { - callback(null) + callback(null, 'missing-pdf') } }) },