Skip to content

Commit 57f4714

Browse files
dependabot[bot]heiskrCopilot
authored
Bump hot-shots from 13.2.0 to 14.3.1 (#60887)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3ec5d39 commit 57f4714

8 files changed

Lines changed: 47 additions & 23 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"helmet": "^8.1.0",
218218
"highlight.js": "^11.11.1",
219219
"highlightjs-curl": "^1.3.0",
220-
"hot-shots": "^13.2.0",
220+
"hot-shots": "^14.3.1",
221221
"html-entities": "^2.5.6",
222222
"http-proxy-middleware": "^3.0.5",
223223
"imurmurhash": "^0.1.4",

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

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

4-
import statsd from '@/observability/lib/statsd'
4+
import statsd, { adaptForTimer } from '@/observability/lib/statsd'
55
import { createLogger } from '@/observability/logger'
66
import {
77
firstVersionDeprecatedOnNewSite,
@@ -252,7 +252,7 @@ export default async function archivedEnterpriseVersions(
252252

253253
const statsdTags = [`version:${requestedVersion}`]
254254
const startTime = Date.now()
255-
const r = await statsd.asyncTimer(doGet, 'archive_enterprise_proxy', [
255+
const r = await statsd.asyncTimer(adaptForTimer(doGet), 'archive_enterprise_proxy', [
256256
...statsdTags,
257257
`path:${req.path}`,
258258
])()

src/events/lib/hydro.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHmac } from 'crypto'
22
import { fetchWithRetry } from '@/frame/lib/fetch-utils'
33
import { isNil } from 'lodash-es'
4-
import statsd from '@/observability/lib/statsd'
4+
import statsd, { adaptForTimer } from '@/observability/lib/statsd'
55
import { report } from '@/observability/lib/failbot'
66
import { MAX_REQUEST_TIMEOUT } from '@/frame/lib/constants'
77
import { createLogger } from '@/observability/logger'
@@ -95,4 +95,6 @@ async function _publish(
9595
return response
9696
}
9797

98-
export const publish = statsd.asyncTimer(_publish, 'hydro.response_time')
98+
const _publishTimed = statsd.asyncTimer(adaptForTimer(_publish), 'hydro.response_time')
99+
export const publish: typeof _publish = (...args) =>
100+
_publishTimed(...(args as Parameters<typeof _publish>))

src/frame/lib/warm-server.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import statsd from '@/observability/lib/statsd'
1+
import statsd, { adaptForTimer } from '@/observability/lib/statsd'
22
import { loadUnversionedTree, loadSiteTree, loadPages, loadPageMap } from './page-data'
33
import loadRedirects from '@/redirects/lib/precompile'
44
import { createLogger } from '@/observability/logger'
@@ -17,12 +17,15 @@ type WarmServerResult = {
1717
// Instrument these functions so that
1818
// it's wrapped in a timer that reports to Datadog
1919
const dog = {
20-
loadUnversionedTree: statsd.asyncTimer(loadUnversionedTree, 'load_unversioned_tree'),
21-
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree'),
22-
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
23-
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
24-
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
25-
warmServer: statsd.asyncTimer(warmServer, 'warm_server'),
20+
loadUnversionedTree: statsd.asyncTimer(
21+
adaptForTimer(loadUnversionedTree),
22+
'load_unversioned_tree',
23+
),
24+
loadSiteTree: statsd.asyncTimer(adaptForTimer(loadSiteTree), 'load_site_tree'),
25+
loadPages: statsd.asyncTimer(adaptForTimer(loadPages), 'load_pages'),
26+
loadPageMap: statsd.asyncTimer(adaptForTimer(loadPageMap), 'load_page_map'),
27+
loadRedirects: statsd.asyncTimer(adaptForTimer(loadRedirects), 'load_redirects'),
28+
warmServer: statsd.asyncTimer(adaptForTimer(warmServer), 'warm_server'),
2629
}
2730

2831
// For multiple-triggered Promise sharing
@@ -59,7 +62,7 @@ async function warmServer(languagesOnly: string[] = []): Promise<WarmServerResul
5962
})
6063

6164
stepStart = Date.now()
62-
const pageMap = await dog.loadPageMap(pageList)
65+
const pageMap = await dog.loadPageMap(pageList, [])
6366
logger.info('warm-server: loadPageMap complete', {
6467
durationMs: Date.now() - stepStart,
6568
permalinkCount: Object.keys(pageMap).length,

src/frame/middleware/render-page.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { get } from 'lodash-es'
66
import { buildMiniTocFromCollected, type CollectedHeading } from '@/frame/lib/get-mini-toc-items'
77
import patterns from '@/frame/lib/patterns'
88
import FailBot from '@/observability/lib/failbot'
9-
import statsd from '@/observability/lib/statsd'
9+
import statsd, { adaptForTimer } from '@/observability/lib/statsd'
1010
import type { ExtendedRequest } from '@/types'
1111
import { allVersions } from '@/versions/lib/all-versions'
1212
import { transformerRegistry } from '@/article-api/transformers'
@@ -31,7 +31,9 @@ async function buildRenderedPage(req: ExtendedRequest): Promise<string> {
3131
context.collectMiniToc = collectMiniToc
3232
}
3333

34-
const pageRenderTimed = statsd.asyncTimer(page.render, STATSD_KEY_RENDER, [`path:${path}`])
34+
const pageRenderTimed = statsd.asyncTimer(adaptForTimer(page.render), STATSD_KEY_RENDER, [
35+
`path:${path}`,
36+
])
3537

3638
return (await pageRenderTimed(context)) as string
3739
}

src/observability/lib/statsd.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import StatsD from 'hot-shots'
1+
import StatsD, { TimerContext } from 'hot-shots'
22

33
const {
44
NODE_ENV,
@@ -33,3 +33,16 @@ const statsd = new StatsD({
3333
})
3434

3535
export default statsd
36+
37+
// hot-shots v14 changed asyncTimer/timer to inject a TimerContext as the
38+
// final argument of the wrapped function. This adapter lets callers keep
39+
// passing functions with their original signatures by appending an ignored
40+
// TimerContext parameter.
41+
export function adaptForTimer<P extends unknown[], R>(
42+
fn: (...args: P) => Promise<R>,
43+
): (...args: [...P, TimerContext]) => Promise<R> {
44+
return (...args) => {
45+
const original = args.slice(0, -1) as P
46+
return fn(...original)
47+
}
48+
}

src/search/middleware/general-search-middleware.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When a user directly hits our API e.g. /api/search/v1?query=foo, they will hit t
99
import { fetchWithRetry } from '@/frame/lib/fetch-utils'
1010
import { Request, Response, NextFunction } from 'express'
1111
import { errors } from '@elastic/elasticsearch'
12-
import statsd from '@/observability/lib/statsd'
12+
import statsd, { adaptForTimer } from '@/observability/lib/statsd'
1313

1414
import { getPathWithoutVersion, getPathWithoutLanguage } from '@/frame/lib/path-utils'
1515
import { getGeneralSearchResults } from '@/search/lib/get-elasticsearch-results/general-search'
@@ -94,7 +94,11 @@ export default async function contextualizeGeneralSearch(
9494
}
9595
} else {
9696
const tags: string[] = [`indexName:${indexName}`, `toplevels:${searchParams.toplevel.length}`]
97-
const timed = statsd.asyncTimer(getGeneralSearchResults, 'contextualize.search', tags)
97+
const timed = statsd.asyncTimer(
98+
adaptForTimer(getGeneralSearchResults),
99+
'contextualize.search',
100+
tags,
101+
)
98102
const getGeneralSearchArgs = {
99103
indexName,
100104
searchParams,

0 commit comments

Comments
 (0)