-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use dynamicMetadata to construct metadataMatchCriteria() #3254
Changes from 8 commits
bde0c9c
1747131
be4fe35
f1f12e0
b261a23
663c922
b24da82
d29a4a5
8b7bb04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,10 @@ | |
#include "common/common/hash.h" | ||
#include "common/common/hex.h" | ||
#include "common/common/logger.h" | ||
#include "common/config/well_known_names.h" | ||
#include "common/http/utility.h" | ||
#include "common/request_info/request_info_impl.h" | ||
#include "common/router/config_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Router { | ||
|
@@ -161,8 +163,27 @@ class Filter : Logger::Loggable<Logger::Id::router>, | |
} | ||
return {}; | ||
} | ||
const Router::MetadataMatchCriteria* metadataMatchCriteria() const override { | ||
const Router::MetadataMatchCriteria* metadataMatchCriteria() override { | ||
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. In the retry case you may end up calling this method multiple times. Is it worth checking to see if 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. I think checking for nullptr and returning early is worth it. Multiple calls to merge should yield the same result, but we can avoid the computation and creating new objects. 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. @mattklein123 hold on -- can the 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. I think it's ok, as long as metadataMatchCriteria() isn't invoked until LoadBalancer::chooseHost, which happens during Router::Filter::getConnPool in Filter::decodeHeaders and again in Filter::doRetry. The route_ and route_entry_ get set in decodeHeaders before load balancing, and I believe that once that happens they do not change. clearRouteCache operates on the Http::ConnectionManagerImpl::ActiveStreamFilterBase which ends up being the source of the route_ and therefore route_entry_ via its implementation of StreamFilterCallbacks::route(). 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. This seems right, can we add an ASSERT to this effect (i.e. if we get called twice, the route entry is the same)? |
||
if (route_entry_) { | ||
// Have we been called before? If so, there's no need to recompute because | ||
// by the time this method is called for the first time, route_entry_ should | ||
// not change anymore. | ||
if (metadata_match_ != nullptr) { | ||
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. Can you add a test for this as well? Thanks. 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. @htuch done — plus two bonus tests:
thanks for the review! |
||
return metadata_match_.get(); | ||
} | ||
|
||
// The request's metadata, if present, takes precedence over the route's. | ||
const auto& request_metadata = callbacks_->requestInfo().dynamicMetadata().filter_metadata(); | ||
const auto filter_it = request_metadata.find(Envoy::Config::MetadataFilters::get().ENVOY_LB); | ||
if (filter_it != request_metadata.end()) { | ||
if (route_entry_->metadataMatchCriteria() != nullptr) { | ||
metadata_match_ = | ||
route_entry_->metadataMatchCriteria()->mergeMatchCriteria(filter_it->second); | ||
} else { | ||
metadata_match_ = std::make_unique<Router::MetadataMatchCriteriaImpl>(filter_it->second); | ||
} | ||
return metadata_match_.get(); | ||
} | ||
return route_entry_->metadataMatchCriteria(); | ||
} | ||
return nullptr; | ||
|
@@ -343,6 +364,7 @@ class Filter : Logger::Loggable<Logger::Id::router>, | |
MonotonicTime downstream_request_complete_time_; | ||
uint32_t buffer_limit_{0}; | ||
bool stream_destroyed_{}; | ||
MetadataMatchCriteriaConstPtr metadata_match_; | ||
|
||
// list of cookies to add to upstream headers | ||
std::vector<std::string> downstream_set_cookies_; | ||
|
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.
Nit: which ProtobufWkt::Struct? Do you want to use @param and @return here?