-
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
Merged
htuch
merged 9 commits into
envoyproxy:master
from
rgs1:merge-request-info-dynamic-metadata-for-lb
May 4, 2018
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bde0c9c
Use dynamicMetadata to construct metadataMatchCriteria()
1747131
Fix formatting issues
be4fe35
Fix more tests
f1f12e0
Add a test for overriding metadata matcha via dynamic metadata
b261a23
Handle route_entry_->metadataMatchCriteria() == nullptr
663c922
Fix formatting
b24da82
Improve method docs.
d29a4a5
Return the cached result of metadataMatchCriteria()
8b7bb04
More tests
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
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
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 |
---|---|---|
|
@@ -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 { | ||
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_; | ||
|
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
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
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
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
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.
In the retry case you may end up calling this method multiple times. Is it worth checking to see if
metadata_match_
is not nullptr and returning if not? Is there any chance that doing the merge multiple times could have strange effects? If not to both of these, I would still add a comment about how this can happen multiple times for a single request.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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
@mattklein123 hold on -- can the
route_entry_
for a request change (e.g.: someone calledclearRouteCache()
and thenmetadataMatchCriteria()
gets called again)? In that case, caching the result formetadataMatchCriteria()
would be wrong... we'd want to recompute.cc: @zuercher @htuch
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 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 comment
The 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)?