-
Notifications
You must be signed in to change notification settings - Fork 5.5k
dfp: adding connection timing test #19766
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -15,12 +15,15 @@ namespace { | |
| class ProxyFilterIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>, | ||
| public HttpIntegrationTest { | ||
| public: | ||
| ProxyFilterIntegrationTest() : HttpIntegrationTest(Http::CodecType::HTTP1, GetParam()) {} | ||
| ProxyFilterIntegrationTest() : HttpIntegrationTest(Http::CodecType::HTTP1, GetParam()) { | ||
| upstream_tls_ = true; | ||
| } | ||
|
|
||
| void initializeWithArgs(uint64_t max_hosts = 1024, uint32_t max_pending_requests = 1024, | ||
| const std::string& override_auto_sni_header = "") { | ||
| setUpstreamProtocol(Http::CodecType::HTTP1); | ||
| const std::string filename = TestEnvironment::temporaryPath("dns_cache.txt"); | ||
| ::unlink(filename.c_str()); | ||
|
|
||
| const std::string filter = fmt::format(R"EOF( | ||
| name: dynamic_forward_proxy | ||
|
|
@@ -143,6 +146,9 @@ name: envoy.clusters.dynamic_forward_proxy | |
| } | ||
| } | ||
|
|
||
| void testConnectionTiming(IntegrationStreamDecoderPtr& response, bool cached_dns, | ||
|
Contributor
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 before?
Contributor
Author
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. done |
||
| int64_t original_usec); | ||
|
|
||
| bool upstream_tls_{}; | ||
| std::string upstream_cert_name_{"upstreamlocalhost"}; | ||
| CdsHelper cds_helper_; | ||
|
|
@@ -151,6 +157,42 @@ name: envoy.clusters.dynamic_forward_proxy | |
| bool use_cache_file_{}; | ||
| }; | ||
|
|
||
| int64_t getHeaderValue(const Http::ResponseHeaderMap& headers, absl::string_view name) { | ||
| EXPECT_FALSE(headers.get(Http::LowerCaseString(name)).empty()); | ||
| int64_t val; | ||
| if (!headers.get(Http::LowerCaseString(name)).empty() && | ||
| absl::SimpleAtoi(headers.get(Http::LowerCaseString(name))[0]->value().getStringView(), | ||
| &val)) { | ||
| return val; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| void ProxyFilterIntegrationTest::testConnectionTiming(IntegrationStreamDecoderPtr& response, | ||
| bool cached_dns, int64_t original_usec) { | ||
| int64_t dns_start = getHeaderValue(response->headers(), "dns_start"); | ||
| int64_t dns_end = getHeaderValue(response->headers(), "dns_end"); | ||
| int64_t connect_start = getHeaderValue(response->headers(), "upstream_connect_start"); | ||
| int64_t connect_end = getHeaderValue(response->headers(), "upstream_connect_complete"); | ||
| int64_t handshake_end = getHeaderValue(response->headers(), "upstream_handshake_complete"); | ||
| int64_t request_send_end = getHeaderValue(response->headers(), "request_send_end"); | ||
| int64_t response_begin = getHeaderValue(response->headers(), "response_begin"); | ||
| Event::DispatcherImpl dispatcher("foo", *api_, timeSystem()); | ||
|
|
||
| ASSERT_LT(original_usec, dns_start); | ||
| ASSERT_LE(dns_start, dns_end); | ||
| if (cached_dns) { | ||
| ASSERT_GE(dns_end, connect_start); | ||
| } else { | ||
| ASSERT_LE(dns_end, connect_start); | ||
| } | ||
| ASSERT_LE(connect_start, connect_end); | ||
| ASSERT_LE(connect_end, handshake_end); | ||
| ASSERT_LE(handshake_end, request_send_end); | ||
| ASSERT_LE(request_send_end, response_begin); | ||
| ASSERT_LT(handshake_end, timeSystem().monotonicTime().time_since_epoch().count()); | ||
| } | ||
|
|
||
| class ProxyFilterWithSimtimeIntegrationTest : public Event::TestUsingSimulatedTime, | ||
| public ProxyFilterIntegrationTest {}; | ||
|
|
||
|
|
@@ -164,6 +206,13 @@ INSTANTIATE_TEST_SUITE_P(IpVersions, ProxyFilterIntegrationTest, | |
| // A basic test where we pause a request to lookup localhost, and then do another request which | ||
| // should hit the TLS cache. | ||
| TEST_P(ProxyFilterIntegrationTest, RequestWithBody) { | ||
| int64_t original_usec = dispatcher_->timeSource().monotonicTime().time_since_epoch().count(); | ||
|
|
||
| config_helper_.prependFilter(fmt::format(R"EOF( | ||
| name: stream-info-to-headers-filter | ||
| typed_config: | ||
| "@type": type.googleapis.com/google.protobuf.Empty)EOF")); | ||
|
|
||
| initializeWithArgs(); | ||
| codec_client_ = makeHttpConnection(lookupPort("http")); | ||
| const Http::TestRequestHeaderMapImpl request_headers{ | ||
|
|
@@ -176,20 +225,24 @@ TEST_P(ProxyFilterIntegrationTest, RequestWithBody) { | |
| auto response = | ||
| sendRequestAndWaitForResponse(request_headers, 1024, default_response_headers_, 1024); | ||
| checkSimpleRequestSuccess(1024, 1024, response.get()); | ||
| testConnectionTiming(response, false, original_usec); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.dns_query_attempt")->value()); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.host_added")->value()); | ||
| // Make sure dns timings are tracked for cache-misses. | ||
| ASSERT_FALSE(response->headers().get(Http::LowerCaseString("dns_start")).empty()); | ||
| ASSERT_FALSE(response->headers().get(Http::LowerCaseString("dns_end")).empty()); | ||
|
|
||
| // Now send another request. This should hit the DNS cache. | ||
| response = sendRequestAndWaitForResponse(request_headers, 512, default_response_headers_, 512); | ||
| checkSimpleRequestSuccess(512, 512, response.get()); | ||
| testConnectionTiming(response, true, original_usec); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.dns_query_attempt")->value()); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.host_added")->value()); | ||
| // Make sure dns timings are tracked for cache-hits. | ||
| ASSERT_FALSE(response->headers().get(Http::LowerCaseString("dns_start")).empty()); | ||
| ASSERT_FALSE(response->headers().get(Http::LowerCaseString("dns_end")).empty()); | ||
|
|
||
| const Extensions::TransportSockets::Tls::SslHandshakerImpl* ssl_socket = | ||
| dynamic_cast<const Extensions::TransportSockets::Tls::SslHandshakerImpl*>( | ||
| fake_upstream_connection_->connection().ssl().get()); | ||
| EXPECT_STREQ("localhost", SSL_get_servername(ssl_socket->ssl(), TLSEXT_NAMETYPE_host_name)); | ||
| } | ||
|
|
||
| // Currently if the first DNS resolution fails, the filter will continue with | ||
|
|
@@ -297,8 +350,8 @@ TEST_P(ProxyFilterIntegrationTest, DNSCacheHostOverflow) { | |
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.host_overflow")->value()); | ||
| } | ||
|
|
||
| // Verify that upstream TLS works with auto verification for SAN as well as auto setting SNI. | ||
| TEST_P(ProxyFilterIntegrationTest, UpstreamTls) { | ||
| // Verify that the filter works without TLS. | ||
| TEST_P(ProxyFilterIntegrationTest, UpstreamCleartext) { | ||
| upstream_tls_ = true; | ||
| initializeWithArgs(); | ||
| codec_client_ = makeHttpConnection(lookupPort("http")); | ||
|
|
@@ -312,11 +365,6 @@ TEST_P(ProxyFilterIntegrationTest, UpstreamTls) { | |
| auto response = codec_client_->makeHeaderOnlyRequest(request_headers); | ||
| waitForNextUpstreamRequest(); | ||
|
|
||
| const Extensions::TransportSockets::Tls::SslHandshakerImpl* ssl_socket = | ||
| dynamic_cast<const Extensions::TransportSockets::Tls::SslHandshakerImpl*>( | ||
| fake_upstream_connection_->connection().ssl().get()); | ||
| EXPECT_STREQ("localhost", SSL_get_servername(ssl_socket->ssl(), TLSEXT_NAMETYPE_host_name)); | ||
|
|
||
| upstream_request_->encodeHeaders(default_response_headers_, true); | ||
| ASSERT_TRUE(response->waitForEndStream()); | ||
| checkSimpleRequestSuccess(0, 0, response.get()); | ||
|
|
@@ -433,6 +481,7 @@ TEST_P(ProxyFilterIntegrationTest, UseCacheFile) { | |
| } | ||
|
|
||
| TEST_P(ProxyFilterIntegrationTest, UseCacheFileAndTestHappyEyeballs) { | ||
| upstream_tls_ = false; // upstream creation doesn't handle autonomous_upstream_ | ||
| autonomous_upstream_ = true; | ||
|
|
||
| config_helper_.addRuntimeOverride("envoy.reloadable_features.allow_multiple_dns_addresses", | ||
|
|
@@ -461,6 +510,8 @@ TEST_P(ProxyFilterIntegrationTest, UseCacheFileAndTestHappyEyeballs) { | |
| } | ||
|
|
||
| TEST_P(ProxyFilterIntegrationTest, MultipleRequestsLowStreamLimit) { | ||
| upstream_tls_ = false; // config below uses bootstrap, tls config is in cluster_ | ||
|
|
||
| setDownstreamProtocol(Http::CodecType::HTTP2); | ||
| setUpstreamProtocol(Http::CodecType::HTTP2); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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.
Out of curiosity, with your new O_TRUNC writes, is this still required?
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 so - not all the tests write the file and the file shouldnt exist in the tests which don't use one