Skip to content
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

10843 construct config from v2 yaml #11923

Closed
Closed
Show file tree
Hide file tree
Changes from 8 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
33 changes: 17 additions & 16 deletions test/common/tcp_proxy/tcp_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ Config constructConfigFromYaml(const std::string& yaml,
return Config(tcp_proxy, context);
}

Config constructConfigFromV2Yaml(const std::string& yaml,
Server::Configuration::FactoryContext& context) {
Config constructConfigFromV3Yaml(const std::string& yaml,
Server::Configuration::FactoryContext& context,
bool avoid_boosting = true) {
envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy tcp_proxy;
TestUtility::loadFromYamlAndValidate(yaml, tcp_proxy);
TestUtility::loadFromYamlAndValidate(yaml, tcp_proxy, false, avoid_boosting);
return Config(tcp_proxy, context);
}

Expand All @@ -76,7 +77,7 @@ cluster: foo
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));
EXPECT_EQ(std::chrono::hours(1), config_obj.sharedConfig()->idleTimeout().value());
}

Expand All @@ -88,7 +89,7 @@ idle_timeout: 0s
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));
EXPECT_FALSE(config_obj.sharedConfig()->idleTimeout().has_value());
}

Expand All @@ -100,7 +101,7 @@ idle_timeout: 1s
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));
EXPECT_EQ(std::chrono::seconds(1), config_obj.sharedConfig()->idleTimeout().value());
}

Expand Down Expand Up @@ -403,7 +404,7 @@ TEST(ConfigTest, WeightedClusterWithZeroWeightConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
EXPECT_THROW(constructConfigFromV2Yaml(yaml, factory_context), EnvoyException);
EXPECT_THROW(constructConfigFromV3Yaml(yaml, factory_context), EnvoyException);
}

// Tests that it is possible to define a list of weighted clusters.
Expand All @@ -419,7 +420,7 @@ TEST(ConfigTest, WeightedClustersConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

NiceMock<Network::MockConnection> connection;
EXPECT_CALL(factory_context.random_, random()).WillOnce(Return(0));
Expand Down Expand Up @@ -453,7 +454,7 @@ TEST(ConfigTest, WeightedClustersWithMetadataMatchConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

{
ProtobufWkt::Value v1, v2;
Expand Down Expand Up @@ -540,7 +541,7 @@ TEST(ConfigTest, WeightedClustersWithMetadataMatchAndTopLevelMetadataMatchConfig
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

ProtobufWkt::Value v00, v01, v04;
v00.set_string_value("v00");
Expand Down Expand Up @@ -631,7 +632,7 @@ TEST(ConfigTest, WeightedClustersWithTopLevelMetadataMatchConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

ProtobufWkt::Value v1, v2;
v1.set_string_value("v1");
Expand Down Expand Up @@ -670,7 +671,7 @@ TEST(ConfigTest, TopLevelMetadataMatchConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

ProtobufWkt::Value v1, v2;
v1.set_string_value("v1");
Expand Down Expand Up @@ -703,7 +704,7 @@ TEST(ConfigTest, ClusterWithTopLevelMetadataMatchConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

ProtobufWkt::Value v1, v2;
v1.set_string_value("v1");
Expand Down Expand Up @@ -742,7 +743,7 @@ TEST(ConfigTest, PerConnectionClusterWithTopLevelMetadataMatchConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));

ProtobufWkt::Value v1, v2;
v1.set_string_value("v1");
Expand Down Expand Up @@ -781,7 +782,7 @@ TEST(ConfigTest, HashWithSourceIpConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));
EXPECT_NE(nullptr, config_obj.hashPolicy());
}

Expand All @@ -792,7 +793,7 @@ TEST(ConfigTest, HashWithSourceIpDefaultConfig) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
Config config_obj(constructConfigFromV2Yaml(yaml, factory_context));
Config config_obj(constructConfigFromV3Yaml(yaml, factory_context));
EXPECT_EQ(nullptr, config_obj.hashPolicy());
}

Expand Down
15 changes: 5 additions & 10 deletions test/common/upstream/cluster_factory_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ TEST_F(TestStaticClusterImplTest, CreateWithoutConfig) {
connect_timeout: 0.25s
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: staticcluster
endpoints:
- lb_endpoints:
- endpoint:
Expand All @@ -95,7 +94,7 @@ TEST_F(TestStaticClusterImplTest, CreateWithoutConfig) {
TestStaticClusterFactory factory;
Registry::InjectFactory<ClusterFactory> registered_factory(factory);

const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml);
auto create_result = ClusterFactoryImplBase::create(
cluster_config, cm_, stats_, tls_, dns_resolver_, ssl_context_manager_, runtime_, random_,
dispatcher_, log_manager_, local_info_, admin_, singleton_manager_,
Expand Down Expand Up @@ -123,7 +122,6 @@ TEST_F(TestStaticClusterImplTest, CreateWithStructConfig) {
connect_timeout: 0.25s
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: staticcluster
endpoints:
- lb_endpoints:
- endpoint:
Expand All @@ -141,7 +139,7 @@ TEST_F(TestStaticClusterImplTest, CreateWithStructConfig) {
port_value: 80
)EOF";

const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml);
auto create_result = ClusterFactoryImplBase::create(
cluster_config, cm_, stats_, tls_, dns_resolver_, ssl_context_manager_, runtime_, random_,
dispatcher_, log_manager_, local_info_, admin_, singleton_manager_,
Expand All @@ -168,7 +166,6 @@ TEST_F(TestStaticClusterImplTest, CreateWithTypedConfig) {
connect_timeout: 0.25s
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: staticcluster
endpoints:
- lb_endpoints:
- endpoint:
Expand All @@ -185,7 +182,7 @@ TEST_F(TestStaticClusterImplTest, CreateWithTypedConfig) {
port_value: 80
)EOF";

const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml);
auto create_result = ClusterFactoryImplBase::create(
cluster_config, cm_, stats_, tls_, dns_resolver_, ssl_context_manager_, runtime_, random_,
dispatcher_, log_manager_, local_info_, admin_, singleton_manager_,
Expand All @@ -212,7 +209,6 @@ TEST_F(TestStaticClusterImplTest, UnsupportedClusterType) {
connect_timeout: 0.25s
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: staticcluster
endpoints:
- lb_endpoints:
- endpoint:
Expand All @@ -229,7 +225,7 @@ TEST_F(TestStaticClusterImplTest, UnsupportedClusterType) {
// the factory is not registered, expect to throw
EXPECT_THROW_WITH_MESSAGE(
{
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml);
ClusterFactoryImplBase::create(
cluster_config, cm_, stats_, tls_, dns_resolver_, ssl_context_manager_, runtime_,
random_, dispatcher_, log_manager_, local_info_, admin_, singleton_manager_,
Expand All @@ -249,7 +245,6 @@ TEST_F(TestStaticClusterImplTest, HostnameWithoutDNS) {
consistent_hashing_lb_config:
use_hostname_for_hashing: true
load_assignment:
cluster_name: staticcluster
endpoints:
- lb_endpoints:
- endpoint:
Expand All @@ -263,7 +258,7 @@ TEST_F(TestStaticClusterImplTest, HostnameWithoutDNS) {

EXPECT_THROW_WITH_MESSAGE(
{
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
const envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml);
ClusterFactoryImplBase::create(
cluster_config, cm_, stats_, tls_, dns_resolver_, ssl_context_manager_, runtime_,
random_, dispatcher_, log_manager_, local_info_, admin_, singleton_manager_,
Expand Down
4 changes: 2 additions & 2 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ TEST_F(ClusterManagerImplTest, MergedUpdatesDestroyedOnUpdate) {
common_lb_config:
update_merge_window: 3s
)EOF";
EXPECT_TRUE(cluster_manager_->addOrUpdateCluster(parseClusterFromV2Yaml(yaml), "version1"));
EXPECT_TRUE(cluster_manager_->addOrUpdateCluster(parseClusterFromV3Yaml(yaml), "version1"));

Cluster& cluster = cluster_manager_->activeClusters().find("new_cluster")->second;
HostVectorSharedPtr hosts(
Expand Down Expand Up @@ -2734,7 +2734,7 @@ TEST_F(ClusterManagerImplTest, MergedUpdatesDestroyedOnUpdate) {
.gauge("cluster_manager.warming_clusters", Stats::Gauge::ImportMode::NeverImport)
.value());
EXPECT_TRUE(
cluster_manager_->addOrUpdateCluster(parseClusterFromV2Yaml(yaml_updated), "version2"));
cluster_manager_->addOrUpdateCluster(parseClusterFromV3Yaml(yaml_updated), "version2"));
EXPECT_EQ(2, factory_.stats_
.gauge("cluster_manager.active_clusters", Stats::Gauge::ImportMode::NeverImport)
.value());
Expand Down
2 changes: 1 addition & 1 deletion test/common/upstream/eds_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EdsSpeedTest {

void resetCluster(const std::string& yaml_config, Cluster::InitializePhase initialize_phase) {
local_info_.node_.mutable_locality()->set_zone("us-east-1a");
eds_cluster_ = parseClusterFromV2Yaml(yaml_config);
eds_cluster_ = parseClusterFromV3Yaml(yaml_config);
ankatare marked this conversation as resolved.
Show resolved Hide resolved
Envoy::Stats::ScopePtr scope = stats_.createScope(fmt::format(
"cluster.{}.",
eds_cluster_.alt_stat_name().empty() ? eds_cluster_.name() : eds_cluster_.alt_stat_name()));
Expand Down
14 changes: 7 additions & 7 deletions test/common/upstream/eds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class EdsTest : public testing::Test {
connect_timeout: 0.25s
type: EDS
lb_policy: ROUND_ROBIN
drain_connections_on_host_removal: true
ignore_health_on_host_removal: true
eds_cluster_config:
service_name: fare
eds_config:
Expand Down Expand Up @@ -88,7 +88,7 @@ class EdsTest : public testing::Test {

void resetCluster(const std::string& yaml_config, Cluster::InitializePhase initialize_phase) {
local_info_.node_.mutable_locality()->set_zone("us-east-1a");
eds_cluster_ = parseClusterFromV2Yaml(yaml_config);
eds_cluster_ = parseClusterFromV3Yaml(yaml_config);
Envoy::Stats::ScopePtr scope = stats_.createScope(fmt::format(
"cluster.{}.",
eds_cluster_.alt_stat_name().empty() ? eds_cluster_.name() : eds_cluster_.alt_stat_name()));
Expand Down Expand Up @@ -137,8 +137,8 @@ class EdsWithHealthCheckUpdateTest : public EdsTest {

// Build the initial cluster with some endpoints.
void initializeCluster(const std::vector<uint32_t> endpoint_ports,
const bool drain_connections_on_host_removal) {
resetCluster(drain_connections_on_host_removal);
const bool ignore_health_on_host_removal) {
resetCluster(ignore_health_on_host_removal);

auto health_checker = std::make_shared<MockHealthChecker>();
EXPECT_CALL(*health_checker, start());
Expand Down Expand Up @@ -172,13 +172,13 @@ class EdsWithHealthCheckUpdateTest : public EdsTest {
}
}

void resetCluster(const bool drain_connections_on_host_removal) {
void resetCluster(const bool ignore_health_on_host_removal) {
const std::string config = R"EOF(
name: name
connect_timeout: 0.25s
type: EDS
lb_policy: ROUND_ROBIN
drain_connections_on_host_removal: {}
ignore_health_on_host_removal: {}
eds_cluster_config:
service_name: fare
eds_config:
Expand All @@ -188,7 +188,7 @@ class EdsWithHealthCheckUpdateTest : public EdsTest {
- eds
refresh_delay: 1s
)EOF";
EdsTest::resetCluster(fmt::format(config, drain_connections_on_host_removal),
EdsTest::resetCluster(fmt::format(config, ignore_health_on_host_removal),
Cluster::InitializePhase::Secondary);
}

Expand Down
Loading