-
Notifications
You must be signed in to change notification settings - Fork 5.4k
dfp: Insert correct preresolved hostname key in DNS cache #30784
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 3 commits
Commits
Show all changes
5 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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,8 +18,11 @@ | |||||
| #include "test/mocks/thread_local/mocks.h" | ||||||
| #include "test/test_common/registry.h" | ||||||
| #include "test/test_common/simulated_time_system.h" | ||||||
| #include "test/test_common/test_runtime.h" | ||||||
| #include "test/test_common/utility.h" | ||||||
|
|
||||||
| #include "absl/strings/str_cat.h" | ||||||
|
|
||||||
| using testing::AtLeast; | ||||||
| using testing::DoAll; | ||||||
| using testing::InSequence; | ||||||
|
|
@@ -37,15 +40,17 @@ static const absl::optional<std::chrono::seconds> kNoTtl = absl::nullopt; | |||||
| class DnsCacheImplTest : public testing::Test, public Event::TestUsingSimulatedTime { | ||||||
| public: | ||||||
| DnsCacheImplTest() : registered_dns_factory_(dns_resolver_factory_) {} | ||||||
| void initialize(std::vector<std::string> preresolve_hostnames = {}, uint32_t max_hosts = 1024) { | ||||||
| void initialize( | ||||||
| std::vector<std::pair<std::string /*host*/, uint32_t /*port*/>> preresolve_hostnames = {}, | ||||||
| uint32_t max_hosts = 1024) { | ||||||
| config_.set_name("foo"); | ||||||
| config_.set_dns_lookup_family(envoy::config::cluster::v3::Cluster::V4_ONLY); | ||||||
| config_.mutable_max_hosts()->set_value(max_hosts); | ||||||
| if (!preresolve_hostnames.empty()) { | ||||||
| for (const auto& hostname : preresolve_hostnames) { | ||||||
| for (const auto& host_pair : preresolve_hostnames) { | ||||||
|
Member
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:
Suggested change
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. Thanks for the recommendation, done! |
||||||
| envoy::config::core::v3::SocketAddress* address = config_.add_preresolve_hostnames(); | ||||||
| address->set_address(hostname); | ||||||
| address->set_port_value(443); | ||||||
| address->set_address(host_pair.first); | ||||||
| address->set_port_value(host_pair.second); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -127,36 +132,60 @@ void verifyCaresDnsConfigAndUnpack( | |||||
| typed_dns_resolver_config.typed_config().UnpackTo(&cares); | ||||||
| } | ||||||
|
|
||||||
| TEST_F(DnsCacheImplTest, PreresolveSuccess) { | ||||||
| class DnsCacheImplPreresolveTest : public DnsCacheImplTest, | ||||||
| public testing::WithParamInterface<bool> { | ||||||
| public: | ||||||
| bool normalizeDfpHost() { return GetParam(); } | ||||||
| }; | ||||||
|
|
||||||
| INSTANTIATE_TEST_SUITE_P(DnsCachePreresolveNormalizedDfpHost, DnsCacheImplPreresolveTest, | ||||||
| testing::Bool()); | ||||||
|
|
||||||
| TEST_P(DnsCacheImplPreresolveTest, PreresolveSuccess) { | ||||||
| TestScopedRuntime scoped_runtime; | ||||||
| scoped_runtime.mergeValues({{"envoy.reloadable_features.normalize_host_for_preresolve_dfp_dns", | ||||||
| absl::StrCat(normalizeDfpHost())}}); | ||||||
|
|
||||||
| Network::DnsResolver::ResolveCb resolve_cb; | ||||||
| std::string hostname = "bar.baz.com:443"; | ||||||
| EXPECT_CALL(*resolver_, resolve("bar.baz.com", _, _)) | ||||||
| .WillOnce(DoAll(SaveArg<2>(&resolve_cb), Return(&resolver_->active_query_))); | ||||||
| EXPECT_CALL(update_callbacks_, | ||||||
| onDnsHostAddOrUpdate("bar.baz.com:443", | ||||||
| DnsHostInfoEquals("10.0.0.1:443", "bar.baz.com", false))); | ||||||
| std::string host = "bar.baz.com"; | ||||||
| uint32_t port = 443; | ||||||
| std::string authority = absl::StrCat(host, ":", port); | ||||||
| EXPECT_CALL(*resolver_, resolve(host, _, _)) | ||||||
| .WillRepeatedly(DoAll(SaveArg<2>(&resolve_cb), Return(&resolver_->active_query_))); | ||||||
| EXPECT_CALL( | ||||||
| update_callbacks_, | ||||||
| onDnsHostAddOrUpdate(authority, DnsHostInfoEquals("10.0.0.1:443", "bar.baz.com", false))); | ||||||
| EXPECT_CALL(update_callbacks_, | ||||||
| onDnsResolutionComplete("bar.baz.com:443", | ||||||
| onDnsResolutionComplete(authority, | ||||||
| DnsHostInfoEquals("10.0.0.1:443", "bar.baz.com", false), | ||||||
| Network::DnsResolver::ResolutionStatus::Success)); | ||||||
|
|
||||||
| initialize({"bar.baz.com:443"} /* preresolve_hostnames */); | ||||||
| initialize({{normalizeDfpHost() ? host : authority, port}} /* preresolve_hostnames */); | ||||||
|
|
||||||
| resolve_cb(Network::DnsResolver::ResolutionStatus::Success, | ||||||
| TestUtility::makeDnsResponse({"10.0.0.1"})); | ||||||
| checkStats(1 /* attempt */, 1 /* success */, 0 /* failure */, 1 /* address changed */, | ||||||
| 1 /* added */, 0 /* removed */, 1 /* num hosts */); | ||||||
|
|
||||||
| MockLoadDnsCacheEntryCallbacks callbacks; | ||||||
| auto result = dns_cache_->loadDnsCacheEntry("bar.baz.com", 443, false, callbacks); | ||||||
| if (normalizeDfpHost()) { | ||||||
| // Retrieve with the hostname and port in the "host". | ||||||
| auto result = dns_cache_->loadDnsCacheEntry(authority, port, false, callbacks); | ||||||
| EXPECT_EQ(DnsCache::LoadDnsCacheEntryStatus::InCache, result.status_); | ||||||
| EXPECT_EQ(result.handle_, nullptr); | ||||||
| EXPECT_NE(absl::nullopt, result.host_info_); | ||||||
| } | ||||||
| // Retrieve with the hostname only in the "host". | ||||||
| auto result = dns_cache_->loadDnsCacheEntry(host, port, false, callbacks); | ||||||
| EXPECT_EQ(DnsCache::LoadDnsCacheEntryStatus::InCache, result.status_); | ||||||
| EXPECT_EQ(result.handle_, nullptr); | ||||||
| EXPECT_NE(absl::nullopt, result.host_info_); | ||||||
| } | ||||||
|
|
||||||
| TEST_F(DnsCacheImplTest, PreresolveFailure) { | ||||||
| TEST_P(DnsCacheImplPreresolveTest, PreresolveFailure) { | ||||||
| EXPECT_THROW_WITH_MESSAGE( | ||||||
| initialize({"bar.baz.com"} /* preresolve_hostnames */, 0 /* max_hosts */), EnvoyException, | ||||||
| initialize({{"bar.baz.com", 443}} /* preresolve_hostnames */, 0 /* max_hosts */), | ||||||
| EnvoyException, | ||||||
| "DNS Cache [foo] configured with preresolve_hostnames=1 larger than max_hosts=0"); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
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.
(I'm trying to comment on line 56)
Wow, is this the correct type for hostname?
repeated config.core.v3.SocketAddress preresolve_hostnames = 10;
Hostname is a bizarre term for this as it seems to be a protocol (tcp/udp), an IP address, a port, and a resolver name. Am I reading that correctly? bizarre
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 was also surprised SocketAddress was used for preresolved hostnames config, and doesn't seem to be the right structure to represent a DNS cache entry. Changing it is a good idea but probably outside the scope of the PR. I do share your concern though..