Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/configuration/cluster_manager/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Cluster
"ssl_context": "{...}",
"features": "...",
"http_codec_options": "...",
"alt_stat_name": "..."
"alt_stat_name": "...",
"dns_refresh_rate_ms": "..."
}

.. _config_cluster_manager_cluster_name:
Expand Down Expand Up @@ -129,6 +130,12 @@ alt_stat_name
<config_cluster_manager_cluster_stats>` will be duplicated between the standard statistics and a
tree specified by this parameter (e.g., *cluster.<alt_stat_name>.*).

dns_refresh_rate_ms

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you point out here that otherwise (for other cluster types) this setting is just ignored.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added

*(optional, integer)* If the dns refresh rate is specified and the cluster type is either *strict_dns*,
or *logical_dns*, this value is used as the cluster's dns refresh rate. If this setting is not specified,
the value defaults to 5000. For cluster types other than *strict_dns* and *logical_dns* this setting is
ignored.

.. toctree::
:hidden:

Expand Down
4 changes: 3 additions & 1 deletion source/common/upstream/logical_dns_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ LogicalDnsCluster::LogicalDnsCluster(const Json::Object& config, Runtime::Loader
Stats::Store& stats, Ssl::ContextManager& ssl_context_manager,
Network::DnsResolver& dns_resolver, ThreadLocal::Instance& tls)
: ClusterImplBase(config, runtime, stats, ssl_context_manager), dns_resolver_(dns_resolver),
dns_refresh_rate_ms_(
std::chrono::milliseconds(config.getInteger("dns_refresh_rate_ms", 5000))),
tls_(tls), tls_slot_(tls.allocateSlot()),
resolve_timer_(dns_resolver.dispatcher().createTimer([this]() -> void { startResolve(); })) {

Expand Down Expand Up @@ -61,7 +63,7 @@ void LogicalDnsCluster::startResolve() {
initialize_callback_ = nullptr;
}

resolve_timer_->enableTimer(std::chrono::milliseconds(5000));
resolve_timer_->enableTimer(dns_refresh_rate_ms_);
});
}

Expand Down
1 change: 1 addition & 0 deletions source/common/upstream/logical_dns_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class LogicalDnsCluster : public ClusterImplBase {
void startResolve();

Network::DnsResolver& dns_resolver_;
const std::chrono::milliseconds dns_refresh_rate_ms_;
ThreadLocal::Instance& tls_;
uint32_t tls_slot_;
std::function<void()> initialize_callback_;
Expand Down
5 changes: 3 additions & 2 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(const Json::Object& config, Runtime::
Ssl::ContextManager& ssl_context_manager,
Network::DnsResolver& dns_resolver)
: BaseDynamicClusterImpl(config, runtime, stats, ssl_context_manager),
dns_resolver_(dns_resolver) {
dns_resolver_(dns_resolver), dns_refresh_rate_ms_(std::chrono::milliseconds(
config.getInteger("dns_refresh_rate_ms", 5000))) {
for (Json::Object& host : config.getObjectArray("hosts")) {
resolve_targets_.emplace_back(new ResolveTarget(*this, host.getString("url")));
}
Expand Down Expand Up @@ -326,7 +327,7 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() {
parent_.initialize_callback_ = nullptr;
}

resolve_timer_->enableTimer(std::chrono::milliseconds(5000));
resolve_timer_->enableTimer(parent_.dns_refresh_rate_ms_);
});
}

Expand Down
1 change: 1 addition & 0 deletions source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class StrictDnsClusterImpl : public BaseDynamicClusterImpl {

Network::DnsResolver& dns_resolver_;
std::list<ResolveTargetPtr> resolve_targets_;
const std::chrono::milliseconds dns_refresh_rate_ms_;
};

} // Upstream
5 changes: 3 additions & 2 deletions test/common/upstream/logical_dns_cluster_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ TEST_F(LogicalDnsClusterTest, Basic) {
"connect_timeout_ms": 250,
"type": "logical_dns",
"lb_type": "round_robin",
"hosts": [{"url": "tcp://foo.bar.com:443"}]
"hosts": [{"url": "tcp://foo.bar.com:443"}],
"dns_refresh_rate_ms": 4000
}
)EOF";

Expand All @@ -72,7 +73,7 @@ TEST_F(LogicalDnsClusterTest, Basic) {

EXPECT_CALL(membership_updated_, ready());
EXPECT_CALL(initialized_, ready());
EXPECT_CALL(*resolve_timer_, enableTimer(_));
EXPECT_CALL(*resolve_timer_, enableTimer(std::chrono::milliseconds(4000)));
dns_callback_({"127.0.0.1", "127.0.0.2"});

EXPECT_EQ(1UL, cluster_->hosts().size());
Expand Down
11 changes: 6 additions & 5 deletions test/common/upstream/upstream_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TEST(StrictDnsClusterImplTest, Basic) {
"name": "name",
"connect_timeout_ms": 250,
"type": "strict_dns",
"dns_refresh_rate_ms": 4000,
"lb_type": "round_robin",
"circuit_breakers": {
"default": {
Expand Down Expand Up @@ -97,34 +98,34 @@ TEST(StrictDnsClusterImplTest, Basic) {
-> void { membership_updated.ready(); });

resolver1.expectResolve(dns_resolver);
EXPECT_CALL(*resolver1.timer_, enableTimer(_));
EXPECT_CALL(*resolver1.timer_, enableTimer(std::chrono::milliseconds(4000)));
EXPECT_CALL(membership_updated, ready());
resolver1.dns_callback_({"127.0.0.1", "127.0.0.2"});
EXPECT_THAT(std::list<std::string>({"tcp://127.0.0.1:11001", "tcp://127.0.0.2:11001"}),
ContainerEq(hostListToURLs(cluster.hosts())));

resolver1.expectResolve(dns_resolver);
resolver1.timer_->callback_();
EXPECT_CALL(*resolver1.timer_, enableTimer(_));
EXPECT_CALL(*resolver1.timer_, enableTimer(std::chrono::milliseconds(4000)));
resolver1.dns_callback_({"127.0.0.2", "127.0.0.1"});
EXPECT_THAT(std::list<std::string>({"tcp://127.0.0.1:11001", "tcp://127.0.0.2:11001"}),
ContainerEq(hostListToURLs(cluster.hosts())));

resolver1.expectResolve(dns_resolver);
resolver1.timer_->callback_();
EXPECT_CALL(*resolver1.timer_, enableTimer(_));
EXPECT_CALL(*resolver1.timer_, enableTimer(std::chrono::milliseconds(4000)));
resolver1.dns_callback_({"127.0.0.2", "127.0.0.1"});
EXPECT_THAT(std::list<std::string>({"tcp://127.0.0.1:11001", "tcp://127.0.0.2:11001"}),
ContainerEq(hostListToURLs(cluster.hosts())));

resolver1.timer_->callback_();
EXPECT_CALL(*resolver1.timer_, enableTimer(_));
EXPECT_CALL(*resolver1.timer_, enableTimer(std::chrono::milliseconds(4000)));
EXPECT_CALL(membership_updated, ready());
resolver1.dns_callback_({"127.0.0.3"});
EXPECT_THAT(std::list<std::string>({"tcp://127.0.0.3:11001"}),
ContainerEq(hostListToURLs(cluster.hosts())));

EXPECT_CALL(*resolver2.timer_, enableTimer(_));
EXPECT_CALL(*resolver2.timer_, enableTimer(std::chrono::milliseconds(4000)));
EXPECT_CALL(membership_updated, ready());
resolver2.dns_callback_({"10.0.0.1"});
EXPECT_THAT(std::list<std::string>({"tcp://127.0.0.3:11001", "tcp://10.0.0.1:11002"}),
Expand Down