зеркало из https://github.com/github/docs.git
Instrument the subfunctions of warmServer with datadog (#16854)
Co-authored-by: James M. Greene <JamesMGreene@github.com>
This commit is contained in:
Родитель
e6518ff9c3
Коммит
33bd3e45d3
|
@ -4,6 +4,16 @@ const loadRedirects = require('./redirects/precompile')
|
|||
const loadSiteData = require('./site-data')
|
||||
const loadSiteTree = require('./site-tree')
|
||||
|
||||
// Instrument these functions so that
|
||||
// it's wrapped in a timer that reports to Datadog
|
||||
const dog = {
|
||||
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
|
||||
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
|
||||
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
|
||||
loadSiteData: statsd.asyncTimer(loadSiteData, 'load_site_data'),
|
||||
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
|
||||
}
|
||||
|
||||
// For local caching
|
||||
let pageList, pageMap, site, redirects, siteTree
|
||||
|
||||
|
@ -32,21 +42,21 @@ async function warmServer () {
|
|||
if (!pageList || !site) {
|
||||
// Promise.all is used to load multiple things in parallel
|
||||
[pageList, site] = await Promise.all([
|
||||
pageList || loadPages(),
|
||||
site || loadSiteData()
|
||||
pageList || dog.loadPages(),
|
||||
site || dog.loadSiteData()
|
||||
])
|
||||
}
|
||||
|
||||
if (!pageMap) {
|
||||
pageMap = await loadPageMap(pageList)
|
||||
pageMap = await dog.loadPageMap(pageList)
|
||||
}
|
||||
|
||||
if (!redirects) {
|
||||
redirects = await loadRedirects(pageList, pageMap)
|
||||
redirects = await dog.loadRedirects(pageList, pageMap)
|
||||
}
|
||||
|
||||
if (!siteTree) {
|
||||
siteTree = await loadSiteTree(pageMap, site, redirects)
|
||||
siteTree = await dog.loadSiteTree(pageMap, site, redirects)
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
|
@ -58,7 +68,7 @@ async function warmServer () {
|
|||
|
||||
// Instrument the `warmServer` function so that
|
||||
// it's wrapped in a timer that reports to Datadog
|
||||
const instrumentedWarmServer = statsd.asyncTimer(warmServer, 'warm_server')
|
||||
dog.warmServer = statsd.asyncTimer(warmServer, 'warm_server')
|
||||
|
||||
// We only want statistics if the priming needs to occur, so let's wrap the
|
||||
// real method and return early [without statistics] whenever possible
|
||||
|
@ -68,5 +78,5 @@ module.exports = async function warmServerWrapper () {
|
|||
return getWarmedCache()
|
||||
}
|
||||
|
||||
return instrumentedWarmServer()
|
||||
return dog.warmServer()
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче