Merge pull request #8911 from overleaf/jpa-pdf-detach-pdf-caching-metrics

[web] fix forwarding of pdf caching metrics in pdf-detach mode

GitOrigin-RevId: c4a65190102ca4abfb7970186bc5ee785bff14c6
This commit is contained in:
Jakob Ackermann 2022-07-20 09:15:41 +01:00 committed by Copybot
parent 9199669c0f
commit 0409676c41
3 changed files with 20 additions and 12 deletions

View file

@ -10,6 +10,7 @@ import withErrorBoundary from '../../../infrastructure/error-boundary'
import ErrorBoundaryFallback from './error-boundary-fallback'
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
import { captureException } from '../../../infrastructure/error-reporter'
import { getPdfCachingMetrics } from '../util/metrics'
function PdfJsViewer({ url, pdfFile }) {
const { _id: projectId } = useProjectContext()
@ -81,7 +82,12 @@ function PdfJsViewer({ url, pdfFile }) {
// We are omitting the render time in case we detect this state.
latencyRender = Math.ceil(timePDFRendered - timePDFFetched)
}
firstRenderDone({ latencyFetch, latencyRender })
firstRenderDone({
latencyFetch,
latencyRender,
// Let the pdfCachingMetrics round trip to account for pdf-detach.
pdfCachingMetrics: getPdfCachingMetrics(),
})
}
const handlePagesinit = () => {

View file

@ -4,15 +4,17 @@ import getMeta from '../../../utils/meta'
// VERSION should get incremented when making changes to caching behavior or
// adjusting metrics collection.
const VERSION = 3
const VERSION = 4
// editing session id
const EDITOR_SESSION_ID = uuid()
let pdfCachingMetrics
const pdfCachingMetrics = {
viewerId: EDITOR_SESSION_ID,
}
export function setCachingMetrics(metrics) {
pdfCachingMetrics = metrics
export function getPdfCachingMetrics() {
return pdfCachingMetrics
}
export function trackPdfDownload(response, compileTimeClientE2E, t0) {
@ -25,8 +27,9 @@ export function trackPdfDownload(response, compileTimeClientE2E, t0) {
// There can be multiple "first" renderings with two pdf viewers.
// E.g. two pdf detach tabs or pdf detacher plus pdf detach.
// Let the pdfCachingMetrics round trip to account for pdf-detach.
let isFirstRender = true
function firstRenderDone({ latencyFetch, latencyRender }) {
function firstRenderDone({ latencyFetch, latencyRender, pdfCachingMetrics }) {
if (!isFirstRender) return
isFirstRender = false
@ -43,6 +46,7 @@ export function trackPdfDownload(response, compileTimeClientE2E, t0) {
latencyFetch,
latencyRender,
compileTimeClientE2E,
...pdfCachingMetrics,
})
}
}
@ -58,8 +62,7 @@ function submitCompileMetrics(metrics) {
version: VERSION,
...metrics,
id: EDITOR_SESSION_ID,
...(pdfCachingMetrics || {}),
}
sl_console.log('/event/compile-metrics', JSON.stringify(metrics))
sl_console.log('/event/compile-metrics', JSON.stringify(leanMetrics))
sendMB('compile-metrics-v6', leanMetrics)
}

View file

@ -1,14 +1,14 @@
import { fallbackRequest, fetchRange } from './pdf-caching'
import getMeta from '../../../utils/meta'
import { captureException } from '../../../infrastructure/error-reporter'
import { setCachingMetrics } from './metrics'
import { getPdfCachingMetrics } from './metrics'
export function generatePdfCachingTransportFactory(PDFJS) {
if (getMeta('ol-pdfCachingMode') !== 'enabled') {
return () => null
}
const cached = new Set()
const metrics = {
const metrics = Object.assign(getPdfCachingMetrics(), {
failedCount: 0,
tooLargeOverheadCount: 0,
tooManyRequestsCount: 0,
@ -18,10 +18,9 @@ export function generatePdfCachingTransportFactory(PDFJS) {
fetchedBytes: 0,
requestedCount: 0,
requestedBytes: 0,
}
})
const verifyChunks =
new URLSearchParams(window.location.search).get('verify_chunks') === 'true'
setCachingMetrics(metrics)
class PDFDataRangeTransport extends PDFJS.PDFDataRangeTransport {
constructor(url, pdfFile, reject) {