diff --git a/test/common/upstream/cluster_manager_impl_test.cc b/test/common/upstream/cluster_manager_impl_test.cc index 37a078501974..a5fb36b1f98e 100644 --- a/test/common/upstream/cluster_manager_impl_test.cc +++ b/test/common/upstream/cluster_manager_impl_test.cc @@ -231,7 +231,7 @@ TEST_F(ClusterManagerImplTest, OutlierEventLog) { )EOF"; EXPECT_CALL(log_manager_, createAccessLog("foo")); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); } TEST_F(ClusterManagerImplTest, NoSdsConfig) { @@ -262,7 +262,7 @@ TEST_F(ClusterManagerImplTest, UnknownClusterType) { } )EOF"; - EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV2Json(json)), EnvoyException, + EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV3Json(json)), EnvoyException, "invalid value \"foo\" for type TYPE_ENUM"); } @@ -280,7 +280,7 @@ TEST_F(ClusterManagerImplTest, LocalClusterNotDefined) { )EOF", clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_2")})); - EXPECT_THROW(create(parseBootstrapFromV2Json(json)), EnvoyException); + EXPECT_THROW(create(parseBootstrapFromV3Json(json)), EnvoyException); } TEST_F(ClusterManagerImplTest, BadClusterManagerConfig) { @@ -298,7 +298,7 @@ TEST_F(ClusterManagerImplTest, BadClusterManagerConfig) { } )EOF"; - EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV2Json(json)), EnvoyException, + EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV3Json(json)), EnvoyException, "fake_property: Cannot find field"); } @@ -317,7 +317,7 @@ TEST_F(ClusterManagerImplTest, LocalClusterDefined) { clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_2"), defaultStaticClusterJson("new_cluster")})); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); checkStats(3 /*added*/, 0 /*modified*/, 0 /*removed*/, 3 /*active*/, 0 /*warming*/); factory_.tls_.shutdownThread(); @@ -327,7 +327,7 @@ TEST_F(ClusterManagerImplTest, DuplicateCluster) { const std::string json = fmt::sprintf( "{\"static_resources\":{%s}}", clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_1")})); - const auto config = parseBootstrapFromV2Json(json); + const auto config = parseBootstrapFromV3Json(json); EXPECT_THROW(create(config), EnvoyException); } @@ -697,7 +697,7 @@ TEST_F(ClusterManagerImplTest, ClusterProvidedLbNoLb) { cluster1->info_->lb_type_ = LoadBalancerType::ClusterProvided; EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _)) .WillOnce(Return(std::make_pair(cluster1, nullptr))); - EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV2Json(json)), EnvoyException, + EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Json(json)), EnvoyException, "cluster manager: cluster provided LB specified but cluster " "'cluster_0' did not provide one. Check cluster documentation."); } @@ -711,7 +711,7 @@ TEST_F(ClusterManagerImplTest, ClusterProvidedLbNotConfigured) { cluster1->info_->name_ = "cluster_0"; EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _)) .WillOnce(Return(std::make_pair(cluster1, new MockThreadAwareLoadBalancer()))); - EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV2Json(json)), EnvoyException, + EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Json(json)), EnvoyException, "cluster manager: cluster provided LB not specified but cluster " "'cluster_0' provided one. Check cluster documentation."); } @@ -731,7 +731,7 @@ class ClusterManagerImplThreadAwareLbTest : public ClusterManagerImplTest { EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _)) .WillOnce(Return(std::make_pair(cluster1, nullptr))); ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary)); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); EXPECT_EQ(nullptr, cluster_manager_->get("cluster_0")->loadBalancer().chooseHost(nullptr)); @@ -834,7 +834,7 @@ TEST_F(ClusterManagerImplTest, UnknownCluster) { const std::string json = fmt::sprintf("{\"static_resources\":{%s}}", clustersJson({defaultStaticClusterJson("cluster_1")})); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); EXPECT_EQ(nullptr, cluster_manager_->get("hello")); EXPECT_EQ(nullptr, cluster_manager_->httpConnPoolForCluster("hello", ResourcePriority::Default, Http::Protocol::Http2, nullptr)); @@ -890,7 +890,7 @@ TEST_F(ClusterManagerImplTest, ShutdownOrder) { const std::string json = fmt::sprintf("{\"static_resources\":{%s}}", clustersJson({defaultStaticClusterJson("cluster_1")})); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); Cluster& cluster = cluster_manager_->activeClusters().begin()->second; EXPECT_EQ("cluster_1", cluster.info()->name()); EXPECT_EQ(cluster.info(), cluster_manager_->get("cluster_1")->info()); @@ -918,7 +918,7 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) { "dynamic_resources": { "cds_config": { "api_config_source": { - "api_type": "UNSUPPORTED_REST_LEGACY", + "api_type": "0", "refresh_delay": "30s", "cluster_names": ["cds_cluster"] } @@ -958,7 +958,7 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) { EXPECT_CALL(*cds_cluster, initialize(_)); EXPECT_CALL(*cluster1, initialize(_)); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); ReadyWatcher initialized; cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); }); @@ -1000,78 +1000,102 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) { version_info: version3 static_clusters: - cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "cds_cluster" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 - cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "fake_cluster" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 - cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "fake_cluster2" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 dynamic_active_clusters: - version_info: "version1" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "cluster3" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 - version_info: "version2" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "cluster4" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 - version_info: "version3" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "cluster5" type: "STATIC" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 @@ -1120,7 +1144,7 @@ TEST_F(ClusterManagerImplTest, DynamicRemoveWithLocalCluster) { ON_CALL(*foo, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary)); EXPECT_CALL(*foo, initialize(_)); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); foo->initialize_callback_(); // Now add a dynamic cluster. This cluster will have a member update callback from the local @@ -1178,14 +1202,18 @@ TEST_F(ClusterManagerImplTest, RemoveWarmingCluster) { dynamic_warming_clusters: - version_info: "version3" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "fake_cluster" type: STATIC connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 @@ -1221,14 +1249,18 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) { dynamic_warming_clusters: - version_info: "version3" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "fake_cluster" type: STATIC connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 last_updated: seconds: 1234567891 nanos: 234000000 @@ -1242,7 +1274,7 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) { EXPECT_CALL(*cluster2, initializePhase()).Times(0); EXPECT_CALL(*cluster2, initialize(_)); EXPECT_TRUE(cluster_manager_->addOrUpdateCluster( - parseClusterFromV2Json(fmt::sprintf(kDefaultStaticClusterTmpl, "fake_cluster", + parseClusterFromV3Json(fmt::sprintf(kDefaultStaticClusterTmpl, "fake_cluster", R"EOF( "socket_address": { "address": "127.0.0.1", @@ -1254,14 +1286,18 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) { dynamic_warming_clusters: - version_info: "version3" cluster: - "@type": type.googleapis.com/envoy.api.v2.Cluster + "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster name: "fake_cluster" type: STATIC connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11002 + load_assignment: + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11002 last_updated: seconds: 1234567891 nanos: 234000000 @@ -1404,7 +1440,7 @@ TEST_F(ClusterManagerImplTest, AddOrUpdateClusterStaticExists) { ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary)); EXPECT_CALL(*cluster1, initialize(_)); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); ReadyWatcher initialized; cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); }); @@ -1433,7 +1469,7 @@ TEST_F(ClusterManagerImplTest, HostsPostedToTlsCluster) { ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary)); EXPECT_CALL(*cluster1, initialize(_)); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); ReadyWatcher initialized; cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); }); @@ -1501,7 +1537,7 @@ TEST_F(ClusterManagerImplTest, CloseHttpConnectionsOnHealthFailure) { // Test inline init. initialize_callback(); })); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); EXPECT_CALL(factory_, allocateConnPool_(_, _, _)).WillOnce(Return(cp1)); cluster_manager_->httpConnPoolForCluster("some_cluster", ResourcePriority::Default, @@ -1564,7 +1600,7 @@ TEST_F(ClusterManagerImplTest, CloseTcpConnectionPoolsOnHealthFailure) { // Test inline init. initialize_callback(); })); - create(parseBootstrapFromV2Json(json)); + create(parseBootstrapFromV3Json(json)); EXPECT_CALL(factory_, allocateTcpConnPool_(_)).WillOnce(Return(cp1)); cluster_manager_->tcpConnPoolForCluster("some_cluster", ResourcePriority::Default, nullptr); diff --git a/test/common/upstream/utility.h b/test/common/upstream/utility.h index 742efed4e9d3..ef3dd210adf3 100644 --- a/test/common/upstream/utility.h +++ b/test/common/upstream/utility.h @@ -27,12 +27,21 @@ constexpr static const char* kDefaultStaticClusterTmpl = R"EOF( "connect_timeout": "0.250s", "type": "static", "lb_policy": "round_robin", - "hosts": [ + "load_assignment": { + "endpoints": [ { - %s, + "lb_endpoints": [ + { + "endpoint": { + "address": { + %s, } + } + } + ] } ] } + } )EOF"; inline std::string defaultStaticClusterJson(const std::string& name) { @@ -44,15 +53,16 @@ inline std::string defaultStaticClusterJson(const std::string& name) { } inline envoy::config::bootstrap::v3::Bootstrap -parseBootstrapFromV2Json(const std::string& json_string) { +parseBootstrapFromV3Json(const std::string& json_string, bool avoid_boosting = true) { envoy::config::bootstrap::v3::Bootstrap bootstrap; - TestUtility::loadFromJson(json_string, bootstrap, true); + TestUtility::loadFromJson(json_string, bootstrap, true, avoid_boosting); return bootstrap; } -inline envoy::config::cluster::v3::Cluster parseClusterFromV2Json(const std::string& json_string) { +inline envoy::config::cluster::v3::Cluster parseClusterFromV3Json(const std::string& json_string, + bool avoid_boosting = true) { envoy::config::cluster::v3::Cluster cluster; - TestUtility::loadFromJson(json_string, cluster, true); + TestUtility::loadFromJson(json_string, cluster, true, avoid_boosting); return cluster; } @@ -64,7 +74,7 @@ inline envoy::config::cluster::v3::Cluster parseClusterFromV3Yaml(const std::str } inline envoy::config::cluster::v3::Cluster defaultStaticCluster(const std::string& name) { - return parseClusterFromV2Json(defaultStaticClusterJson(name)); + return parseClusterFromV3Json(defaultStaticClusterJson(name)); } inline HostSharedPtr makeTestHost(ClusterInfoConstSharedPtr cluster, const std::string& hostname, diff --git a/test/server/configuration_impl_test.cc b/test/server/configuration_impl_test.cc index cd7f2ce5c7e4..5576179da9b8 100644 --- a/test/server/configuration_impl_test.cc +++ b/test/server/configuration_impl_test.cc @@ -102,7 +102,7 @@ TEST_F(ConfigurationImplTest, CustomStatsFlushInterval) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); MainImpl config; config.initialize(bootstrap, server_, cluster_manager_factory_); @@ -122,14 +122,24 @@ TEST_F(ConfigurationImplTest, SetUpstreamClusterPerConnectionBufferLimit) { "connect_timeout": "0.01s", "per_connection_buffer_limit_bytes": 8192, "lb_policy": "round_robin", - "hosts": [ - { - "socket_address" : { - "address": "127.0.0.1", - "port_value": 9999 + "load_assignment": { + "endpoints": [ + { + "lb_endpoints": [ + { + "endpoint": { + "address": { + "socket_address": { + "address": "127.0.0.1", + "port_value": 9999 + } } } - ] + } + ] + } + ] + } } ] }, @@ -145,7 +155,7 @@ TEST_F(ConfigurationImplTest, SetUpstreamClusterPerConnectionBufferLimit) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); MainImpl config; config.initialize(bootstrap, server_, cluster_manager_factory_); @@ -189,7 +199,7 @@ TEST_F(ConfigurationImplTest, NullTracerSetWhenTracingConfigurationAbsent) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); server_.local_info_.node_.set_cluster(""); MainImpl config; @@ -229,7 +239,7 @@ TEST_F(ConfigurationImplTest, NullTracerSetWhenHttpKeyAbsentFromTracerConfigurat } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); server_.local_info_.node_.set_cluster(""); MainImpl config; @@ -281,7 +291,7 @@ TEST_F(ConfigurationImplTest, ConfigurationFailsWhenInvalidTracerSpecified) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); MainImpl config; EXPECT_THROW_WITH_MESSAGE(config.initialize(bootstrap, server_, cluster_manager_factory_), EnvoyException, @@ -307,7 +317,7 @@ TEST_F(ConfigurationImplTest, ProtoSpecifiedStatsSink) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); auto& sink = *bootstrap.mutable_stats_sinks()->Add(); sink.set_name(Extensions::StatSinks::StatsSinkNames::get().Statsd); @@ -338,7 +348,7 @@ TEST_F(ConfigurationImplTest, StatsSinkWithInvalidName) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); envoy::config::metrics::v3::StatsSink& sink = *bootstrap.mutable_stats_sinks()->Add(); sink.set_name("envoy.invalid"); @@ -368,7 +378,7 @@ TEST_F(ConfigurationImplTest, StatsSinkWithNoName) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); bootstrap.mutable_stats_sinks()->Add(); @@ -397,7 +407,7 @@ TEST_F(ConfigurationImplTest, StatsSinkWithNoType) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); auto& sink = *bootstrap.mutable_stats_sinks()->Add(); udpa::type::v1::TypedStruct typed_struct; @@ -530,7 +540,7 @@ TEST_F(ConfigurationImplTest, AdminSocketOptions) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); InitialImpl config(bootstrap); Network::MockListenSocket socket_mock; @@ -616,7 +626,7 @@ TEST_F(ConfigurationImplTest, ExceedLoadBalancerHostWeightsLimit) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); MainImpl config; EXPECT_THROW_WITH_MESSAGE( @@ -722,7 +732,7 @@ TEST_F(ConfigurationImplTest, ExceedLoadBalancerLocalityWeightsLimit) { } )EOF"; - auto bootstrap = Upstream::parseBootstrapFromV2Json(json); + auto bootstrap = Upstream::parseBootstrapFromV3Json(json); MainImpl config; EXPECT_THROW_WITH_MESSAGE( diff --git a/test/test_common/utility.h b/test/test_common/utility.h index 0727b98729c7..aa01d2f6f35b 100644 --- a/test/test_common/utility.h +++ b/test/test_common/utility.h @@ -538,8 +538,9 @@ class TestUtility { // Strict variants of Protobuf::MessageUtil static void loadFromJson(const std::string& json, Protobuf::Message& message, - bool preserve_original_type = false) { - MessageUtil::loadFromJson(json, message, ProtobufMessage::getStrictValidationVisitor()); + bool preserve_original_type = false, bool avoid_boosting = false) { + MessageUtil::loadFromJson(json, message, ProtobufMessage::getStrictValidationVisitor(), + !avoid_boosting); if (!preserve_original_type) { Config::VersionConverter::eraseOriginalTypeInformation(message); }