1
0
mirror of synced 2025-12-25 02:17:36 -05:00

Measure how much proxying we're doing (#23175)

Part of #1284
This commit is contained in:
Peter Bengtsson
2021-12-02 13:11:40 -05:00
committed by GitHub
parent 012881b9dd
commit 913b761c05

View File

@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'
import slash from 'slash'
import statsd from '../lib/statsd.js'
import {
firstVersionDeprecatedOnNewSite,
lastVersionWithoutArchivedRedirectsFile,
@@ -113,8 +114,16 @@ export default async function archivedEnterpriseVersions(req, res, next) {
}
}
try {
const r = await got(getProxyPath(req.path, requestedVersion))
const statsdTags = [`version:${requestedVersion}`]
const doGet = () =>
got(getProxyPath(req.path, requestedVersion), {
throwHttpErrors: false,
})
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy', [
...statsdTags,
`path:${req.path}`,
])()
if (r.statusCode === 200) {
res.set('x-robots-tag', 'noindex')
// make stubbed redirect files (which exist in versions <2.13) redirect with a 301
@@ -126,19 +135,25 @@ export default async function archivedEnterpriseVersions(req, res, next) {
res.set('content-type', r.headers['content-type'])
return res.send(r.body)
} catch (err) {
for (const fallbackRedirect of getFallbackRedirects(req, requestedVersion) || []) {
try {
await got(getProxyPath(fallbackRedirect, requestedVersion))
cacheControl(res)
return res.redirect(301, fallbackRedirect)
} catch (err) {
// noop
}
}
return next()
}
for (const fallbackRedirect of getFallbackRedirects(req, requestedVersion) || []) {
const doGet = () =>
got(getProxyPath(fallbackRedirect, requestedVersion), {
throwHttpErrors: false,
})
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy_fallback', [
...statsdTags,
`fallback:${fallbackRedirect}`,
])()
if (r.statusCode === 200) {
cacheControl(res)
return res.redirect(301, fallbackRedirect)
}
}
return next()
}
// paths are slightly different depending on the version