-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upstream: add interfaces for priority/host retry selection extension …
…points (#4212) This adds the necessary configuration and interfaces to register implementations of RetryPriority and RetryHostPredicate, which will allow configuring smarter host selection during retries. Part of #3958 Risk Level: low, api changes Testing: n/a Doc Changes: inline Release Notes:n/a Signed-off-by: Snow Pettersen <snowp@squareup.com>
- Loading branch information
Showing
11 changed files
with
180 additions
and
18 deletions.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#pragma once | ||
|
||
#include "envoy/upstream/upstream.h" | ||
|
||
namespace Envoy { | ||
namespace Upstream { | ||
|
||
// Redeclare this here in order to get around cyclical dependencies. | ||
typedef std::vector<uint32_t> PriorityLoad; | ||
|
||
/** | ||
* Used to optionally modify the PriorityLoad when selecting a priority for | ||
* a retry attempt. | ||
* | ||
* Each RetryPriority will live throughout the lifetime of a request and updated | ||
* with attempted hosts through onHostAttempted. | ||
*/ | ||
class RetryPriority { | ||
public: | ||
virtual ~RetryPriority() {} | ||
|
||
/** | ||
* Determines what PriorityLoad to use. | ||
* | ||
* @param priority_state current state of cluster. | ||
* @param original_priority the unmodified PriorityLoad. | ||
* @return a reference to the PriorityLoad to use. Return original_priority if no changes should | ||
* be made. | ||
*/ | ||
virtual PriorityLoad& determinePriorityLoad(const PriorityState& priority_state, | ||
const PriorityLoad& original_priority) PURE; | ||
|
||
/** | ||
* Called after a host has been attempted but before host selection for the next attempt has | ||
* begun. | ||
* | ||
* @param attempted_host the host that was previously attempted. | ||
*/ | ||
virtual void onHostAttempted(HostSharedPtr attempted_host) PURE; | ||
}; | ||
|
||
typedef std::shared_ptr<RetryPriority> RetryPrioritySharedPtr; | ||
|
||
/** | ||
* Used to decide whether a selected host should be rejected during retries. Host selection will be | ||
* reattempted until either the host predicate accepts the host or a configured max number of | ||
* attempts is reached. | ||
* | ||
* Each RetryHostPredicate will live throughout the lifetime of a request and updated | ||
* with attempted hosts through onHostAttempted. | ||
*/ | ||
class RetryHostPredicate { | ||
public: | ||
virtual ~RetryHostPredicate() {} | ||
|
||
/** | ||
* Determines whether a host should be rejected during host selection. | ||
* | ||
* @param candidate_host the host to either reject or accept. | ||
* @return whether the host should be rejected and host selection reattempted. | ||
*/ | ||
virtual bool shouldSelectAnotherHost(const Host& candidate_host) PURE; | ||
|
||
/** | ||
* Called after a host has been attempted but before host selection for the next attempt has | ||
* begun. | ||
* | ||
* @param attempted_host the host that was previously attempted. | ||
*/ | ||
virtual void onHostAttempted(HostSharedPtr attempted_host) PURE; | ||
}; | ||
|
||
typedef std::shared_ptr<RetryHostPredicate> RetryHostPredicateSharedPtr; | ||
|
||
/** | ||
* Callbacks given to a RetryPriorityFactory that allows adding retry filters. | ||
*/ | ||
class RetryPriorityFactoryCallbacks { | ||
public: | ||
virtual ~RetryPriorityFactoryCallbacks() {} | ||
|
||
/** | ||
* Called by the factory to add a RetryPriority. | ||
*/ | ||
virtual void addRetryPriority(RetryPrioritySharedPtr filter) PURE; | ||
}; | ||
|
||
/** | ||
* Callbacks given to a RetryHostPredicateFactory that allows adding retry filters. | ||
*/ | ||
class RetryHostPredicateFactoryCallbacks { | ||
public: | ||
virtual ~RetryHostPredicateFactoryCallbacks() {} | ||
|
||
/** | ||
* Called by the factory to add a RetryHostPredicate. | ||
*/ | ||
virtual void addHostPredicate(RetryHostPredicateSharedPtr filter) PURE; | ||
}; | ||
|
||
/** | ||
* Factory for RetryPriority. | ||
*/ | ||
class RetryPriorityFactory { | ||
public: | ||
virtual ~RetryPriorityFactory() {} | ||
|
||
virtual void createRetryPriority(RetryPriorityFactoryCallbacks& callbacks) PURE; | ||
}; | ||
|
||
/** | ||
* Factory for RetryHostPredicate. | ||
*/ | ||
class RetryHostPredicateFactory { | ||
public: | ||
virtual ~RetryHostPredicateFactory() {} | ||
|
||
virtual void createHostPredicate(RetryHostPredicateFactoryCallbacks& callbacks) PURE; | ||
}; | ||
|
||
} // namespace Upstream | ||
} // namespace Envoy |
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