Skip to content

Commit 913b761

Browse files
author
Peter Bengtsson
authored
Measure how much proxying we're doing (#23175)
Part of #1284
1 parent 012881b commit 913b761

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

middleware/archived-enterprise-versions.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33
import slash from 'slash'
4+
import statsd from '../lib/statsd.js'
45
import {
56
firstVersionDeprecatedOnNewSite,
67
lastVersionWithoutArchivedRedirectsFile,
@@ -113,8 +114,16 @@ export default async function archivedEnterpriseVersions(req, res, next) {
113114
}
114115
}
115116

116-
try {
117-
const r = await got(getProxyPath(req.path, requestedVersion))
117+
const statsdTags = [`version:${requestedVersion}`]
118+
const doGet = () =>
119+
got(getProxyPath(req.path, requestedVersion), {
120+
throwHttpErrors: false,
121+
})
122+
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy', [
123+
...statsdTags,
124+
`path:${req.path}`,
125+
])()
126+
if (r.statusCode === 200) {
118127
res.set('x-robots-tag', 'noindex')
119128

120129
// 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) {
126135

127136
res.set('content-type', r.headers['content-type'])
128137
return res.send(r.body)
129-
} catch (err) {
130-
for (const fallbackRedirect of getFallbackRedirects(req, requestedVersion) || []) {
131-
try {
132-
await got(getProxyPath(fallbackRedirect, requestedVersion))
133-
cacheControl(res)
134-
return res.redirect(301, fallbackRedirect)
135-
} catch (err) {
136-
// noop
137-
}
138-
}
138+
}
139139

140-
return next()
140+
for (const fallbackRedirect of getFallbackRedirects(req, requestedVersion) || []) {
141+
const doGet = () =>
142+
got(getProxyPath(fallbackRedirect, requestedVersion), {
143+
throwHttpErrors: false,
144+
})
145+
146+
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy_fallback', [
147+
...statsdTags,
148+
`fallback:${fallbackRedirect}`,
149+
])()
150+
if (r.statusCode === 200) {
151+
cacheControl(res)
152+
return res.redirect(301, fallbackRedirect)
153+
}
141154
}
155+
156+
return next()
142157
}
143158

144159
// paths are slightly different depending on the version

0 commit comments

Comments
 (0)