-
Notifications
You must be signed in to change notification settings - Fork 87
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
perf: memoize blobs requests in the request scope #2777
Merged
pieh
merged 14 commits into
main
from
michalpiechowiak/frb-1629-intermittent-proxy-timeouts-on-runtime-v594
Mar 28, 2025
+729
−170
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
03f168d
test: add test case with multiple fetches for same resource and test …
pieh 2e7a951
refactor: create simplified key-value store interface to interact wit…
pieh 2f7dee1
refactor: create reusable helper to record warnings
pieh 85d4eb9
perf: memoize blobs requests in the request scope
pieh 41bca90
Merge branch 'main' into michalpiechowiak/frb-1629-intermittent-proxy…
pieh 42977ed
refactor: rename RequestSpecificInMemoryCache to RequestScopedInMemor…
pieh cff9f73
refactor: modulurize blobs storage abstractions
pieh 9db4cf0
Merge remote-tracking branch 'origin/main' into michalpiechowiak/frb-…
pieh d2a7fac
chore: fix lint
pieh ca233ef
refactor: move non-CacheHandler related types and utils from cache-ty…
pieh 578fbc5
fix: add missing implementation for isTagManifest and isHtmlBlob type…
pieh 13a65c3
Merge branch 'main' into michalpiechowiak/frb-1629-intermittent-proxy…
pieh 7daeeca
chore: drop use of noOpInMemoryCache
mrstork a1d2780
Merge branch 'main' into michalpiechowiak/frb-1629-intermittent-proxy…
pieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: create reusable helper to record warnings
commit 2f7dee1bdc2ab01fef32807cea9a481357540a32
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import type { NextConfigComplete } from 'next/dist/server/config-shared.js' | |
import type { NetlifyCachedRouteValue, NetlifyCacheHandlerValue } from '../shared/cache-types.cjs' | ||
|
||
import { getLogger, RequestContext } from './handlers/request-context.cjs' | ||
import { recordWarning } from './handlers/tracer.cjs' | ||
import { getMemoizedKeyValueStoreBackedByRegionalBlobStore } from './regional-blob-store.cjs' | ||
|
||
const ALL_VARIATIONS = Symbol.for('ALL_VARIATIONS') | ||
|
@@ -145,13 +146,10 @@ export const adjustDateHeader = async ({ | |
// request context would contain lastModified value | ||
// this is not fatal as we have fallback, | ||
// but we want to know about it happening | ||
span.recordException( | ||
recordWarning( | ||
new Error('lastModified not found in requestContext, falling back to trying blobs'), | ||
span, | ||
) | ||
span.setAttributes({ | ||
severity: 'alert', | ||
warning: true, | ||
}) | ||
|
||
const cacheStore = getMemoizedKeyValueStoreBackedByRegionalBlobStore({ consistency: 'strong' }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming note - perhaps |
||
const cacheEntry = await cacheStore.get<NetlifyCacheHandlerValue>( | ||
|
@@ -164,15 +162,13 @@ export const adjustDateHeader = async ({ | |
if (!lastModified) { | ||
// this should never happen as we only execute this code path for cached responses | ||
// and those should always have lastModified value | ||
span.recordException( | ||
recordWarning( | ||
new Error( | ||
'lastModified not found in either requestContext or blobs, date header for cached response is not set', | ||
), | ||
span, | ||
) | ||
span.setAttributes({ | ||
severity: 'alert', | ||
warning: true, | ||
}) | ||
|
||
return | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCacheKeySpan
looked to be non-nullable, can we makespan
non-nullable here as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opennextjs-netlify/src/shared/cache-types.cts
Lines 210 to 214 in 41bca90
span
to pass it, so that's why I made it optional.Generally preferably we do pass span explicitly instead of getting "active span", because it's more stable on which span things would be recorded, but it's better to record at all than skip recording because we don't have reference to a span.
Alternative could be to make above linked code get active span and then make
span
here non-nullable, but I did want to simplify usage of it, but would be fine making that change (less "magic")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did attempt the alternative but to me it moved too much tracing related logic and checks to module that doesn't already have reference to containing span I mentioned above and concern of finding active span seems much more in
tracer.cts
module than modules that might want to record warnings, so I'd prefer to keep the signature of this function as it is