Skip to content
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

ext_proc: Support clearing the route cache #16288

Merged
merged 1 commit into from
May 5, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ message CommonResponse {
// along with the CONTINUE_AND_REPLACE status.
config.core.v3.HeaderMap trailers = 4;

// [#not-implemented-hide:]
// Clear the route cache for the current request.
// This is necessary if the remote server
// modified headers that are used to calculate the route.
Expand Down

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

6 changes: 6 additions & 0 deletions source/extensions/filters/http/ext_proc/processor_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bool ProcessorState::handleHeadersResponse(const HeadersResponse& response) {
if (callback_state_ == CallbackState::HeadersCallback) {
ENVOY_LOG(debug, "applying headers response");
MutationUtils::applyCommonHeaderResponse(response, *headers_);
if (response.response().clear_route_cache()) {
filter_callbacks_->clearRouteCache();
}
callback_state_ = CallbackState::Idle;
clearWatermark();
message_timer_->disableTimer();
Expand Down Expand Up @@ -66,6 +69,9 @@ bool ProcessorState::handleBodyResponse(const BodyResponse& response) {
modifyBufferedData([this, &response](Buffer::Instance& data) {
MutationUtils::applyCommonBodyResponse(response, headers_, data);
});
if (response.response().clear_route_cache()) {
filter_callbacks_->clearRouteCache();
Copy link
Member

Choose a reason for hiding this comment

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

Since routing doesn't use the body, does it make sense to clear here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the body is in buffered mode, it's possible to set headers when responding to the body callback, so it's possible that someone will want this.

}
headers_ = nullptr;
callback_state_ = CallbackState::Idle;
message_timer_->disableTimer();
Expand Down
43 changes: 43 additions & 0 deletions test/extensions/filters/http/ext_proc/filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,49 @@ TEST_F(HttpFilterTest, ProcessingModeResponseHeadersOnly) {
EXPECT_EQ(1, config_->stats().streams_closed_.value());
}

// Using the default configuration, verify that the "clear_route_cache_ flag makes the appropriate
// callback on the filter.
TEST_F(HttpFilterTest, ClearRouteCache) {
initialize(R"EOF(
grpc_service:
envoy_grpc:
cluster_name: "ext_proc_server"
processing_mode:
response_body_mode: "BUFFERED"
)EOF");

// Create synthetic HTTP request
HttpTestUtility::addDefaultHeaders(request_headers_, "GET");

EXPECT_EQ(FilterHeadersStatus::StopIteration, filter_->decodeHeaders(request_headers_, true));

EXPECT_CALL(decoder_callbacks_, clearRouteCache());
processRequestHeaders(false, [](const HttpHeaders&, ProcessingResponse&, HeadersResponse& resp) {
resp.mutable_response()->set_clear_route_cache(true);
});

EXPECT_EQ(FilterHeadersStatus::StopIteration, filter_->encodeHeaders(response_headers_, false));
processResponseHeaders(true, absl::nullopt);

Buffer::OwnedImpl resp_data("foo");
Buffer::OwnedImpl buffered_response_data;
setUpEncodingBuffering(buffered_response_data);

EXPECT_EQ(FilterDataStatus::StopIterationNoBuffer, filter_->encodeData(resp_data, true));

EXPECT_CALL(encoder_callbacks_, clearRouteCache());
processResponseBody([](const HttpBody&, ProcessingResponse&, BodyResponse& resp) {
resp.mutable_response()->set_clear_route_cache(true);
});

filter_->onDestroy();

EXPECT_EQ(1, config_->stats().streams_started_.value());
EXPECT_EQ(3, config_->stats().stream_msgs_sent_.value());
EXPECT_EQ(3, config_->stats().stream_msgs_received_.value());
EXPECT_EQ(1, config_->stats().streams_closed_.value());
}

// Using the default configuration, test the filter with a processor that
// replies to the request_headers message incorrectly by sending a
// request_body message, which should result in the stream being closed
Expand Down