Skip to content

Commit 33bd3e4

Browse files
heiskrJamesMGreene
andauthored
Instrument the subfunctions of warmServer with datadog (#16854)
Co-authored-by: James M. Greene <JamesMGreene@github.com>
1 parent e6518ff commit 33bd3e4

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

lib/warm-server.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ const loadRedirects = require('./redirects/precompile')
44
const loadSiteData = require('./site-data')
55
const loadSiteTree = require('./site-tree')
66

7+
// Instrument these functions so that
8+
// it's wrapped in a timer that reports to Datadog
9+
const dog = {
10+
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
11+
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
12+
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
13+
loadSiteData: statsd.asyncTimer(loadSiteData, 'load_site_data'),
14+
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
15+
}
16+
717
// For local caching
818
let pageList, pageMap, site, redirects, siteTree
919

@@ -32,21 +42,21 @@ async function warmServer () {
3242
if (!pageList || !site) {
3343
// Promise.all is used to load multiple things in parallel
3444
[pageList, site] = await Promise.all([
35-
pageList || loadPages(),
36-
site || loadSiteData()
45+
pageList || dog.loadPages(),
46+
site || dog.loadSiteData()
3747
])
3848
}
3949

4050
if (!pageMap) {
41-
pageMap = await loadPageMap(pageList)
51+
pageMap = await dog.loadPageMap(pageList)
4252
}
4353

4454
if (!redirects) {
45-
redirects = await loadRedirects(pageList, pageMap)
55+
redirects = await dog.loadRedirects(pageList, pageMap)
4656
}
4757

4858
if (!siteTree) {
49-
siteTree = await loadSiteTree(pageMap, site, redirects)
59+
siteTree = await dog.loadSiteTree(pageMap, site, redirects)
5060
}
5161

5262
if (process.env.NODE_ENV !== 'test') {
@@ -58,7 +68,7 @@ async function warmServer () {
5868

5969
// Instrument the `warmServer` function so that
6070
// it's wrapped in a timer that reports to Datadog
61-
const instrumentedWarmServer = statsd.asyncTimer(warmServer, 'warm_server')
71+
dog.warmServer = statsd.asyncTimer(warmServer, 'warm_server')
6272

6373
// We only want statistics if the priming needs to occur, so let's wrap the
6474
// real method and return early [without statistics] whenever possible
@@ -68,5 +78,5 @@ module.exports = async function warmServerWrapper () {
6878
return getWarmedCache()
6979
}
7080

71-
return instrumentedWarmServer()
81+
return dog.warmServer()
7282
}

0 commit comments

Comments
 (0)