Skip to content

Commit

Permalink
Add setters for all OptionsImpl fields. (#3424)
Browse files Browse the repository at this point in the history
This allows modifying options in a custom main() before instantiating
the server but leaving them readonly within the server's context.

Signed-off-by: Trevor Schroeder <trevors@google.com>
  • Loading branch information
tschroed authored and mattklein123 committed May 18, 2018
1 parent ab08a0b commit cf0cbc5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
37 changes: 37 additions & 0 deletions source/server/options_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ class OptionsImpl : public Server::Options {
OptionsImpl(int argc, char** argv, const HotRestartVersionCb& hot_restart_version_cb,
spdlog::level::level_enum default_log_level);

// Setters for option fields. These are not part of the Options interface.
void setBaseId(uint64_t base_id) { base_id_ = base_id; };
void setConcurrency(uint32_t concurrency) { concurrency_ = concurrency; }
void setConfigPath(const std::string& config_path) { config_path_ = config_path; }
void setConfigYaml(const std::string& config_yaml) { config_yaml_ = config_yaml; }
void setV2ConfigOnly(bool v2_config_only) { v2_config_only_ = v2_config_only; }
void setAdminAddressPath(const std::string& admin_address_path) {
admin_address_path_ = admin_address_path;
}
void setLocalAddressIpVersion(Network::Address::IpVersion local_address_ip_version) {
local_address_ip_version_ = local_address_ip_version;
}
void setDrainTime(std::chrono::seconds drain_time) { drain_time_ = drain_time; }
void setLogLevel(spdlog::level::level_enum log_level) { log_level_ = log_level; }
void setLogFormat(const std::string& log_format) { log_format_ = log_format; }
void setLogPath(const std::string& log_path) { log_path_ = log_path; }
void setParentShutdownTime(std::chrono::seconds parent_shutdown_time) {
parent_shutdown_time_ = parent_shutdown_time;
}
void setRestartEpoch(uint64_t restart_epoch) { restart_epoch_ = restart_epoch; }
void setMode(Server::Mode mode) { mode_ = mode; }
void setFileFlushIntervalMsec(std::chrono::milliseconds file_flush_interval_msec) {
file_flush_interval_msec_ = file_flush_interval_msec;
}
void setServiceClusterName(const std::string& service_cluster) {
service_cluster_ = service_cluster;
}
void setServiceNodeName(const std::string& service_node) { service_node_ = service_node; }
void setServiceZone(const std::string& service_zone) { service_zone_ = service_zone; }
void setMaxStats(uint64_t max_stats) { max_stats_ = max_stats; }
void setMaxObjNameLength(uint64_t max_obj_name_length) {
max_obj_name_length_ = max_obj_name_length;
}
void setHotRestartDisabled(bool hot_restart_disabled) {
hot_restart_disabled_ = hot_restart_disabled;
}

// Server::Options
uint64_t baseId() const override { return base_id_; }
uint32_t concurrency() const override { return concurrency_; }
Expand Down
49 changes: 49 additions & 0 deletions test/server/options_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,55 @@ TEST(OptionsImplTest, All) {
EXPECT_EQ(true, options->hotRestartDisabled());
}

TEST(OptionsImplTest, SetAll) {
std::unique_ptr<OptionsImpl> options = createOptionsImpl("envoy -c hello");
bool v2_config_only = options->v2ConfigOnly();
bool hot_restart_disabled = options->v2ConfigOnly();
options->setBaseId(109876);
options->setConcurrency(42);
options->setConfigPath("foo");
options->setConfigYaml("bogus:");
options->setV2ConfigOnly(!options->v2ConfigOnly());
options->setAdminAddressPath("path");
options->setLocalAddressIpVersion(Network::Address::IpVersion::v6);
options->setDrainTime(std::chrono::seconds(42));
options->setLogLevel(spdlog::level::trace);
options->setLogFormat("%L %n %v");
options->setLogPath("/foo/bar");
options->setParentShutdownTime(std::chrono::seconds(43));
options->setRestartEpoch(44);
options->setFileFlushIntervalMsec(std::chrono::milliseconds(45));
options->setMode(Server::Mode::Validate);
options->setServiceClusterName("cluster_foo");
options->setServiceNodeName("node_foo");
options->setServiceZone("zone_foo");
options->setMaxStats(12345);
options->setMaxObjNameLength(54321);
options->setHotRestartDisabled(!options->hotRestartDisabled());

EXPECT_EQ(109876, options->baseId());
EXPECT_EQ(42U, options->concurrency());
EXPECT_EQ("foo", options->configPath());
EXPECT_EQ("bogus:", options->configYaml());
EXPECT_EQ(!v2_config_only, options->v2ConfigOnly());
EXPECT_EQ("path", options->adminAddressPath());
EXPECT_EQ(Network::Address::IpVersion::v6, options->localAddressIpVersion());
EXPECT_EQ(std::chrono::seconds(42), options->drainTime());
EXPECT_EQ(spdlog::level::trace, options->logLevel());
EXPECT_EQ("%L %n %v", options->logFormat());
EXPECT_EQ("/foo/bar", options->logPath());
EXPECT_EQ(std::chrono::seconds(43), options->parentShutdownTime());
EXPECT_EQ(44, options->restartEpoch());
EXPECT_EQ(std::chrono::milliseconds(45), options->fileFlushIntervalMsec());
EXPECT_EQ(Server::Mode::Validate, options->mode());
EXPECT_EQ("cluster_foo", options->serviceClusterName());
EXPECT_EQ("node_foo", options->serviceNodeName());
EXPECT_EQ("zone_foo", options->serviceZone());
EXPECT_EQ(12345U, options->maxStats());
EXPECT_EQ(54321U, options->maxObjNameLength());
EXPECT_EQ(!hot_restart_disabled, options->hotRestartDisabled());
}

TEST(OptionsImplTest, DefaultParams) {
std::unique_ptr<OptionsImpl> options = createOptionsImpl("envoy -c hello");
EXPECT_EQ(std::chrono::seconds(600), options->drainTime());
Expand Down

0 comments on commit cf0cbc5

Please sign in to comment.