-
Notifications
You must be signed in to change notification settings - Fork 5.5k
dns_cache: tracking ttl but not yet using it #17951
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
Changes from 3 commits
fdf2fc5
e8e3020
e2b3815
b150b55
3ded0b7
70553bc
02e9e53
054f2ef
24c13f3
b8cd3b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,9 @@ class DnsCacheImpl : public DnsCache, Logger::Loggable<Logger::Id::forward_proxy | |
| const std::string& resolvedHost() const override { return resolved_host_; } | ||
| bool isIpAddress() const override { return is_ip_address_; } | ||
| void touch() final { last_used_time_ = time_source_.monotonicTime().time_since_epoch(); } | ||
| void updateStale(MonotonicTime resolution_time, const std::chrono::seconds ttl) { | ||
|
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: avoid const value params |
||
| stale_at_time_ = resolution_time + ttl; | ||
| } | ||
|
|
||
| void setAddress(Network::Address::InstanceConstSharedPtr address) { | ||
| absl::WriterMutexLock lock{&resolve_lock_}; | ||
|
|
@@ -141,6 +144,7 @@ class DnsCacheImpl : public DnsCache, Logger::Loggable<Logger::Id::forward_proxy | |
| // Using std::chrono::steady_clock::duration is required for compilation within an atomic vs. | ||
| // using MonotonicTime. | ||
| std::atomic<std::chrono::steady_clock::duration> last_used_time_; | ||
| std::atomic<MonotonicTime> stale_at_time_; | ||
| bool first_resolve_complete_ ABSL_GUARDED_BY(resolve_lock_){false}; | ||
| }; | ||
|
|
||
|
|
@@ -177,7 +181,8 @@ class DnsCacheImpl : public DnsCache, Logger::Loggable<Logger::Id::forward_proxy | |
| void startResolve(const std::string& host, PrimaryHostInfo& host_info) | ||
| ABSL_LOCKS_EXCLUDED(primary_hosts_lock_); | ||
| void finishResolve(const std::string& host, Network::DnsResolver::ResolutionStatus status, | ||
| std::list<Network::DnsResponse>&& response, bool from_cache = false); | ||
| std::list<Network::DnsResponse>&& response, | ||
| absl::optional<MonotonicTime> resolution_time = {}); | ||
| void runAddUpdateCallbacks(const std::string& host, const DnsHostInfoSharedPtr& host_info); | ||
| void runRemoveCallbacks(const std::string& host); | ||
| void notifyThreads(const std::string& host, const DnsHostInfoImplSharedPtr& resolved_info); | ||
|
|
@@ -186,10 +191,12 @@ class DnsCacheImpl : public DnsCache, Logger::Loggable<Logger::Id::forward_proxy | |
| PrimaryHostInfo& getPrimaryHost(const std::string& host); | ||
|
|
||
| void addCacheEntry(const std::string& host, | ||
| const Network::Address::InstanceConstSharedPtr& address); | ||
| const Network::Address::InstanceConstSharedPtr& address, | ||
| const std::chrono::seconds& ttl); | ||
|
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. I think normally we'd pass this by value since it's just a wrapper around an integer |
||
| void removeCacheEntry(const std::string& host); | ||
| void loadCacheEntries( | ||
| const envoy::extensions::common::dynamic_forward_proxy::v3::DnsCacheConfig& config); | ||
| PrimaryHostInfo* createHost(const std::string& host, uint16_t default_port); | ||
|
|
||
| Event::Dispatcher& main_thread_dispatcher_; | ||
| const Network::DnsLookupFamily dns_lookup_family_; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,7 +122,8 @@ name: envoy.clusters.dynamic_forward_proxy | |
| if (write_cache_file_) { | ||
| std::string host = | ||
| fmt::format("localhost:{}", fake_upstreams_[0]->localAddress()->ip()->port()); | ||
| std::string value = fake_upstreams_[0]->localAddress()->asString(); | ||
| std::string value = | ||
| absl::StrCat(fake_upstreams_[0]->localAddress()->asString(), "|1000000|0"); | ||
| TestEnvironment::writeStringToFileForTest( | ||
| "dns_cache.txt", absl::StrCat(host.length(), "\n", host, value.length(), "\n", value)); | ||
| } | ||
|
|
@@ -359,7 +360,6 @@ TEST_P(ProxyFilterIntegrationTest, UseCacheFile) { | |
| sendRequestAndWaitForResponse(request_headers, 1024, default_response_headers_, 1024); | ||
| checkSimpleRequestSuccess(1024, 1024, response.get()); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.cache_load")->value()); | ||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.dns_query_attempt")->value()); | ||
|
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. Would it be valid to check that this is 0 since the cached entry won't be re-queried?
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. I think it might race becasue it reregisters for refresh and I'm not sure how long it'll take |
||
| EXPECT_EQ(1, test_server_->counter("dns_cache.foo.host_added")->value()); | ||
| } | ||
| #endif | ||
|
|
||
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 might be misreading this code but it seems like up on line 452, we write 3 things into the cache value. Down here, we spilt on | and ensure that we have 2 parts. This all makes sense. But I only see code looking at parts[0] (line 478) and parts[1] (line 483) but I don't see a reference to parts[2]. Is this expected?
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.
yeah I wasn't using part two yet. I was going to do in the PR where we start using stale, but I've worked it into this one with the time updates.
I'll say I'm not 100% on the conversion back and forth but it's hard to test until we have stale expirey which is coming in the next PR!