-
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
Network 475 check upstream for canary status #49
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
62c1f60
Add checking upstream host for canary to AsyncClient
bb4d3a9
Change the way upstream_canary is checked by chargeResponseData
5b83157
Fixed router and added router tests
179a47f
Fix codes test
320b42f
TEMP let roman check
b0e61de
Clean up Async Client test
4a5509d
Merge branch 'master' of github.com:lyft/envoy into NETWORK-475-check…
740f01c
Check canary status onResetStream and onRequestTimeout
b0768e1
Clean up async client test
a0393cc
Update per comments
82d41c8
Fix nits
e412ad7
Consolidate isUpstreamCanary logic
f3f886b
Fix format
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
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 |
---|---|---|
|
@@ -13,13 +13,14 @@ using testing::ByRef; | |
using testing::Invoke; | ||
using testing::NiceMock; | ||
using testing::Ref; | ||
using testing::Return; | ||
using testing::ReturnRef; | ||
|
||
namespace Http { | ||
|
||
class AsyncClientImplTest : public testing::Test, public AsyncClientConnPoolFactory { | ||
class AsyncClientImplTestBase : public testing::Test, public AsyncClientConnPoolFactory { | ||
public: | ||
AsyncClientImplTest() { | ||
AsyncClientImplTestBase() { | ||
HttpTestUtility::addDefaultHeaders(message_->headers()); | ||
ON_CALL(*conn_pool_.host_, zone()).WillByDefault(ReturnRef(upstream_zone_)); | ||
} | ||
|
@@ -35,13 +36,22 @@ class AsyncClientImplTest : public testing::Test, public AsyncClientConnPoolFact | |
ConnectionPool::MockInstance conn_pool_; | ||
NiceMock<MockStreamEncoder> stream_encoder_; | ||
StreamDecoder* response_decoder_{}; | ||
NiceMock<Stats::MockStore> stats_store_; | ||
NiceMock<Event::MockTimer>* timer_; | ||
NiceMock<Event::MockDispatcher> dispatcher_; | ||
NiceMock<Upstream::MockCluster> cluster_; | ||
}; | ||
|
||
TEST_F(AsyncClientImplTest, Basic) { | ||
class AsyncClientImplTestMockStats : public AsyncClientImplTestBase { | ||
public: | ||
NiceMock<Stats::MockStore> stats_store_; | ||
}; | ||
|
||
class AsyncClientImplTestIsolatedStats : public AsyncClientImplTestBase { | ||
public: | ||
Stats::IsolatedStoreImpl stats_store_; | ||
}; | ||
|
||
TEST_F(AsyncClientImplTestMockStats, Basic) { | ||
message_->body(Buffer::InstancePtr{new Buffer::OwnedImpl("test body")}); | ||
Buffer::Instance& data = *message_->body(); | ||
|
||
|
@@ -77,7 +87,7 @@ TEST_F(AsyncClientImplTest, Basic) { | |
response_decoder_->decodeData(data, true); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, MultipleRequests) { | ||
TEST_F(AsyncClientImplTestMockStats, MultipleRequests) { | ||
// Send request 1 | ||
message_->body(Buffer::InstancePtr{new Buffer::OwnedImpl("test body")}); | ||
Buffer::Instance& data = *message_->body(); | ||
|
@@ -124,7 +134,7 @@ TEST_F(AsyncClientImplTest, MultipleRequests) { | |
response_decoder_->decodeData(data, true); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, Trailers) { | ||
TEST_F(AsyncClientImplTestMockStats, Trailers) { | ||
message_->body(Buffer::InstancePtr{new Buffer::OwnedImpl("test body")}); | ||
Buffer::Instance& data = *message_->body(); | ||
|
||
|
@@ -148,7 +158,7 @@ TEST_F(AsyncClientImplTest, Trailers) { | |
response_decoder_->decodeTrailers(HeaderMapPtr{new HeaderMapImpl{{"some", "trailer"}}}); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, FailRequest) { | ||
TEST_F(AsyncClientImplTestMockStats, FailRequest) { | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_5xx")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_503")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.zone.from_az.to_az.upstream_rq_503")); | ||
|
@@ -171,7 +181,7 @@ TEST_F(AsyncClientImplTest, FailRequest) { | |
stream_encoder_.getStream().resetStream(StreamResetReason::RemoteReset); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, CancelRequest) { | ||
TEST_F(AsyncClientImplTestMockStats, CancelRequest) { | ||
EXPECT_CALL(conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](StreamDecoder&, ConnectionPool::Callbacks& callbacks) | ||
-> ConnectionPool::Cancellable* { | ||
|
@@ -188,7 +198,7 @@ TEST_F(AsyncClientImplTest, CancelRequest) { | |
request->cancel(); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, PoolFailure) { | ||
TEST_F(AsyncClientImplTestMockStats, PoolFailure) { | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_5xx")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_503")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.zone.from_az.to_az.upstream_rq_5xx")); | ||
|
@@ -210,7 +220,7 @@ TEST_F(AsyncClientImplTest, PoolFailure) { | |
client.send(std::move(message_), callbacks_, Optional<std::chrono::milliseconds>())); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, RequestTimeout) { | ||
TEST_F(AsyncClientImplTestMockStats, RequestTimeout) { | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_5xx")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.upstream_rq_504")); | ||
EXPECT_CALL(stats_store_, counter("cluster.fake_cluster.zone.from_az.to_az.upstream_rq_5xx")); | ||
|
@@ -236,7 +246,7 @@ TEST_F(AsyncClientImplTest, RequestTimeout) { | |
EXPECT_EQ(1UL, cluster_.stats_store_.counter("cluster.fake_cluster.upstream_rq_timeout").value()); | ||
} | ||
|
||
TEST_F(AsyncClientImplTest, DisableTimer) { | ||
TEST_F(AsyncClientImplTestMockStats, DisableTimer) { | ||
EXPECT_CALL(conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](StreamDecoder&, ConnectionPool::Callbacks& callbacks) | ||
-> ConnectionPool::Cancellable* { | ||
|
@@ -255,4 +265,44 @@ TEST_F(AsyncClientImplTest, DisableTimer) { | |
request->cancel(); | ||
} | ||
|
||
TEST_F(AsyncClientImplTestIsolatedStats, CanaryStatusCounterTrue) { | ||
message_->body(Buffer::InstancePtr{new Buffer::OwnedImpl("test body")}); | ||
Buffer::Instance& data = *message_->body(); | ||
|
||
EXPECT_CALL(conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](StreamDecoder& decoder, ConnectionPool::Callbacks& callbacks) | ||
-> ConnectionPool::Cancellable* { | ||
callbacks.onPoolReady(stream_encoder_, conn_pool_.host_); | ||
response_decoder_ = &decoder; | ||
return nullptr; | ||
})); | ||
AsyncClientImpl client(cluster_, *this, stats_store_, dispatcher_, "from_az"); | ||
client.send(std::move(message_), callbacks_, Optional<std::chrono::milliseconds>()); | ||
HeaderMapPtr response_headers( | ||
new HeaderMapImpl{{":status", "200"}, {"x-envoy-upstream-canary", "false"}}); | ||
ON_CALL(*conn_pool_.host_, canary()).WillByDefault(Return(true)); | ||
response_decoder_->decodeHeaders(std::move(response_headers), false); | ||
EXPECT_EQ(1U, stats_store_.counter("cluster.fake_cluster.canary.upstream_rq_200").value()); | ||
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. Use expect call here instead of EXPECT_EQ as stats_store_ is MockInstance and not the Isolated one |
||
response_decoder_->decodeData(data, true); | ||
} | ||
|
||
TEST_F(AsyncClientImplTestIsolatedStats, CanaryStatusCounterFalse) { | ||
message_->body(Buffer::InstancePtr{new Buffer::OwnedImpl("test body")}); | ||
Buffer::Instance& data = *message_->body(); | ||
|
||
EXPECT_CALL(conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](StreamDecoder& decoder, ConnectionPool::Callbacks& callbacks) | ||
-> ConnectionPool::Cancellable* { | ||
callbacks.onPoolReady(stream_encoder_, conn_pool_.host_); | ||
response_decoder_ = &decoder; | ||
return nullptr; | ||
})); | ||
AsyncClientImpl client(cluster_, *this, stats_store_, dispatcher_, "from_az"); | ||
client.send(std::move(message_), callbacks_, Optional<std::chrono::milliseconds>()); | ||
HeaderMapPtr response_headers( | ||
new HeaderMapImpl{{":status", "200"}, {"x-envoy-upstream-canary", "false"}}); | ||
response_decoder_->decodeHeaders(std::move(response_headers), false); | ||
EXPECT_EQ(0U, stats_store_.counter("cluster.fake_cluster.canary.upstream_rq_200").value()); | ||
response_decoder_->decodeData(data, true); | ||
} | ||
} // Http |
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 |
---|---|---|
|
@@ -710,4 +710,65 @@ TEST(RouterFilterUtilityTest, shouldShadow) { | |
} | ||
} | ||
|
||
TEST_F(RouterTest, CanaryStatusTrue) { | ||
NiceMock<MockRouteEntry> route_entry; | ||
EXPECT_CALL(callbacks_.route_table_, routeForRequest(_)).WillOnce(Return(&route_entry)); | ||
EXPECT_CALL(route_entry, timeout()).WillOnce(Return(std::chrono::milliseconds(0))); | ||
EXPECT_CALL(callbacks_.dispatcher_, createTimer_(_)).Times(0); | ||
|
||
NiceMock<Http::MockStreamEncoder> encoder; | ||
Http::StreamDecoder* response_decoder = nullptr; | ||
EXPECT_CALL(cm_.conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](Http::StreamDecoder& decoder, Http::ConnectionPool::Callbacks& callbacks) | ||
-> Http::ConnectionPool::Cancellable* { | ||
response_decoder = &decoder; | ||
callbacks.onPoolReady(encoder, cm_.conn_pool_.host_); | ||
return nullptr; | ||
})); | ||
|
||
Http::HeaderMapImpl headers{{"x-envoy-upstream-alt-stat-name", "alt_stat"}, | ||
{"x-envoy-internal", "true"}}; | ||
HttpTestUtility::addDefaultHeaders(headers); | ||
router_.decodeHeaders(headers, true); | ||
|
||
Http::HeaderMapPtr response_headers( | ||
new Http::HeaderMapImpl{{":status", "200"}, | ||
{"x-envoy-upstream-canary", "false"}, | ||
{"x-envoy-virtual-cluster", "hello"}}); | ||
ON_CALL(*cm_.conn_pool_.host_, canary()).WillByDefault(Return(true)); | ||
response_decoder->decodeHeaders(std::move(response_headers), true); | ||
|
||
EXPECT_EQ(1U, stats_store_.counter("cluster.fake_cluster.canary.upstream_rq_200").value()); | ||
} | ||
|
||
TEST_F(RouterTest, CanaryStatusFalse) { | ||
NiceMock<MockRouteEntry> route_entry; | ||
EXPECT_CALL(callbacks_.route_table_, routeForRequest(_)).WillOnce(Return(&route_entry)); | ||
EXPECT_CALL(route_entry, timeout()).WillOnce(Return(std::chrono::milliseconds(0))); | ||
EXPECT_CALL(callbacks_.dispatcher_, createTimer_(_)).Times(0); | ||
|
||
NiceMock<Http::MockStreamEncoder> encoder; | ||
Http::StreamDecoder* response_decoder = nullptr; | ||
EXPECT_CALL(cm_.conn_pool_, newStream(_, _)) | ||
.WillOnce(Invoke([&](Http::StreamDecoder& decoder, Http::ConnectionPool::Callbacks& callbacks) | ||
-> Http::ConnectionPool::Cancellable* { | ||
response_decoder = &decoder; | ||
callbacks.onPoolReady(encoder, cm_.conn_pool_.host_); | ||
return nullptr; | ||
})); | ||
|
||
Http::HeaderMapImpl headers{{"x-envoy-upstream-alt-stat-name", "alt_stat"}, | ||
{"x-envoy-internal", "true"}}; | ||
HttpTestUtility::addDefaultHeaders(headers); | ||
router_.decodeHeaders(headers, true); | ||
|
||
Http::HeaderMapPtr response_headers( | ||
new Http::HeaderMapImpl{{":status", "200"}, | ||
{"x-envoy-upstream-canary", "false"}, | ||
{"x-envoy-virtual-cluster", "hello"}}); | ||
response_decoder->decodeHeaders(std::move(response_headers), true); | ||
|
||
EXPECT_EQ(0U, stats_store_.counter("cluster.fake_cluster.canary.upstream_rq_200").value()); | ||
} | ||
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: newline after this line |
||
|
||
} // Router |
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.
parens
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.
fixed