diff --git a/include/envoy/server/options.h b/include/envoy/server/options.h index fd119fc81ee27..0b141f86830c7 100644 --- a/include/envoy/server/options.h +++ b/include/envoy/server/options.h @@ -137,6 +137,11 @@ class Options { * router/cluster/listener. */ virtual uint64_t maxObjNameLength() PURE; + + /** + * @return bool indicating whether the hot restart functionality has been disabled via cli flags. + */ + virtual bool hotRestartDisabled() PURE; }; } // namespace Server diff --git a/source/server/options_impl.cc b/source/server/options_impl.cc index 7c2b6aed20226..efe802dc4aa8f 100644 --- a/source/server/options_impl.cc +++ b/source/server/options_impl.cc @@ -92,6 +92,8 @@ OptionsImpl::OptionsImpl(int argc, char** argv, const HotRestartVersionCb& hot_r " the cluster name)", false, ENVOY_DEFAULT_MAX_OBJ_NAME_LENGTH, "uint64_t", cmd); + TCLAP::SwitchArg disable_hot_restart("", "disable-hot-restart", + "Disable hot restart functionality", cmd, false); cmd.setExceptionHandling(false); try { @@ -169,5 +171,6 @@ OptionsImpl::OptionsImpl(int argc, char** argv, const HotRestartVersionCb& hot_r parent_shutdown_time_ = std::chrono::seconds(parent_shutdown_time_s.getValue()); max_stats_ = max_stats.getValue(); max_obj_name_length_ = max_obj_name_len.getValue(); + hot_restart_disabled_ = disable_hot_restart.getValue(); } } // namespace Envoy diff --git a/source/server/options_impl.h b/source/server/options_impl.h index b4b0335cc1d5a..0598e1b666711 100644 --- a/source/server/options_impl.h +++ b/source/server/options_impl.h @@ -46,6 +46,7 @@ class OptionsImpl : public Server::Options { const std::string& serviceZone() override { return service_zone_; } uint64_t maxStats() override { return max_stats_; } uint64_t maxObjNameLength() override { return max_obj_name_length_; } + bool hotRestartDisabled() override { return hot_restart_disabled_; } private: uint64_t base_id_; @@ -66,6 +67,7 @@ class OptionsImpl : public Server::Options { Server::Mode mode_; uint64_t max_stats_; uint64_t max_obj_name_length_; + bool hot_restart_disabled_; }; /** diff --git a/test/integration/server.h b/test/integration/server.h index 86f4d6f8c036d..b8bacf29a9242 100644 --- a/test/integration/server.h +++ b/test/integration/server.h @@ -53,6 +53,7 @@ class TestOptionsImpl : public Options { const std::string& serviceZone() override { return service_zone_; } uint64_t maxStats() override { return 16384; } uint64_t maxObjNameLength() override { return 60; } + bool hotRestartDisabled() override { return false; } private: const std::string config_path_; diff --git a/test/mocks/server/mocks.cc b/test/mocks/server/mocks.cc index 16d0bf7b7e63d..e2d6606234adf 100644 --- a/test/mocks/server/mocks.cc +++ b/test/mocks/server/mocks.cc @@ -10,6 +10,7 @@ using testing::Invoke; using testing::Return; using testing::ReturnNew; +using testing::ReturnPointee; using testing::ReturnRef; using testing::SaveArg; using testing::_; @@ -28,6 +29,7 @@ MockOptions::MockOptions(const std::string& config_path) ON_CALL(*this, logPath()).WillByDefault(ReturnRef(log_path_)); ON_CALL(*this, maxStats()).WillByDefault(Return(1000)); ON_CALL(*this, maxObjNameLength()).WillByDefault(Return(150)); + ON_CALL(*this, hotRestartDisabled()).WillByDefault(ReturnPointee(&hot_restart_disabled_)); } MockOptions::~MockOptions() {} diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 620d759094cf5..1e83e5bb9ee3f 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -62,6 +62,7 @@ class MockOptions : public Options { MOCK_METHOD0(serviceZone, const std::string&()); MOCK_METHOD0(maxStats, uint64_t()); MOCK_METHOD0(maxObjNameLength, uint64_t()); + MOCK_METHOD0(hotRestartDisabled, bool()); std::string config_path_; bool v2_config_only_{}; @@ -70,6 +71,7 @@ class MockOptions : public Options { std::string service_node_name_; std::string service_zone_name_; std::string log_path_; + bool hot_restart_disabled_{}; }; class MockAdmin : public Admin { diff --git a/test/server/options_impl_test.cc b/test/server/options_impl_test.cc index f1f746b59e322..38d3d1f1683dc 100644 --- a/test/server/options_impl_test.cc +++ b/test/server/options_impl_test.cc @@ -63,7 +63,7 @@ TEST(OptionsImplTest, All) { "envoy --mode validate --concurrency 2 -c hello --admin-address-path path --restart-epoch 1 " "--local-address-ip-version v6 -l info --service-cluster cluster --service-node node " "--service-zone zone --file-flush-interval-msec 9000 --drain-time-s 60 " - "--parent-shutdown-time-s 90 --log-path /foo/bar --v2-config-only"); + "--parent-shutdown-time-s 90 --log-path /foo/bar --v2-config-only --disable-hot-restart"); EXPECT_EQ(Server::Mode::Validate, options->mode()); EXPECT_EQ(2U, options->concurrency()); EXPECT_EQ("hello", options->configPath()); @@ -79,6 +79,7 @@ TEST(OptionsImplTest, All) { EXPECT_EQ(std::chrono::milliseconds(9000), options->fileFlushIntervalMsec()); EXPECT_EQ(std::chrono::seconds(60), options->drainTime()); EXPECT_EQ(std::chrono::seconds(90), options->parentShutdownTime()); + EXPECT_EQ(true, options->hotRestartDisabled()); } TEST(OptionsImplTest, DefaultParams) { @@ -88,6 +89,7 @@ TEST(OptionsImplTest, DefaultParams) { EXPECT_EQ("", options->adminAddressPath()); EXPECT_EQ(Network::Address::IpVersion::v4, options->localAddressIpVersion()); EXPECT_EQ(Server::Mode::Serve, options->mode()); + EXPECT_EQ(false, options->hotRestartDisabled()); } TEST(OptionsImplTest, BadCliOption) {