dynamic_modules: remote source: add caching for fetched modules#43974
dynamic_modules: remote source: add caching for fetched modules#43974wbpcode merged 4 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an in-memory cache for remotely fetched dynamic modules, which is a great performance improvement. The implementation is straightforward, adding the caching logic at the factory level to avoid redundant HTTP fetches for modules with the same SHA256. The cache invalidation logic for missing or unloadable files is also handled correctly. The added unit tests are comprehensive and cover both cache hits and cache invalidation scenarios.
I have one suggestion regarding code maintainability, related to how the path for the cached module is determined. Overall, this is a solid contribution.
| auto cached_path = std::filesystem::temp_directory_path() / | ||
| fmt::format("envoy_dynamic_module_{}.so", fetch_sha256); | ||
| remote_module_cache_[fetch_sha256] = cached_path.string(); |
There was a problem hiding this comment.
This code reconstructs the path to the temporary file where the dynamic module was saved by newDynamicModuleFromBytes. This path generation logic appears to be duplicated from what newDynamicModuleFromBytes does internally, which creates a fragile dependency on its implementation details. If the file naming convention in newDynamicModuleFromBytes were to change, this caching logic would break.
A more robust approach would be for newDynamicModuleFromBytes to return the path of the created file along with the module pointer, or for the DynamicModule object to store the path from which it was loaded. This would eliminate the need to reconstruct the path here.
While changing newDynamicModuleFromBytes might be out of scope for this PR, it would be beneficial to centralize the path generation logic into a shared helper function to reduce duplication and improve long-term maintainability.
Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
|
/retest |
wbpcode
left a comment
There was a problem hiding this comment.
Thanks for this great contribution. And tow comments are added. :)
| auto cache_it = remote_module_cache_.find(sha256); | ||
| if (cache_it != remote_module_cache_.end()) { |
There was a problem hiding this comment.
Do we need the remote_module_cache_? I think we may could only need to check the std::filesystem::exists(cached_path) and if the file is there, then the cache hit.
There was a problem hiding this comment.
Thank you so much for the review.
This makes sense. I was somehow trying to keep nack_on_cache_miss in my mind and not introduce a global cache key. But I think that's not avoidable in this PR.
| if (dynamic_module.ok()) { | ||
| // Cache hit — skip async fetch entirely. | ||
| return buildFilterFactoryCallback(std::move(dynamic_module.value()), proto_config, | ||
| module_config, context, scope); | ||
| } |
There was a problem hiding this comment.
I don't think we need the fallback because the hash of the file is used for caching. The re-fecthing won't resolve the problem if the file/content is invalid?
Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
|
/assign @wbpcode |
…yproxy#43974) **Commit Message**: dynamic_modules: remote source: add caching for fetched modules **Motivation** Follow up from envoyproxy#43818 and envoyproxy#43333 Next PR: `nack_on_cache_miss` support (NACK on cache miss + background fetch) **Additional Description**: `newDynamicModuleFromBytes` already writes fetched modules to a deterministic path based on SHA256. This PR adds a check before the async fetch: if the file already exists on disk, load it directly and skip the HTTP fetch entirely. It is a simple approach that forms base for the next PR. **Risk Level**: Low **Testing**: Added unit tests **Docs Changes**: NA **Release Notes**: Added Platform Specific Features: NA [Optional Runtime guard:] Not needed [Optional Fixes #Issue]: NA [Optional Fixes commit #PR or SHA]: NA [Optional Deprecated:]: NA [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] NA --------- Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
…yproxy#43974) **Commit Message**: dynamic_modules: remote source: add caching for fetched modules **Motivation** Follow up from envoyproxy#43818 and envoyproxy#43333 Next PR: `nack_on_cache_miss` support (NACK on cache miss + background fetch) **Additional Description**: `newDynamicModuleFromBytes` already writes fetched modules to a deterministic path based on SHA256. This PR adds a check before the async fetch: if the file already exists on disk, load it directly and skip the HTTP fetch entirely. It is a simple approach that forms base for the next PR. **Risk Level**: Low **Testing**: Added unit tests **Docs Changes**: NA **Release Notes**: Added Platform Specific Features: NA [Optional Runtime guard:] Not needed [Optional Fixes #Issue]: NA [Optional Fixes commit #PR or SHA]: NA [Optional Deprecated:]: NA [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] NA --------- Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com> Signed-off-by: Xuyang Tao <taoxuy@google.com>
…yproxy#43974) **Commit Message**: dynamic_modules: remote source: add caching for fetched modules **Motivation** Follow up from envoyproxy#43818 and envoyproxy#43333 Next PR: `nack_on_cache_miss` support (NACK on cache miss + background fetch) **Additional Description**: `newDynamicModuleFromBytes` already writes fetched modules to a deterministic path based on SHA256. This PR adds a check before the async fetch: if the file already exists on disk, load it directly and skip the HTTP fetch entirely. It is a simple approach that forms base for the next PR. **Risk Level**: Low **Testing**: Added unit tests **Docs Changes**: NA **Release Notes**: Added Platform Specific Features: NA [Optional Runtime guard:] Not needed [Optional Fixes #Issue]: NA [Optional Fixes commit #PR or SHA]: NA [Optional Deprecated:]: NA [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] NA --------- Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com> Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
…yproxy#43974) **Commit Message**: dynamic_modules: remote source: add caching for fetched modules **Motivation** Follow up from envoyproxy#43818 and envoyproxy#43333 Next PR: `nack_on_cache_miss` support (NACK on cache miss + background fetch) **Additional Description**: `newDynamicModuleFromBytes` already writes fetched modules to a deterministic path based on SHA256. This PR adds a check before the async fetch: if the file already exists on disk, load it directly and skip the HTTP fetch entirely. It is a simple approach that forms base for the next PR. **Risk Level**: Low **Testing**: Added unit tests **Docs Changes**: NA **Release Notes**: Added Platform Specific Features: NA [Optional Runtime guard:] Not needed [Optional Fixes #Issue]: NA [Optional Fixes commit #PR or SHA]: NA [Optional Deprecated:]: NA [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] NA --------- Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
Commit Message: dynamic_modules: remote source: add caching for fetched modules
Motivation
Follow up from #43818 and #43333
Next PR:
nack_on_cache_misssupport (NACK on cache miss + background fetch)Additional Description:
newDynamicModuleFromBytesalready writes fetched modules to a deterministic path based on SHA256. This PR adds a check before the async fetch: if the file already exists on disk, load it directly and skip the HTTP fetch entirely.It is a simple approach that forms base for the next PR.
Risk Level: Low
Testing: Added unit tests
Docs Changes: NA
Release Notes: Added
Platform Specific Features: NA
[Optional Runtime guard:] Not needed
[Optional Fixes #Issue]: NA
[Optional Fixes commit #PR or SHA]: NA
[Optional Deprecated:]: NA
[Optional API Considerations:] NA