Skip to content

Commit 2849f8b

Browse files
EbonsignoriCopilot
andauthored
[Sentry Auto-Fix] DOCS-2JX: Error: Request timed out after 1500ms (#59286)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Ebonsignori <17055832+Ebonsignori@users.noreply.github.com>
1 parent 676fc70 commit 2849f8b

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

src/archives/middleware/archived-enterprise-versions.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Response, NextFunction } from 'express'
22
import { fetchWithRetry } from '@/frame/lib/fetch-utils'
33

44
import statsd from '@/observability/lib/statsd'
5+
import { createLogger } from '@/observability/logger'
56
import {
67
firstVersionDeprecatedOnNewSite,
78
lastVersionWithoutArchivedRedirectsFile,
@@ -19,6 +20,8 @@ import getRedirect, { splitPathByLanguage } from '@/redirects/lib/get-redirect'
1920
import getRemoteJSON from '@/frame/lib/get-remote-json'
2021
import { ExtendedRequest } from '@/types'
2122

23+
const logger = createLogger(import.meta.url)
24+
2225
const OLD_PUBLIC_AZURE_BLOB_URL = 'https://githubdocs.azureedge.net'
2326
// Old Azure Blob Storage `enterprise` container.
2427
const OLD_AZURE_BLOB_ENTERPRISE_DIR = `${OLD_PUBLIC_AZURE_BLOB_URL}/enterprise`
@@ -78,11 +81,17 @@ const cacheAggressively = (res: Response) => {
7881
const retryConfiguration = { limit: 3 }
7982
// According to our Datadog metrics, the *average* time for the
8083
// the 'archive_enterprise_proxy' metric is ~70ms (excluding spikes)
81-
// which much less than 1500ms.
84+
// which is much less than 3000ms.
8285
// We have observed errors of timeout, in production, when it was
83-
// set to 500ms. Let's try to be very conservative here to avoid
84-
// unnecessary error reporting.
85-
const timeoutConfiguration = { response: 1500 }
86+
// set to 500ms and then 1500ms. Let's be more conservative here to
87+
// avoid unnecessary error reporting during occasional slow responses.
88+
const timeoutConfiguration = { response: 3000 }
89+
90+
// Monitoring thresholds for logging response times
91+
// Log warnings when responses exceed half the timeout threshold
92+
const WARN_RESPONSE_THRESHOLD = timeoutConfiguration.response / 2 // 1500ms
93+
// Log info for responses that are noticeably slow but not concerning
94+
const SLOW_RESPONSE_THRESHOLD = 500 // ms
8695

8796
// This module handles requests for deprecated GitHub Enterprise versions
8897
// by routing them to static content in
@@ -201,10 +210,44 @@ export default async function archivedEnterpriseVersions(
201210
)
202211

203212
const statsdTags = [`version:${requestedVersion}`]
213+
const startTime = Date.now()
204214
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy', [
205215
...statsdTags,
206216
`path:${req.path}`,
207217
])()
218+
const responseTime = Date.now() - startTime
219+
220+
// Log warnings for slow responses to help identify degraded performance
221+
// A response time over half the timeout indicates potential issues
222+
if (responseTime > WARN_RESPONSE_THRESHOLD) {
223+
logger.warn('Slow response from archived enterprise content', {
224+
version: requestedVersion,
225+
path: req.path,
226+
responseTime: `${responseTime}ms`,
227+
status: r.status,
228+
threshold: `${WARN_RESPONSE_THRESHOLD}ms`,
229+
})
230+
}
231+
232+
// Log errors for non-200 responses to help identify issues with archived content
233+
if (r.status !== 200) {
234+
logger.error('Failed to fetch archived enterprise content', {
235+
version: requestedVersion,
236+
path: req.path,
237+
status: r.status,
238+
responseTime: `${responseTime}ms`,
239+
url: getProxyPath(req.path, requestedVersion),
240+
})
241+
}
242+
243+
// Log successful responses with timing for monitoring trends
244+
if (r.status === 200 && responseTime > SLOW_RESPONSE_THRESHOLD) {
245+
logger.info('Archived enterprise content response', {
246+
version: requestedVersion,
247+
responseTime: `${responseTime}ms`,
248+
status: r.status,
249+
})
250+
}
208251

209252
if (r.status === 200) {
210253
const body = await r.text()
@@ -317,6 +360,7 @@ export default async function archivedEnterpriseVersions(
317360

318361
return res.send(modifiedBody)
319362
}
363+
320364
// In releases 2.13 - 2.17, we lost access to frontmatter redirects
321365
// during the archival process. This workaround finds potentially
322366
// relevant frontmatter redirects in currently supported pages

0 commit comments

Comments
 (0)