Repository navigation
http::cache: Adds serving HEAD requests from cache. - #15910
Conversation
Relevant issue: envoyproxy#10020 Signed-off-by: Eleonora Kiziv <[email protected]>
|
Hi @ekiziv, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
rojkov
left a comment
There was a problem hiding this comment.
Thank you! I've left some comments regarding coding style.
You may also want to automate running format checks before git push with ./support/bootstrap.
| // Note that if a request is not cacheable according to 'isCacheableRequest' | ||
| // then its response is also not cacheable. | ||
| // Therefore, isCacheableRequest, isCacheableResponse and CacheFilter::request_allows_inserts_ |
There was a problem hiding this comment.
The references to isCacheableRequest here should be updated to CanServeRequestFromCache.
| // request cache-control headers only decide whether | ||
| // validation is required and whether the response can be cached. | ||
| static bool isCacheableRequest(const Http::RequestHeaderMap& headers); | ||
| static bool CanServeRequestFromCache(const Http::RequestHeaderMap& headers); |
There was a problem hiding this comment.
For functions we use camelCased names. Envoy's coding style diverges from Google's here.
|
|
||
| TEST_P(CacheIntegrationTest, ServeHeadFromCacheAfterGetRequest) { | ||
| useAccessLog("%RESPONSE_FLAGS% %RESPONSE_CODE_DETAILS%"); | ||
| simTime().setSystemTime(std::chrono::hours(1)); |
There was a problem hiding this comment.
nit: perhaps this line needs the same comment as in the cases above for consistency:
// Set system time to cause Envoy's cached formatted time to match time on this thread.|
|
||
| TEST_P(CacheIntegrationTest, ServeGetFromUpstreamAfterHeadRequest) { | ||
| useAccessLog("%RESPONSE_FLAGS% %RESPONSE_CODE_DETAILS%"); | ||
| simTime().setSystemTime(std::chrono::hours(1)); |
| return Http::FilterHeadersStatus::Continue; | ||
| } | ||
| if (!CacheabilityUtils::isCacheableRequest(headers)) { | ||
| if (!CacheabilityUtils::CanServeRequestFromCache(headers)) { |
There was a problem hiding this comment.
canServeRequestFromCache per envoy style guide
| response_decoder->waitForEndStream(); | ||
| EXPECT_TRUE(response_decoder->complete()); | ||
| EXPECT_THAT(response_decoder->headers(), IsSupersetOfHeaders(response_headers)); | ||
| EXPECT_TRUE(response_decoder->headers().get(Http::Headers::get().Age).empty()); |
There was a problem hiding this comment.
minor suggestion: this is all over this file in pre-existing code, but if you compare a string to "" with EXPECT_EQ, you'll get more potentially actionable info in the test log if it fails.
Feel free to either ignore this or fix all of them :)
There was a problem hiding this comment.
Thank you for your suggestion. I tried following it, however, turns out that response_decoder->headers().get(Http::Headers::get().Age) returns an Envoy::Http::HeaderMap::GetResult, which contains an absl::InlinedVector<HeaderEntry*, 1>. Therefore, as far as I understand, empty() is to check for an empty list and not an empty string.
There was a problem hiding this comment.
Ah in that case compare size to 0, or better yet compare the vector to the expected empty vector using the gtest macros for that.
| simTime().setSystemTime(std::chrono::hours(1)); | ||
| initializeFilter(default_config); | ||
|
|
||
| const Http::TestRequestHeaderMapImpl request_headers = { |
There was a problem hiding this comment.
high level question on the test structure. There are a lot of common (or maybe mostly common) stanzas of code in all your new tests. Would it be worth factoring these out into common helper methods in the test-class? The benefit is that by factoring out the common boilerplate, it might be easier to scan over the tests and see what the differences are.
There was a problem hiding this comment.
I have refactored the tests slightly, nevertheless ensuring that I always EXPECT in the tests rather than in the helper methods to make it really clear what is being tested. Let me know what you think!
There was a problem hiding this comment.
This looks better, and I agree. Thank you!
…n_test.cc to reduce code duplication. Signed-off-by: Eleonora Kiziv <[email protected]>
| } | ||
|
|
||
| Http::TestResponseHeaderMapImpl httpResponseHeadersForBody( | ||
| std::string body, std::string cache_control = "public,max-age=3600", |
There was a problem hiding this comment.
pass by absl::string_view or const std::string&
| } | ||
|
|
||
| IntegrationStreamDecoderPtr sendHeaderOnlyRequestAwaitResponse( | ||
| Http::TestRequestHeaderMapImpl headers, std::function<void()> simulate_upstream = []() {}) { |
There was a problem hiding this comment.
const Http::TestRequestHeaderMapImpl&
| return response_decoder; | ||
| } | ||
|
|
||
| std::function<void()> simulateUpstreamResponse(Http::TestResponseHeaderMapImpl headers, |
| simTime().setSystemTime(std::chrono::hours(1)); | ||
| initializeFilter(default_config); | ||
|
|
||
| const Http::TestRequestHeaderMapImpl request_headers = { |
There was a problem hiding this comment.
This looks better, and I agree. Thank you!
| response_decoder->waitForEndStream(); | ||
| EXPECT_TRUE(response_decoder->complete()); | ||
| EXPECT_THAT(response_decoder->headers(), IsSupersetOfHeaders(response_headers)); | ||
| EXPECT_TRUE(response_decoder->headers().get(Http::Headers::get().Age).empty()); |
There was a problem hiding this comment.
Ah in that case compare size to 0, or better yet compare the vector to the expected empty vector using the gtest macros for that.
|
Also you need to fix format before CI runs. /wait |
Signed-off-by: Eleonora Kiziv <[email protected]>
jmarantz
left a comment
There was a problem hiding this comment.
Looks great modulo one nit.
@envoyproxy/senior-maintainers
| } | ||
|
|
||
| std::function<void()> simulateUpstreamResponse(const Http::TestResponseHeaderMapImpl& headers, | ||
| const std::string* body) { |
There was a problem hiding this comment.
nit: Try OptRef<std::string>, found in include/envoy/common/optref.h for a more Envoy-idiomatic way of doing this.
|
/assign-from @envoyproxy/senior-maintainers |
|
@envoyproxy/senior-maintainers assignee is @htuch |
std::string>body. Signed-off-by: Eleonora Kiziv <[email protected]>
| // Stop the encoding stream until the cached response is fetched & added to the encoding stream. | ||
| return Http::FilterHeadersStatus::StopIteration; | ||
| if (is_head_request_) { | ||
| // Return since head requests are not cached |
There was a problem hiding this comment.
Nit: remove double spacing after Return, capitalize HEAD
| } | ||
|
|
||
| if (lookup_result_->content_length_ > 0) { | ||
| if (filter_state_ == FilterState::EncodeServingFromCache && is_head_request_) { |
There was a problem hiding this comment.
Coverage is actually fine in this PR, but more generally, this filter is missing a bunch of coverage, e.g. the red in https://storage.googleapis.com/envoy-pr/a8f4dde/coverage/source/extensions/filters/http/cache/cache_filter.cc.gcov.html.
@ekiziv @toddmgreer @jmarantz it would be great if we can get this filter up to full coverage, doesn't seem to be huge amount of extra testing needed.
There was a problem hiding this comment.
I will address this in the followup PR! :)
| *decoder_callbacks_, headers); | ||
| return Http::FilterHeadersStatus::Continue; | ||
| } | ||
| if (!CacheabilityUtils::isCacheableRequest(headers)) { |
There was a problem hiding this comment.
@ekiziv can you add a version history entry for this feature in https://www.envoyproxy.io/docs/envoy/latest/version_history/current? Thanks. LGTM otherwise.
Signed-off-by: Eleonora Kiziv <[email protected]>
htuch
left a comment
There was a problem hiding this comment.
LGTM, but needs main merge! Thanks.
* http::cache: Adds serving HEAD requests from cache. Relevant issue: envoyproxy#10020 Signed-off-by: Eleonora Kiziv <[email protected]> Commit Message: Adds serving HEAD requests from cache. Does not add storing HEAD responses in cache. Additional Description: Relevant issue: envoyproxy#10020 Risk Level: Low Testing: Unit, integration Signed-off-by: Eleonora Kiziv <[email protected]> Signed-off-by: Gokul Nair <[email protected]>
* http::cache: Adds serving HEAD requests from cache. Relevant issue: envoyproxy#10020 Signed-off-by: Eleonora Kiziv <[email protected]> Commit Message: Adds serving HEAD requests from cache. Does not add storing HEAD responses in cache. Additional Description: Relevant issue: envoyproxy#10020 Risk Level: Low Testing: Unit, integration Signed-off-by: Eleonora Kiziv <[email protected]> Signed-off-by: Gokul Nair <[email protected]>
Signed-off-by: Eleonora Kiziv [email protected]
Commit Message: Adds serving HEAD requests from cache. Does not add storing HEAD responses in cache.
Additional Description: Relevant issue: #10020
Risk Level: Low
Testing: Unit, integration