@@ -2,6 +2,7 @@ import type { Response, NextFunction } from 'express'
22import { fetchWithRetry } from '@/frame/lib/fetch-utils'
33
44import statsd from '@/observability/lib/statsd'
5+ import { createLogger } from '@/observability/logger'
56import {
67 firstVersionDeprecatedOnNewSite ,
78 lastVersionWithoutArchivedRedirectsFile ,
@@ -19,6 +20,8 @@ import getRedirect, { splitPathByLanguage } from '@/redirects/lib/get-redirect'
1920import getRemoteJSON from '@/frame/lib/get-remote-json'
2021import { ExtendedRequest } from '@/types'
2122
23+ const logger = createLogger ( import . meta. url )
24+
2225const OLD_PUBLIC_AZURE_BLOB_URL = 'https://githubdocs.azureedge.net'
2326// Old Azure Blob Storage `enterprise` container.
2427const OLD_AZURE_BLOB_ENTERPRISE_DIR = `${ OLD_PUBLIC_AZURE_BLOB_URL } /enterprise`
@@ -78,11 +81,17 @@ const cacheAggressively = (res: Response) => {
7881const 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