Skip to content

fix: set user agent for purge requests #2730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@netlify/edge-bundler": "^12.2.3",
"@netlify/edge-functions": "^2.11.0",
"@netlify/eslint-config-node": "^7.0.1",
"@netlify/functions": "^2.8.2",
"@netlify/functions": "^3.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/netlify/functions/releases/tag/v3.0.0

Breaking change is not affecting us, as runtime already is node@>=18:

"engines": {
"node": ">=18.0.0"
},

"@netlify/serverless-functions-api": "^1.30.1",
"@netlify/zip-it-and-ship-it": "^9.41.0",
"@opentelemetry/api": "^1.8.0",
Expand Down
19 changes: 12 additions & 7 deletions src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { type Span } from '@opentelemetry/api'
import type { PrerenderManifest } from 'next/dist/build/index.js'
import { NEXT_CACHE_TAGS_HEADER } from 'next/dist/lib/constants.js'

import { name as nextRuntimePkgName, version as nextRuntimePkgVersion } from '../../../package.json'
import {
type CacheHandlerContext,
type CacheHandlerForMultipleVersions,
Expand All @@ -30,6 +31,8 @@ type TagManifest = { revalidatedAt: number }

type TagManifestBlobCache = Record<string, Promise<TagManifest>>

const purgeCacheUserAgent = `${nextRuntimePkgName}@${nextRuntimePkgVersion}`

export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
options: CacheHandlerContext
revalidatedTags: string[]
Expand Down Expand Up @@ -347,12 +350,14 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
const tag = `_N_T_${key === '/index' ? '/' : encodeURI(key)}`
getLogger().debug(`Purging CDN cache for: [${tag}]`)
requestContext.trackBackgroundWork(
purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => {
// TODO: add reporting here
getLogger()
.withError(error)
.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`)
}),
purgeCache({ tags: tag.split(/,|%2c/gi), userAgent: purgeCacheUserAgent }).catch(
(error) => {
// TODO: add reporting here
getLogger()
.withError(error)
.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`)
},
),
)
}
}
Expand Down Expand Up @@ -393,7 +398,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
}),
)

await purgeCache({ tags }).catch((error) => {
await purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => {
// TODO: add reporting here
getLogger()
.withError(error)
Expand Down
Loading