-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
HTTP consistent hash routing #496
Changes from 2 commits
0ad568c
8bc5661
c9a6e51
87041d2
a2761c9
da53644
e006b28
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 |
---|---|---|
|
@@ -5,6 +5,20 @@ | |
|
||
namespace Upstream { | ||
|
||
/** | ||
* Context passed to a load balancer to use when choosing a host. Not all load balancers make use | ||
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. nit: of all or any context information |
||
* of all context information. | ||
*/ | ||
class LoadBalancerContext { | ||
public: | ||
virtual ~LoadBalancerContext() {} | ||
|
||
/** | ||
* @return const Optional<uint64_t>& the optional hash key to use during load balancing. | ||
*/ | ||
virtual const Optional<uint64_t>& hashKey() const PURE; | ||
}; | ||
|
||
/** | ||
* Abstract load balancing interface. | ||
*/ | ||
|
@@ -14,8 +28,11 @@ class LoadBalancer { | |
|
||
/** | ||
* Ask the load balancer for the next host to use depending on the underlying LB algorithm. | ||
* @param context supplies the load balancer context. Not all load balancers make use of all | ||
* context information. Load balancers should be written to assume that context information | ||
* is missing and use sensible defaults. | ||
*/ | ||
virtual ConstHostPtr chooseHost() PURE; | ||
virtual ConstHostPtr chooseHost(const LoadBalancerContext* context) PURE; | ||
}; | ||
|
||
typedef std::unique_ptr<LoadBalancer> LoadBalancerPtr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -535,7 +535,15 @@ const std::string Json::Schema::ROUTE_ENTRY_CONFIGURATION_SCHEMA(R"EOF( | |
"additionalProperties" : false | ||
} | ||
}, | ||
"rate_limits" : {"type" : "array"} | ||
"rate_limits" : {"type" : "array"}, | ||
"hash_policy" : { | ||
"type" : "object", | ||
"properties" : { | ||
"header_name" : {"type" : "string"} | ||
}, | ||
"required" : ["header_name"], | ||
"additionalProperties" : false | ||
} | ||
}, | ||
"additionalProperties" : false | ||
} | ||
|
@@ -983,7 +991,7 @@ const std::string Json::Schema::CLUSTER_SCHEMA(R"EOF( | |
}, | ||
"lb_type" : { | ||
"type" : "string", | ||
"enum" : ["round_robin", "least_request", "random"] | ||
"enum" : ["round_robin", "least_request", "random", "ring_hash"] | ||
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 should be exposed as Also, we might want to add other consistent hashes in the future (like the less memory-hungry |
||
}, | ||
"hosts" : { | ||
"type" : "array", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,15 @@ class Filter : Logger::Loggable<Logger::Id::router>, public Http::StreamDecoderF | |
|
||
typedef std::unique_ptr<UpstreamRequest> UpstreamRequestPtr; | ||
|
||
struct LoadBalancerContextImpl : public Upstream::LoadBalancerContext { | ||
LoadBalancerContextImpl(const Optional<uint64_t>& hash) : hash_(hash) {} | ||
|
||
// Upstream::LoadBalancerContext | ||
const Optional<uint64_t>& hashKey() const override { return hash_; } | ||
|
||
Optional<uint64_t> hash_; | ||
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. const |
||
}; | ||
|
||
enum class UpstreamResetType { Reset, GlobalTimeout, PerTryTimeout }; | ||
|
||
Http::AccessLog::ResponseFlag | ||
|
@@ -185,6 +194,7 @@ class Filter : Logger::Loggable<Logger::Id::router>, public Http::StreamDecoderF | |
Event::Dispatcher& dispatcher, | ||
Upstream::ResourcePriority priority) PURE; | ||
Upstream::ResourcePriority finalPriority(); | ||
Http::ConnectionPool::Instance* getConnPool(); | ||
void maybeDoShadowing(); | ||
void onRequestComplete(); | ||
void onResetStream(); | ||
|
@@ -214,6 +224,7 @@ class Filter : Logger::Loggable<Logger::Id::router>, public Http::StreamDecoderF | |
Http::HeaderMap* downstream_headers_{}; | ||
Http::HeaderMap* downstream_trailers_{}; | ||
SystemTime downstream_request_complete_time_; | ||
std::unique_ptr<LoadBalancerContextImpl> lb_context_; | ||
|
||
bool downstream_response_started_ : 1; | ||
bool downstream_end_stream_ : 1; | ||
|
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.
additional