Skip to content

Commit

Permalink
Instrument the subfunctions of warmServer with datadog (github#16854)
Browse files Browse the repository at this point in the history
Co-authored-by: James M. Greene <JamesMGreene@github.com>
  • Loading branch information
heiskr and JamesMGreene authored Dec 10, 2020
1 parent e6518ff commit 33bd3e4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/warm-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand All @@ -68,5 +78,5 @@ module.exports = async function warmServerWrapper () {
return getWarmedCache()
}

return instrumentedWarmServer()
return dog.warmServer()
}

0 comments on commit 33bd3e4

Please sign in to comment.