From eb57dcef9e96caa610f71fd140d2be8b4974b36e Mon Sep 17 00:00:00 2001 From: Matt Klein Date: Tue, 7 Nov 2017 16:45:39 -0800 Subject: [PATCH] mongo: add runtime feature flag for drain close behavior There are some issues in Lyft's environment related to this feature. I need to do further work on draining in general but that is going to take me several days. This is a short term fix and seems fine to have this control here in either case. Note that I will add better documentation on draining as an overall topic when I do the draining follow ups. Signed-off-by: Matt Klein --- docs/configuration/network_filters/mongo_proxy_filter.rst | 4 ++++ source/common/mongo/proxy.cc | 3 ++- source/common/mongo/proxy.h | 1 + test/common/mongo/proxy_test.cc | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/configuration/network_filters/mongo_proxy_filter.rst b/docs/configuration/network_filters/mongo_proxy_filter.rst index 3d113d53ccd68..86a58c9a0d47c 100644 --- a/docs/configuration/network_filters/mongo_proxy_filter.rst +++ b/docs/configuration/network_filters/mongo_proxy_filter.rst @@ -179,6 +179,10 @@ mongo.logging_enabled % of messages that will be logged. Defaults to 100. If less than 100, queries may be logged without replies, etc. +mongo.mongo.drain_close_enabled + % of connections that will be drain closed if the server is draining and would otherwise + attempt a drain close. Defaults to 100. + mongo.fault.fixed_delay.percent Probability of an eligible MongoDB operation to be affected by the injected fault when there is no active fault. diff --git a/source/common/mongo/proxy.cc b/source/common/mongo/proxy.cc index 1c876de012940..e3ea4675f03f2 100644 --- a/source/common/mongo/proxy.cc +++ b/source/common/mongo/proxy.cc @@ -185,7 +185,8 @@ void ProxyFilter::decodeReply(ReplyMessagePtr&& message) { break; } - if (active_query_list_.empty() && drain_decision_.drainClose()) { + if (active_query_list_.empty() && drain_decision_.drainClose() && + runtime_.snapshot().featureEnabled(MongoRuntimeConfig::get().DrainCloseEnabled, 100)) { ENVOY_LOG(debug, "drain closing mongo connection"); stats_.cx_drain_close_.inc(); diff --git a/source/common/mongo/proxy.h b/source/common/mongo/proxy.h index 10516ac8c86ac..799f0195e5eb6 100644 --- a/source/common/mongo/proxy.h +++ b/source/common/mongo/proxy.h @@ -36,6 +36,7 @@ class MongoRuntimeConfigKeys { const std::string LoggingEnabled{"mongo.logging_enabled"}; const std::string ProxyEnabled{"mongo.proxy_enabled"}; const std::string ConnectionLoggingEnabled{"mongo.connection_logging_enabled"}; + const std::string DrainCloseEnabled{"mongo.drain_close_enabled"}; }; typedef ConstSingleton MongoRuntimeConfig; diff --git a/test/common/mongo/proxy_test.cc b/test/common/mongo/proxy_test.cc index 3b2dc205ece08..a6d2e647b8e8b 100644 --- a/test/common/mongo/proxy_test.cc +++ b/test/common/mongo/proxy_test.cc @@ -430,6 +430,8 @@ TEST_F(MongoProxyFilterTest, ConcurrentQueryWithDrainClose) { message->flags(0b11); message->cursorId(1); message->documents().push_back(Bson::DocumentImpl::create()->addString("hello", "world")); + ON_CALL(runtime_.snapshot_, featureEnabled("mongo.drain_close_enabled", 100)) + .WillByDefault(Return(true)); EXPECT_CALL(drain_decision_, drainClose()).WillOnce(Return(true)); drain_timer = new Event::MockTimer(&read_filter_callbacks_.connection_.dispatcher_); EXPECT_CALL(*drain_timer, enableTimer(std::chrono::milliseconds(0)));