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

router: implement RetryHostPredicate #4385

Merged
merged 10 commits into from
Sep 14, 2018
Merged

Conversation

snowp
Copy link
Contributor

@snowp snowp commented Sep 10, 2018

Description: Wires up route configuration to allow specifying what hosts should be
reattempted during retry host selection.
Risk Level: Medium, some changes made to the router. Otherwise new optional feature
Testing: unit and integration test
Docs Changes: n/a
Release Notes: n/a

Part of #3958

Wires up route configuration to allow specifying what hosts should be
reattempted during retry host selection.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
@snowp
Copy link
Contributor Author

snowp commented Sep 12, 2018

@zuercher If you have time I'd love some feedback on this one. Part of the implementation of the previous retry PR you looked over.

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks pretty good.

test/integration/http_integration.h Outdated Show resolved Hide resolved
#include "envoy/registry/registry.h"

namespace Envoy {
static Registry::RegisterFactory<TestHostPredicateFactory, Upstream::RetryHostPredicateFactory>
Copy link
Member

Choose a reason for hiding this comment

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

You can use Registery::InjectFactory to avoid having to insure this factory is linked into your tests and also control exactly when the predicate is available.

source/common/router/config_impl.cc Outdated Show resolved Hide resolved
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
@snowp
Copy link
Contributor Author

snowp commented Sep 13, 2018

Build failure seems to be due to CircleCi degraded service, I'll re-run CI in a bit once they resolve their issues

Signed-off-by: Snow Pettersen <snowp@squareup.com>
zuercher
zuercher previously approved these changes Sep 13, 2018
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks good. @htuch do you want to take a pass as well?

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Generally looks good, a few minor nits.

auto factory = Registry::FactoryRegistry<Upstream::RetryHostPredicateFactory>::getFactory(
host_predicate.name());

ASSERT(factory);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: no need to ASSERT if doing an immediate dereference next line.

@@ -48,6 +48,15 @@ RetryPolicyImpl::RetryPolicyImpl(const envoy::api::v2::route::RouteAction& confi
num_retries_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT(config.retry_policy(), num_retries, 1);
retry_on_ = RetryStateImpl::parseRetryOn(config.retry_policy().retry_on());
retry_on_ |= RetryStateImpl::parseRetryGrpcOn(config.retry_policy().retry_on());

for (const auto& host_predicate : config.retry_policy().retry_host_predicate()) {
// TODO(snowp): support passing the config Struct during initialization.
Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to do in this PR, should only be a few lines?

void waitForNextUpstreamRequest(uint64_t upstream_index = 0);
// In cases where the upstream that will receive the request is not deterministic, a second
// upstream index may be provided, in which case both upstreams will be checked for requests.
uint64_t waitForNextUpstreamRequest(uint64_t upstream_index = 0,
Copy link
Member

Choose a reason for hiding this comment

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

If feels a bit clunky making this either 1 or 2; why not just provide a set of hosts?

@@ -308,5 +308,11 @@ class MockClusterInfoFactory : public ClusterInfoFactory, Logger::Loggable<Logge
Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random));
};

class MockRetryHostPredicate : public RetryHostPredicate {
public:
Copy link
Member

Choose a reason for hiding this comment

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

Please add explicit constructor/destructor and put definition in .cc for mock build performance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Surprised this makes a difference. Does the implicit ctor/dtor definition in header add significant overhead?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, thanks for the link. Makes me think we should go over the existing mocks and move the ctors/dtors into the .cc file, I see it's missing from some of them

Copy link
Member

Choose a reason for hiding this comment

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

Sure, any cleanups PRs most welcome.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
absl::optional<uint64_t> second_upstream_index) {
uint64_t upstream_with_request = upstream_index;
uint64_t HttpIntegrationTest::waitForNextUpstreamRequest(
const std::unordered_set<uint64_t>& upstream_indices) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you want this to be a vector or you're going to have a source of non-determinism leading to test flakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's a good point, I'll change

Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks!

@htuch htuch merged commit 62eb123 into envoyproxy:master Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants