From bb1a252f2882e276bc9e17a6236d5419b6b0f955 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Tue, 31 Jul 2018 16:53:37 -0700 Subject: [PATCH 1/8] add more accessor into TransportSocketFactoryContext. Signed-off-by: JimmyCYJ --- api/bazel/api_build_system.bzl | 4 + api/bazel/repositories.bzl | 3 + bazel/cc_configure.bzl | 7 +- bazel/repositories.bzl | 4 +- bazel/repository_locations.bzl | 54 +++---- include/envoy/server/BUILD | 5 + .../envoy/server/transport_socket_config.h | 30 ++++ source/common/upstream/BUILD | 1 + source/common/upstream/eds.cc | 22 +-- source/common/upstream/eds.h | 7 +- source/common/upstream/logical_dns_cluster.cc | 19 +-- source/common/upstream/logical_dns_cluster.h | 6 +- .../common/upstream/original_dst_cluster.cc | 16 +- source/common/upstream/original_dst_cluster.h | 6 +- source/common/upstream/upstream_impl.cc | 150 ++++++++++-------- source/common/upstream/upstream_impl.h | 37 ++--- source/server/BUILD | 9 ++ source/server/listener_manager_impl.cc | 8 +- source/server/listener_manager_impl.h | 6 - test/common/upstream/eds_test.cc | 9 +- .../upstream/logical_dns_cluster_test.cc | 11 +- .../upstream/original_dst_cluster_test.cc | 8 +- test/common/upstream/sds_test.cc | 9 +- test/common/upstream/upstream_impl_test.cc | 55 +++++-- test/mocks/server/mocks.h | 6 + tools/protodoc/protodoc.bzl | 2 +- 26 files changed, 301 insertions(+), 193 deletions(-) diff --git a/api/bazel/api_build_system.bzl b/api/bazel/api_build_system.bzl index 497d82c5ccc07..c573b12551869 100644 --- a/api/bazel/api_build_system.bzl +++ b/api/bazel/api_build_system.bzl @@ -4,9 +4,13 @@ load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_test") _PY_SUFFIX = "_py" + _CC_SUFFIX = "_cc" + _GO_PROTO_SUFFIX = "_go_proto" + _GO_GRPC_SUFFIX = "_go_grpc" + _GO_IMPORTPATH_PREFIX = "github.com/envoyproxy/data-plane-api/api/" def _Suffix(d, suffix): diff --git a/api/bazel/repositories.bzl b/api/bazel/repositories.bzl index 2e497d712fc87..0288243c458ca 100644 --- a/api/bazel/repositories.bzl +++ b/api/bazel/repositories.bzl @@ -1,6 +1,9 @@ GOOGLEAPIS_SHA = "d642131a6e6582fc226caf9893cb7fe7885b3411" # May 23, 2018 + GOGOPROTO_SHA = "1adfc126b41513cc696b209667c8656ea7aac67c" # v1.0.0 + PROMETHEUS_SHA = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c" # Nov 17, 2017 + OPENCENSUS_SHA = "ab82e5fdec8267dc2a726544b10af97675970847" # May 23, 2018 PGV_GIT_SHA = "f9d2b11e44149635b23a002693b76512b01ae515" diff --git a/bazel/cc_configure.bzl b/bazel/cc_configure.bzl index eb1dead6b260a..3cc25e81ac509 100644 --- a/bazel/cc_configure.bzl +++ b/bazel/cc_configure.bzl @@ -1,4 +1,7 @@ -load("@bazel_tools//tools/cpp:cc_configure.bzl", _upstream_cc_autoconf_impl = "cc_autoconf_impl") +load( + "@bazel_tools//tools/cpp:cc_configure.bzl", + _upstream_cc_autoconf_impl = "cc_autoconf_impl", +) load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "find_cc") @@ -82,7 +85,6 @@ def cc_autoconf_impl(repository_ctx): return _upstream_cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools) cc_autoconf = repository_rule( - implementation = cc_autoconf_impl, attrs = { "_envoy_cc_wrapper": attr.label(default = "@envoy//bazel:cc_wrapper.py"), }, @@ -118,6 +120,7 @@ cc_autoconf = repository_rule( "VS120COMNTOOLS", "VS140COMNTOOLS", ], + implementation = cc_autoconf_impl, ) def cc_configure(): diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 3d231c259ff00..359085772bfcc 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -126,10 +126,10 @@ def _default_envoy_build_config_impl(ctx): ctx.symlink(ctx.attr.config, "extensions_build_config.bzl") _default_envoy_build_config = repository_rule( - implementation = _default_envoy_build_config_impl, attrs = { "config": attr.label(default = "@envoy//source/extensions:extensions_build_config.bzl"), }, + implementation = _default_envoy_build_config_impl, ) def _default_envoy_api_impl(ctx): @@ -147,10 +147,10 @@ def _default_envoy_api_impl(ctx): ctx.symlink(ctx.path(ctx.attr.api).dirname.get_child(d), d) _default_envoy_api = repository_rule( - implementation = _default_envoy_api_impl, attrs = { "api": attr.label(default = "@envoy//api:BUILD"), }, + implementation = _default_envoy_api_impl, ) # Python dependencies. If these become non-trivial, we might be better off using a virtualenv to diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 7a65f4c956f3a..9712442aa5130 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -4,14 +4,10 @@ REPOSITORY_LOCATIONS = dict( commit = "372daf7042ffe3da1335743e7c93d78f1399aba7", # chromium-68.0.3440.75 remote = "https://github.com/google/boringssl", ), - com_google_absl = dict( - commit = "92020a042c0cd46979db9f6f0cb32783dc07765e", # 2018-06-08 - remote = "https://github.com/abseil/abseil-cpp", - ), com_github_apache_thrift = dict( sha256 = "7d59ac4fdcb2c58037ebd4a9da5f9a49e3e034bf75b3f26d9fe48ba3d8806e6b", - urls = ["https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz"], # 0.11.0 strip_prefix = "thrift-0.11.0", + urls = ["https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz"], # 0.11.0 ), com_github_bombela_backward = dict( commit = "44ae9609e860e3428cd057f7052e505b4819eb84", # 2018-02-06 @@ -43,6 +39,10 @@ REPOSITORY_LOCATIONS = dict( commit = "c0d77201039c7b119b18bc7fb991564c602dd75d", remote = "https://github.com/gcovr/gcovr", ), + com_github_google_jwt_verify = dict( + commit = "4eb9e96485b71e00d43acc7207501caafb085b4a", + remote = "https://github.com/google/jwt_verify_lib", + ), com_github_google_libprotobuf_mutator = dict( commit = "c3d2faf04a1070b0b852b0efdef81e1a81ba925e", remote = "https://github.com/google/libprotobuf-mutator", @@ -51,22 +51,6 @@ REPOSITORY_LOCATIONS = dict( commit = "bec3b5ada2c5e5d782dff0b7b5018df646b65cb0", # v1.12.0 remote = "https://github.com/grpc/grpc.git", ), - io_opentracing_cpp = dict( - commit = "3b36b084a4d7fffc196eac83203cf24dfb8696b3", # v1.4.2 - remote = "https://github.com/opentracing/opentracing-cpp", - ), - com_lightstep_tracer_cpp = dict( - commit = "ae6a6bba65f8c4d438a6a3ac855751ca8f52e1dc", - remote = "https://github.com/lightstep/lightstep-tracer-cpp", # v0.7.1 - ), - lightstep_vendored_googleapis = dict( - commit = "d6f78d948c53f3b400bb46996eb3084359914f9b", - remote = "https://github.com/google/googleapis", - ), - com_github_google_jwt_verify = dict( - commit = "4eb9e96485b71e00d43acc7207501caafb085b4a", - remote = "https://github.com/google/jwt_verify_lib", - ), com_github_nodejs_http_parser = dict( # 2018-07-20 snapshot to pick up: # A performance fix, nodejs/http-parser PR 422. @@ -87,20 +71,24 @@ REPOSITORY_LOCATIONS = dict( commit = "f54b0e47a08782a6131cc3d60f94d038fa6e0a51", # v1.1.0 remote = "https://github.com/tencent/rapidjson", ), + com_github_twitter_common_finagle_thrift = dict( + sha256 = "1e3a57d11f94f58745e6b83348ecd4fa74194618704f45444a15bc391fde497a", + strip_prefix = "twitter.common.finagle-thrift-0.3.9/src", + urls = ["https://files.pythonhosted.org/packages/f9/e7/4f80d582578f8489226370762d2cf6bc9381175d1929eba1754e03f70708/twitter.common.finagle-thrift-0.3.9.tar.gz"], # 0.3.9 + ), com_github_twitter_common_lang = dict( sha256 = "56d1d266fd4767941d11c27061a57bc1266a3342e551bde3780f9e9eb5ad0ed1", - urls = ["https://files.pythonhosted.org/packages/08/bc/d6409a813a9dccd4920a6262eb6e5889e90381453a5f58938ba4cf1d9420/twitter.common.lang-0.3.9.tar.gz"], # 0.3.9 strip_prefix = "twitter.common.lang-0.3.9/src", + urls = ["https://files.pythonhosted.org/packages/08/bc/d6409a813a9dccd4920a6262eb6e5889e90381453a5f58938ba4cf1d9420/twitter.common.lang-0.3.9.tar.gz"], # 0.3.9 ), com_github_twitter_common_rpc = dict( sha256 = "0792b63fb2fb32d970c2e9a409d3d00633190a22eb185145fe3d9067fdaa4514", - urls = ["https://files.pythonhosted.org/packages/be/97/f5f701b703d0f25fbf148992cd58d55b4d08d3db785aad209255ee67e2d0/twitter.common.rpc-0.3.9.tar.gz"], # 0.3.9 strip_prefix = "twitter.common.rpc-0.3.9/src", + urls = ["https://files.pythonhosted.org/packages/be/97/f5f701b703d0f25fbf148992cd58d55b4d08d3db785aad209255ee67e2d0/twitter.common.rpc-0.3.9.tar.gz"], # 0.3.9 ), - com_github_twitter_common_finagle_thrift = dict( - sha256 = "1e3a57d11f94f58745e6b83348ecd4fa74194618704f45444a15bc391fde497a", - urls = ["https://files.pythonhosted.org/packages/f9/e7/4f80d582578f8489226370762d2cf6bc9381175d1929eba1754e03f70708/twitter.common.finagle-thrift-0.3.9.tar.gz"], # 0.3.9 - strip_prefix = "twitter.common.finagle-thrift-0.3.9/src", + com_google_absl = dict( + commit = "92020a042c0cd46979db9f6f0cb32783dc07765e", # 2018-06-08 + remote = "https://github.com/abseil/abseil-cpp", ), com_google_googletest = dict( commit = "43863938377a9ea1399c0596269e0890b5c5515a", @@ -114,6 +102,10 @@ REPOSITORY_LOCATIONS = dict( commit = "6a4fec616ec4b20f54d5fb530808b855cb664390", remote = "https://github.com/google/protobuf", ), + com_lightstep_tracer_cpp = dict( + commit = "ae6a6bba65f8c4d438a6a3ac855751ca8f52e1dc", + remote = "https://github.com/lightstep/lightstep-tracer-cpp", # v0.7.1 + ), grpc_httpjson_transcoding = dict( commit = "05a15e4ecd0244a981fdf0348a76658def62fa9c", # 2018-05-30 remote = "https://github.com/grpc-ecosystem/grpc-httpjson-transcoding", @@ -122,6 +114,14 @@ REPOSITORY_LOCATIONS = dict( commit = "0.11.1", remote = "https://github.com/bazelbuild/rules_go", ), + io_opentracing_cpp = dict( + commit = "3b36b084a4d7fffc196eac83203cf24dfb8696b3", # v1.4.2 + remote = "https://github.com/opentracing/opentracing-cpp", + ), + lightstep_vendored_googleapis = dict( + commit = "d6f78d948c53f3b400bb46996eb3084359914f9b", + remote = "https://github.com/google/googleapis", + ), six_archive = dict( sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", strip_prefix = "", diff --git a/include/envoy/server/BUILD b/include/envoy/server/BUILD index 42acd80d8f161..3a3179362ce49 100644 --- a/include/envoy/server/BUILD +++ b/include/envoy/server/BUILD @@ -175,9 +175,14 @@ envoy_cc_library( name = "transport_socket_config_interface", hdrs = ["transport_socket_config.h"], deps = [ + "//include/envoy/event:dispatcher_interface", + "//include/envoy/local_info:local_info_interface", "//include/envoy/network:transport_socket_interface", + "//include/envoy/runtime:runtime_interface", "//include/envoy/secret:secret_manager_interface", "//include/envoy/ssl:context_manager_interface", + "//include/envoy/stats:stats_interface", + "//include/envoy/upstream:cluster_manager_interface", "//source/common/protobuf", ], ) diff --git a/include/envoy/server/transport_socket_config.h b/include/envoy/server/transport_socket_config.h index 4e85386cb16d8..9adb43233d3e6 100644 --- a/include/envoy/server/transport_socket_config.h +++ b/include/envoy/server/transport_socket_config.h @@ -2,9 +2,14 @@ #include +#include "envoy/event/dispatcher.h" +#include "envoy/local_info/local_info.h" #include "envoy/network/transport_socket.h" +#include "envoy/runtime/runtime.h" #include "envoy/secret/secret_manager.h" #include "envoy/ssl/context_manager.h" +#include "envoy/stats/stats.h" +#include "envoy/upstream/cluster_manager.h" #include "common/protobuf/protobuf.h" @@ -33,6 +38,31 @@ class TransportSocketFactoryContext { * Return the instance of secret manager. */ virtual Secret::SecretManager& secretManager() PURE; + + /** + * @return the instance of ClusterManager. + */ + virtual Upstream::ClusterManager& clusterManager() PURE; + + /** + * @return information about the local environment the server is running in. + */ + virtual const LocalInfo::LocalInfo& local_info() PURE; + + /** + * @return Event::Dispatcher& the main thread's dispatcher. + */ + virtual Event::Dispatcher& dispatcher() PURE; + + /** + * @return RandomGenerator& the random generator for the server. + */ + virtual Envoy::Runtime::RandomGenerator& random() PURE; + + /** + * @return the server-wide stats store. + */ + virtual Stats::Store& stats() PURE; }; class TransportSocketConfigFactory { diff --git a/source/common/upstream/BUILD b/source/common/upstream/BUILD index 939f0f58b220d..545a660a4368c 100644 --- a/source/common/upstream/BUILD +++ b/source/common/upstream/BUILD @@ -362,6 +362,7 @@ envoy_cc_library( "//source/common/protobuf", "//source/common/protobuf:utility_lib", "//source/extensions/transport_sockets:well_known_names", + "//source/server:transport_socket_config_lib", "@envoy_api//envoy/api/v2/core:base_cc", ], ) diff --git a/source/common/upstream/eds.cc b/source/common/upstream/eds.cc index 46435a6de4d3c..fee384140067a 100644 --- a/source/common/upstream/eds.cc +++ b/source/common/upstream/eds.cc @@ -17,23 +17,25 @@ namespace Envoy { namespace Upstream { -EdsClusterImpl::EdsClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, ClusterManager& cm, - Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random, - bool added_via_api) - : BaseDynamicClusterImpl(cluster, cm.bindConfig(), runtime, stats, ssl_context_manager, - cm.clusterManagerFactory().secretManager(), added_via_api), - cm_(cm), local_info_(local_info), +EdsClusterImpl::EdsClusterImpl( + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : BaseDynamicClusterImpl(cluster, runtime, added_via_api, factory_context, + std::move(stats_scope)), + cm_(factory_context.clusterManager()), local_info_(factory_context.local_info()), cluster_name_(cluster.eds_cluster_config().service_name().empty() ? cluster.name() : cluster.eds_cluster_config().service_name()) { - Config::Utility::checkLocalInfo("eds", local_info); + Config::Utility::checkLocalInfo("eds", local_info_); const auto& eds_config = cluster.eds_cluster_config().eds_config(); + Event::Dispatcher& dispatcher = factory_context.dispatcher(); + Runtime::RandomGenerator& random = factory_context.random(); + Upstream::ClusterManager& cm = factory_context.clusterManager(); subscription_ = Config::SubscriptionFactory::subscriptionFromConfigSource< envoy::api::v2::ClusterLoadAssignment>( - eds_config, local_info.node(), dispatcher, cm, random, info_->statsScope(), + eds_config, local_info_.node(), dispatcher, cm, random, info_->statsScope(), [this, &eds_config, &cm, &dispatcher, &random]() -> Config::Subscription* { return new SdsSubscription(info_->stats(), eds_config, cm, dispatcher, random); diff --git a/source/common/upstream/eds.h b/source/common/upstream/eds.h index d84f02091799e..c8c333b6e9c5f 100644 --- a/source/common/upstream/eds.h +++ b/source/common/upstream/eds.h @@ -19,10 +19,9 @@ class EdsClusterImpl : public BaseDynamicClusterImpl, Config::SubscriptionCallbacks { public: EdsClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, ClusterManager& cm, - Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random, - bool added_via_api); + bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Secondary; } diff --git a/source/common/upstream/logical_dns_cluster.cc b/source/common/upstream/logical_dns_cluster.cc index 5b3709041b021..cf1fdcc29149d 100644 --- a/source/common/upstream/logical_dns_cluster.cc +++ b/source/common/upstream/logical_dns_cluster.cc @@ -15,21 +15,18 @@ namespace Envoy { namespace Upstream { -LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, - Network::DnsResolverSharedPtr dns_resolver, - ThreadLocal::SlotAllocator& tls, ClusterManager& cm, - Event::Dispatcher& dispatcher, bool added_via_api) - : ClusterImplBase(cluster, cm.bindConfig(), runtime, stats, ssl_context_manager, - cm.clusterManagerFactory().secretManager(), added_via_api), +LogicalDnsCluster::LogicalDnsCluster( + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, + Network::DnsResolverSharedPtr dns_resolver, ThreadLocal::SlotAllocator& tls, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : ClusterImplBase(cluster, runtime, added_via_api, factory_context, std::move(stats_scope)), dns_resolver_(dns_resolver), dns_refresh_rate_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))), tls_(tls.allocateSlot()), - resolve_timer_(dispatcher.createTimer([this]() -> void { startResolve(); })), - local_info_(local_info), + resolve_timer_(factory_context.dispatcher().createTimer([this]() -> void { startResolve(); })), + local_info_(factory_context.local_info()), load_assignment_(cluster.has_load_assignment() ? cluster.load_assignment() : Config::Utility::translateClusterHosts(cluster.hosts())) { diff --git a/source/common/upstream/logical_dns_cluster.h b/source/common/upstream/logical_dns_cluster.h index 2feec15579b78..cf51b52836fbb 100644 --- a/source/common/upstream/logical_dns_cluster.h +++ b/source/common/upstream/logical_dns_cluster.h @@ -29,10 +29,10 @@ namespace Upstream { class LogicalDnsCluster : public ClusterImplBase { public: LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, Network::DnsResolverSharedPtr dns_resolver, ThreadLocal::SlotAllocator& tls, - ClusterManager& cm, Event::Dispatcher& dispatcher, bool added_via_api); + bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope); ~LogicalDnsCluster(); diff --git a/source/common/upstream/original_dst_cluster.cc b/source/common/upstream/original_dst_cluster.cc index e00f39f9410d9..f3598e31ccba7 100644 --- a/source/common/upstream/original_dst_cluster.cc +++ b/source/common/upstream/original_dst_cluster.cc @@ -123,14 +123,14 @@ OriginalDstCluster::LoadBalancer::requestOverrideHost(LoadBalancerContext* conte } OriginalDstCluster::OriginalDstCluster(const envoy::api::v2::Cluster& config, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, ClusterManager& cm, - Event::Dispatcher& dispatcher, bool added_via_api) - : ClusterImplBase(config, cm.bindConfig(), runtime, stats, ssl_context_manager, - cm.clusterManagerFactory().secretManager(), added_via_api), - dispatcher_(dispatcher), cleanup_interval_ms_(std::chrono::milliseconds( - PROTOBUF_GET_MS_OR_DEFAULT(config, cleanup_interval, 5000))), - cleanup_timer_(dispatcher.createTimer([this]() -> void { cleanup(); })) { + Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : ClusterImplBase(config, runtime, added_via_api, factory_context, std::move(stats_scope)), + dispatcher_(factory_context.dispatcher()), + cleanup_interval_ms_(std::chrono::milliseconds( + PROTOBUF_GET_MS_OR_DEFAULT(config, cleanup_interval, 5000))), + cleanup_timer_(dispatcher_.createTimer([this]() -> void { cleanup(); })) { cleanup_timer_->enableTimer(cleanup_interval_ms_); } diff --git a/source/common/upstream/original_dst_cluster.h b/source/common/upstream/original_dst_cluster.h index 5cb5107a3a4aa..0fece8f9af33d 100644 --- a/source/common/upstream/original_dst_cluster.h +++ b/source/common/upstream/original_dst_cluster.h @@ -6,6 +6,7 @@ #include #include "envoy/secret/secret_manager.h" +#include "envoy/server/transport_socket_config.h" #include "envoy/thread_local/thread_local.h" #include "common/common/empty_string.h" @@ -24,8 +25,9 @@ namespace Upstream { class OriginalDstCluster : public ClusterImplBase { public: OriginalDstCluster(const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - ClusterManager& cm, Event::Dispatcher& dispatcher, bool added_via_api); + bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 0ac8dc532041b..bf3837a103bc9 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -33,6 +33,8 @@ #include "common/upstream/logical_dns_cluster.h" #include "common/upstream/original_dst_cluster.h" +#include "server/transport_socket_config_impl.h" + #include "extensions/transport_sockets/well_known_names.h" namespace Envoy { @@ -265,9 +267,9 @@ ClusterLoadReportStats ClusterInfoImpl::generateLoadReportStats(Stats::Scope& sc ClusterInfoImpl::ClusterInfoImpl(const envoy::api::v2::Cluster& config, const envoy::api::v2::core::BindConfig& bind_config, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, - Secret::SecretManager& secret_manager, bool added_via_api) + Runtime::Loader& runtime, + Network::TransportSocketFactoryPtr&& socket_factory, + Stats::ScopePtr&& stats_scope, bool added_via_api) : runtime_(runtime), name_(config.name()), type_(config.type()), max_requests_per_connection_( PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_requests_per_connection, 0)), @@ -275,43 +277,19 @@ ClusterInfoImpl::ClusterInfoImpl(const envoy::api::v2::Cluster& config, std::chrono::milliseconds(PROTOBUF_GET_MS_REQUIRED(config, connect_timeout))), per_connection_buffer_limit_bytes_( PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, per_connection_buffer_limit_bytes, 1024 * 1024)), - stats_scope_(stats.createScope(fmt::format( - "cluster.{}.", - config.alt_stat_name().empty() ? name_ : std::string(config.alt_stat_name())))), - stats_(generateStats(*stats_scope_)), load_report_stats_(generateLoadReportStats(load_report_stats_store_)), - features_(parseFeatures(config)), + transport_socket_factory_(std::move(socket_factory)), stats_scope_(std::move(stats_scope)), + stats_(generateStats(*stats_scope_)), features_(parseFeatures(config)), http2_settings_(Http::Utility::parseHttp2Settings(config.http2_protocol_options())), resource_managers_(config, runtime, name_), maintenance_mode_runtime_key_(fmt::format("upstream.maintenance_mode.{}", name_)), source_address_(getSourceAddress(config, bind_config)), lb_ring_hash_config_(envoy::api::v2::Cluster::RingHashLbConfig(config.ring_hash_lb_config())), - ssl_context_manager_(ssl_context_manager), added_via_api_(added_via_api), + added_via_api_(added_via_api), lb_subset_(LoadBalancerSubsetInfoImpl(config.lb_subset_config())), metadata_(config.metadata()), common_lb_config_(config.common_lb_config()), cluster_socket_options_(parseClusterSocketOptions(config, bind_config)), - drain_connections_on_host_removal_(config.drain_connections_on_host_removal()), - secret_manager_(secret_manager) { - - // If the cluster doesn't have a transport socket configured, override with the default transport - // socket implementation based on the tls_context. We copy by value first then override if - // necessary. - auto transport_socket = config.transport_socket(); - if (!config.has_transport_socket()) { - if (config.has_tls_context()) { - transport_socket.set_name(Extensions::TransportSockets::TransportSocketNames::get().Tls); - MessageUtil::jsonConvert(config.tls_context(), *transport_socket.mutable_config()); - } else { - transport_socket.set_name( - Extensions::TransportSockets::TransportSocketNames::get().RawBuffer); - } - } - - auto& config_factory = Config::Utility::getAndCheckFactory< - Server::Configuration::UpstreamTransportSocketConfigFactory>(transport_socket.name()); - ProtobufTypes::MessagePtr message = - Config::Utility::translateToFactoryConfig(transport_socket, config_factory); - transport_socket_factory_ = config_factory.createTransportSocketFactory(*message, *this); + drain_connections_on_host_removal_(config.drain_connections_on_host_removal()) { switch (config.lb_policy()) { case envoy::api::v2::Cluster::ROUND_ROBIN: @@ -354,6 +332,39 @@ ClusterInfoImpl::ClusterInfoImpl(const envoy::api::v2::Cluster& config, } } +namespace { + +Stats::ScopePtr generateStatsScope(const envoy::api::v2::Cluster& config, Stats::Store& stats) { + return stats.createScope(fmt::format("cluster.{}.", config.alt_stat_name().empty() + ? config.name() + : std::string(config.alt_stat_name()))); +} + +Network::TransportSocketFactoryPtr createTransportSocketFactory( + const envoy::api::v2::Cluster& config, Server::Configuration::TransportSocketFactoryContext& factory_context) { + // If the cluster config doesn't have a transport socket configured, override with the default + // transport socket implementation based on the tls_context. We copy by value first then override + // if necessary. + auto transport_socket = config.transport_socket(); + if (!config.has_transport_socket()) { + if (config.has_tls_context()) { + transport_socket.set_name(Extensions::TransportSockets::TransportSocketNames::get().Tls); + MessageUtil::jsonConvert(config.tls_context(), *transport_socket.mutable_config()); + } else { + transport_socket.set_name( + Extensions::TransportSockets::TransportSocketNames::get().RawBuffer); + } + } + + auto& config_factory = Config::Utility::getAndCheckFactory< + Server::Configuration::UpstreamTransportSocketConfigFactory>(transport_socket.name()); + ProtobufTypes::MessagePtr message = + Config::Utility::translateToFactoryConfig(transport_socket, config_factory); + return config_factory.createTransportSocketFactory(*message, factory_context); +} + +} // namespace + ClusterSharedPtr ClusterImplBase::create( const envoy::api::v2::Cluster& cluster, ClusterManager& cm, Stats::Store& stats, ThreadLocal::Instance& tls, Network::DnsResolverSharedPtr dns_resolver, @@ -380,20 +391,24 @@ ClusterSharedPtr ClusterImplBase::create( selected_dns_resolver = dispatcher.createDnsResolver(resolvers); } + auto stats_scope = generateStatsScope(cluster, stats); + Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *stats_scope, cm, local_info, dispatcher, random, stats); + switch (cluster.type()) { case envoy::api::v2::Cluster::STATIC: - new_cluster.reset(new StaticClusterImpl(cluster, runtime, stats, ssl_context_manager, - local_info, cm, added_via_api)); + new_cluster.reset(new StaticClusterImpl(cluster, runtime, added_via_api, factory_context, + std::move(stats_scope))); break; case envoy::api::v2::Cluster::STRICT_DNS: - new_cluster.reset(new StrictDnsClusterImpl(cluster, runtime, stats, ssl_context_manager, - local_info, selected_dns_resolver, cm, dispatcher, - added_via_api)); + new_cluster.reset(new StrictDnsClusterImpl(cluster, runtime, selected_dns_resolver, + added_via_api, factory_context, + std::move(stats_scope))); break; case envoy::api::v2::Cluster::LOGICAL_DNS: - new_cluster.reset(new LogicalDnsCluster(cluster, runtime, stats, ssl_context_manager, - local_info, selected_dns_resolver, tls, cm, dispatcher, - added_via_api)); + new_cluster.reset(new LogicalDnsCluster(cluster, runtime, selected_dns_resolver, + tls, added_via_api, factory_context, + std::move(stats_scope))); break; case envoy::api::v2::Cluster::ORIGINAL_DST: if (cluster.lb_policy() != envoy::api::v2::Cluster::ORIGINAL_DST_LB) { @@ -404,8 +419,8 @@ ClusterSharedPtr ClusterImplBase::create( throw EnvoyException(fmt::format( "cluster: cluster type 'original_dst' may not be used with lb_subset_config")); } - new_cluster.reset(new OriginalDstCluster(cluster, runtime, stats, ssl_context_manager, cm, - dispatcher, added_via_api)); + new_cluster.reset(new OriginalDstCluster(cluster, runtime, added_via_api, factory_context, + std::move(stats_scope))); break; case envoy::api::v2::Cluster::EDS: if (!cluster.has_eds_cluster_config()) { @@ -413,8 +428,8 @@ ClusterSharedPtr ClusterImplBase::create( } // We map SDS to EDS, since EDS provides backwards compatibility with SDS. - new_cluster.reset(new EdsClusterImpl(cluster, runtime, stats, ssl_context_manager, local_info, - cm, dispatcher, random, added_via_api)); + new_cluster.reset(new EdsClusterImpl(cluster, runtime, added_via_api, factory_context, + std::move(stats_scope))); break; default: NOT_REACHED_GCOVR_EXCL_LINE; @@ -436,13 +451,14 @@ ClusterSharedPtr ClusterImplBase::create( } ClusterImplBase::ClusterImplBase(const envoy::api::v2::Cluster& cluster, - const envoy::api::v2::core::BindConfig& bind_config, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, - Secret::SecretManager& secret_manager, bool added_via_api) - : runtime_(runtime), - info_(new ClusterInfoImpl(cluster, bind_config, runtime, stats, ssl_context_manager, - secret_manager, added_via_api)) { + Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : runtime_(runtime) { + auto socket_factory = createTransportSocketFactory(cluster, factory_context); + info_ = std::make_unique(cluster, factory_context.clusterManager().bindConfig(), + runtime, std::move(socket_factory), + std::move(stats_scope), added_via_api); // Create the default (empty) priority set before registering callbacks to // avoid getting an update the first time it is accessed. priority_set_.getOrCreateHostSet(0); @@ -768,14 +784,12 @@ void PriorityStateManager::updateClusterPrioritySet( hosts_removed.value_or({})); } -StaticClusterImpl::StaticClusterImpl(const envoy::api::v2::Cluster& cluster, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, ClusterManager& cm, - bool added_via_api) - : ClusterImplBase(cluster, cm.bindConfig(), runtime, stats, ssl_context_manager, - cm.clusterManagerFactory().secretManager(), added_via_api), - priority_state_manager_(new PriorityStateManager(*this, local_info)) { +StaticClusterImpl::StaticClusterImpl( + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : ClusterImplBase(cluster, runtime, added_via_api, factory_context, std::move(stats_scope)), + priority_state_manager_(new PriorityStateManager(*this, factory_context.local_info())) { // TODO(dio): Use by-reference when cluster.hosts() is removed. const envoy::api::v2::ClusterLoadAssignment cluster_load_assignment( cluster.has_load_assignment() ? cluster.load_assignment() @@ -952,16 +966,14 @@ bool BaseDynamicClusterImpl::updateDynamicHostList(const HostVector& new_hosts, } } -StrictDnsClusterImpl::StrictDnsClusterImpl(const envoy::api::v2::Cluster& cluster, - Runtime::Loader& runtime, Stats::Store& stats, - Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, - Network::DnsResolverSharedPtr dns_resolver, - ClusterManager& cm, Event::Dispatcher& dispatcher, - bool added_via_api) - : BaseDynamicClusterImpl(cluster, cm.bindConfig(), runtime, stats, ssl_context_manager, - cm.clusterManagerFactory().secretManager(), added_via_api), - local_info_(local_info), dns_resolver_(dns_resolver), +StrictDnsClusterImpl::StrictDnsClusterImpl( + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, + Network::DnsResolverSharedPtr dns_resolver, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) + : BaseDynamicClusterImpl(cluster, runtime, added_via_api, factory_context, + std::move(stats_scope)), + local_info_(factory_context.local_info()), dns_resolver_(dns_resolver), dns_refresh_rate_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))) { switch (cluster.dns_lookup_family()) { @@ -988,7 +1000,7 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(const envoy::api::v2::Cluster& cluste const std::string& url = fmt::format("tcp://{}:{}", host.socket_address().address(), host.socket_address().port_value()); resolve_targets_.emplace_back( - new ResolveTarget(*this, dispatcher, url, locality_lb_endpoint, lb_endpoint)); + new ResolveTarget(*this, factory_context.dispatcher(), url, locality_lb_endpoint, lb_endpoint)); } } } diff --git a/source/common/upstream/upstream_impl.h b/source/common/upstream/upstream_impl.h index f9b4c4e57cfd4..b4bec3831b127 100644 --- a/source/common/upstream/upstream_impl.h +++ b/source/common/upstream/upstream_impl.h @@ -328,13 +328,12 @@ class PrioritySetImpl : public PrioritySet { /** * Implementation of ClusterInfo that reads from JSON. */ -class ClusterInfoImpl : public ClusterInfo, - public Server::Configuration::TransportSocketFactoryContext { +class ClusterInfoImpl : public ClusterInfo { public: ClusterInfoImpl(const envoy::api::v2::Cluster& config, const envoy::api::v2::core::BindConfig& bind_config, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - Secret::SecretManager& secret_manager, bool added_via_api); + Network::TransportSocketFactoryPtr&& socket_factory, + Stats::ScopePtr&& stats_scope, bool added_via_api); static ClusterStats generateStats(Stats::Scope& scope); static ClusterLoadReportStats generateLoadReportStats(Stats::Scope& scope); @@ -375,17 +374,12 @@ class ClusterInfoImpl : public ClusterInfo, const LoadBalancerSubsetInfo& lbSubsetInfo() const override { return lb_subset_; } const envoy::api::v2::core::Metadata& metadata() const override { return metadata_; } - // Server::Configuration::TransportSocketFactoryContext - Ssl::ContextManager& sslContextManager() override { return ssl_context_manager_; } - const Network::ConnectionSocket::OptionsSharedPtr& clusterSocketOptions() const override { return cluster_socket_options_; }; bool drainConnectionsOnHostRemoval() const override { return drain_connections_on_host_removal_; } - Secret::SecretManager& secretManager() override { return secret_manager_; } - private: struct ResourceManagers { ResourceManagers(const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, @@ -406,11 +400,11 @@ class ClusterInfoImpl : public ClusterInfo, const std::chrono::milliseconds connect_timeout_; absl::optional idle_timeout_; const uint32_t per_connection_buffer_limit_bytes_; - Stats::ScopePtr stats_scope_; - mutable ClusterStats stats_; Stats::IsolatedStoreImpl load_report_stats_store_; mutable ClusterLoadReportStats load_report_stats_; Network::TransportSocketFactoryPtr transport_socket_factory_; + Stats::ScopePtr stats_scope_; + mutable ClusterStats stats_; const uint64_t features_; const Http::Http2Settings http2_settings_; mutable ResourceManagers resource_managers_; @@ -418,14 +412,12 @@ class ClusterInfoImpl : public ClusterInfo, const Network::Address::InstanceConstSharedPtr source_address_; LoadBalancerType lb_type_; absl::optional lb_ring_hash_config_; - Ssl::ContextManager& ssl_context_manager_; const bool added_via_api_; LoadBalancerSubsetInfoImpl lb_subset_; const envoy::api::v2::core::Metadata metadata_; const envoy::api::v2::Cluster::CommonLbConfig common_lb_config_; const Network::ConnectionSocket::OptionsSharedPtr cluster_socket_options_; const bool drain_connections_on_host_removal_; - Secret::SecretManager& secret_manager_; }; /** @@ -479,9 +471,10 @@ class ClusterImplBase : public Cluster, protected Logger::Loggable PriorityStateManagerPtr; class StaticClusterImpl : public ClusterImplBase { public: StaticClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, ClusterManager& cm, bool added_via_api); + bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } @@ -607,10 +601,9 @@ class BaseDynamicClusterImpl : public ClusterImplBase { class StrictDnsClusterImpl : public BaseDynamicClusterImpl { public: StrictDnsClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Stats::Store& stats, Ssl::ContextManager& ssl_context_manager, - const LocalInfo::LocalInfo& local_info, - Network::DnsResolverSharedPtr dns_resolver, ClusterManager& cm, - Event::Dispatcher& dispatcher, bool added_via_api); + Network::DnsResolverSharedPtr dns_resolver, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } diff --git a/source/server/BUILD b/source/server/BUILD index 1f02f4424c4cf..d60b6ae48e923 100644 --- a/source/server/BUILD +++ b/source/server/BUILD @@ -217,6 +217,7 @@ envoy_cc_library( ":drain_manager_lib", ":init_manager_lib", ":lds_api_lib", + ":transport_socket_config_lib", "//include/envoy/server:filter_config_interface", "//include/envoy/server:listener_manager_interface", "//include/envoy/server:transport_socket_config_interface", @@ -349,3 +350,11 @@ envoy_cc_library( "//source/common/common:thread_lib", ], ) + +envoy_cc_library( + name = "transport_socket_config_lib", + hdrs = ["transport_socket_config_impl.h"], + deps = [ + "//include/envoy/server:transport_socket_config_interface", + ], +) diff --git a/source/server/listener_manager_impl.cc b/source/server/listener_manager_impl.cc index 3e3d25bb4f185..d118bc58f4314 100644 --- a/source/server/listener_manager_impl.cc +++ b/source/server/listener_manager_impl.cc @@ -14,6 +14,7 @@ #include "common/network/socket_option_factory.h" #include "common/network/utility.h" #include "common/protobuf/utility.h" +#include "server/transport_socket_config_impl.h" #include "server/configuration_impl.h" #include "server/drain_manager_impl.h" @@ -225,11 +226,14 @@ ListenerImpl::ListenerImpl(const envoy::api::v2::Listener& config, const std::st std::vector application_protocols( filter_chain_match.application_protocols().begin(), filter_chain_match.application_protocols().end()); - + Server::Configuration::TransportSocketFactoryContextImpl factory_context( + parent_.server_.sslContextManager(), *listener_scope_, parent_.server_.clusterManager(), + parent_.server_.localInfo(), parent_.server_.dispatcher(), parent_.server_.random(), + parent_.server_.stats()); addFilterChain(PROTOBUF_GET_WRAPPED_OR_DEFAULT(filter_chain_match, destination_port, 0), destination_ips, server_names, filter_chain_match.transport_protocol(), application_protocols, - config_factory.createTransportSocketFactory(*message, *this, server_names), + config_factory.createTransportSocketFactory(*message, factory_context, server_names), parent_.factory_.createNetworkFilterFactoryList(filter_chain.filters(), *this)); need_tls_inspector |= filter_chain_match.transport_protocol() == "tls" || diff --git a/source/server/listener_manager_impl.h b/source/server/listener_manager_impl.h index 14dfadf30ab58..89193b7def039 100644 --- a/source/server/listener_manager_impl.h +++ b/source/server/listener_manager_impl.h @@ -190,7 +190,6 @@ class ListenerImpl : public Network::ListenerConfig, public Network::DrainDecision, public Network::FilterChainManager, public Network::FilterChainFactory, - public Configuration::TransportSocketFactoryContext, Logger::Loggable { public: /** @@ -301,11 +300,6 @@ class ListenerImpl : public Network::ListenerConfig, const std::vector& factories) override; bool createListenerFilterChain(Network::ListenerFilterManager& manager) override; - // Configuration::TransportSocketFactoryContext - Ssl::ContextManager& sslContextManager() override { return parent_.server_.sslContextManager(); } - Stats::Scope& statsScope() const override { return *listener_scope_; } - Secret::SecretManager& secretManager() override { return parent_.server_.secretManager(); } - SystemTime last_updated_; private: diff --git a/test/common/upstream/eds_test.cc b/test/common/upstream/eds_test.cc index 1d8555da76228..55b0ceb52be94 100644 --- a/test/common/upstream/eds_test.cc +++ b/test/common/upstream/eds_test.cc @@ -9,6 +9,7 @@ #include "test/mocks/local_info/mocks.h" #include "test/mocks/runtime/mocks.h" #include "test/mocks/ssl/mocks.h" +#include "test/mocks/server/mocks.h" #include "test/mocks/upstream/mocks.h" #include "test/test_common/utility.h" @@ -51,8 +52,12 @@ class EdsTest : public testing::Test { EXPECT_CALL(cm_, clusters()).WillOnce(Return(cluster_map)); EXPECT_CALL(cluster, info()).Times(2); EXPECT_CALL(*cluster.info_, addedViaApi()); - cluster_.reset(new EdsClusterImpl(eds_cluster_, runtime_, stats_, ssl_context_manager_, - local_info_, cm_, dispatcher_, random_, false)); + NiceMock factory_context; + Envoy::Stats::ScopePtr scope; + EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm_)); + EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_)); + cluster_.reset( + new EdsClusterImpl(eds_cluster_, runtime_, false, factory_context, std::move(scope))); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); } diff --git a/test/common/upstream/logical_dns_cluster_test.cc b/test/common/upstream/logical_dns_cluster_test.cc index 80a5c7b705fc5..0dae3ea7617b9 100644 --- a/test/common/upstream/logical_dns_cluster_test.cc +++ b/test/common/upstream/logical_dns_cluster_test.cc @@ -15,6 +15,7 @@ #include "test/mocks/ssl/mocks.h" #include "test/mocks/thread_local/mocks.h" #include "test/mocks/upstream/mocks.h" +#include "test/mocks/server/mocks.h" #include "test/test_common/utility.h" #include "gmock/gmock.h" @@ -22,6 +23,7 @@ using testing::Invoke; using testing::NiceMock; +using testing::ReturnRef; using testing::_; namespace Envoy { @@ -34,9 +36,12 @@ class LogicalDnsClusterTest : public testing::Test { void setupFromV1Json(const std::string& json) { resolve_timer_ = new Event::MockTimer(&dispatcher_); NiceMock cm; - cluster_.reset(new LogicalDnsCluster(parseClusterFromJson(json), runtime_, stats_store_, - ssl_context_manager_, local_info_, dns_resolver_, tls_, cm, - dispatcher_, false)); + NiceMock factory_context; + Envoy::Stats::ScopePtr scope; + EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); + EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_store_)); + cluster_.reset(new LogicalDnsCluster(parseClusterFromJson(json), runtime_, dns_resolver_, tls_, + false, factory_context, std::move(scope))); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); diff --git a/test/common/upstream/original_dst_cluster_test.cc b/test/common/upstream/original_dst_cluster_test.cc index 098723c4d0ddc..56cc49cbc2722 100644 --- a/test/common/upstream/original_dst_cluster_test.cc +++ b/test/common/upstream/original_dst_cluster_test.cc @@ -59,8 +59,12 @@ class OriginalDstClusterTest : public testing::Test { void setup(const std::string& json) { NiceMock cm; - cluster_.reset(new OriginalDstCluster(parseClusterFromJson(json), runtime_, stats_store_, - ssl_context_manager_, cm, dispatcher_, false)); + NiceMock factory_context; + Envoy::Stats::ScopePtr scope; + EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); + EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_store_)); + cluster_.reset(new OriginalDstCluster(parseClusterFromJson(json), runtime_, false, + factory_context, std::move(scope))); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); diff --git a/test/common/upstream/sds_test.cc b/test/common/upstream/sds_test.cc index cd01ae7539ccb..3d12f6cb5a1eb 100644 --- a/test/common/upstream/sds_test.cc +++ b/test/common/upstream/sds_test.cc @@ -18,6 +18,7 @@ #include "test/mocks/runtime/mocks.h" #include "test/mocks/ssl/mocks.h" #include "test/mocks/upstream/mocks.h" +#include "test/mocks/server/mocks.h" #include "test/test_common/environment.h" #include "test/test_common/printers.h" #include "test/test_common/utility.h" @@ -30,6 +31,7 @@ using testing::InSequence; using testing::Invoke; using testing::NiceMock; using testing::Return; +using testing::ReturnRef; using testing::SaveArg; using testing::WithArg; using testing::_; @@ -62,8 +64,10 @@ class SdsTest : public testing::Test { EXPECT_CALL(cm_, clusters()).WillOnce(Return(cluster_map)); EXPECT_CALL(cluster, info()).Times(2); EXPECT_CALL(*cluster.info_, addedViaApi()); - cluster_.reset(new EdsClusterImpl(sds_cluster_, runtime_, stats_, ssl_context_manager_, - local_info_, cm_, dispatcher_, random_, false)); + Stats::ScopePtr stats_scope; + EXPECT_CALL(factory_context_, stats()).WillRepeatedly(ReturnRef(stats_)); + cluster_.reset(new EdsClusterImpl(sds_cluster_, runtime_, false, factory_context_, + std::move(stats_scope))); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); } @@ -123,6 +127,7 @@ class SdsTest : public testing::Test { Http::MockAsyncClientRequest request_; NiceMock runtime_; NiceMock local_info_; + NiceMock factory_context_; }; TEST_F(SdsTest, Shutdown) { diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index f4b43c393d2d6..2e831503e7d28 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -20,6 +20,7 @@ #include "test/mocks/local_info/mocks.h" #include "test/mocks/network/mocks.h" #include "test/mocks/runtime/mocks.h" +#include "test/mocks/server/mocks.h" #include "test/mocks/ssl/mocks.h" #include "test/mocks/upstream/mocks.h" #include "test/test_common/utility.h" @@ -30,6 +31,7 @@ using testing::ContainerEq; using testing::Invoke; using testing::NiceMock; +using testing::ReturnRef; using testing::_; namespace Envoy { @@ -142,8 +144,11 @@ TEST_P(StrictDnsParamTest, ImmediateResolve) { return nullptr; })); NiceMock cm; - StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); +StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, dns_resolver, false, + factory_context, std::move(scope)); cluster.initialize([&]() -> void { initialized.ready(); }); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->hosts().size()); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -169,8 +174,10 @@ TEST(StrictDnsClusterImplTest, ZeroHostsHealthChecker) { )EOF"; ResolverData resolver(*dns_resolver, dispatcher); - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, + factory_context, std::move(scope)); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -228,8 +235,11 @@ TEST(StrictDnsClusterImplTest, Basic) { )EOF"; NiceMock cm; - StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); +StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, dns_resolver, false, + factory_context, std::move(scope)); EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); EXPECT_CALL(runtime.snapshot_, @@ -345,8 +355,10 @@ TEST(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) { )EOF"; ResolverData resolver(*dns_resolver, dispatcher); - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, + factory_context, std::move(scope)); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -437,8 +449,11 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasic) { )EOF"; NiceMock cm; - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); +StaticClusterImpl cluster(parseClusterFromJson(json), runtime, false, factory_context, + std::move(scope)); EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); EXPECT_CALL(runtime.snapshot_, @@ -587,9 +602,11 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasicMultiplePriorities) { )EOF"; NiceMock cm; - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); - + NiceMock factory_context; + Envoy::Stats::ScopePtr scope; + EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); + StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, + factory_context, std::move(scope)); ReadyWatcher membership_updated; cluster.prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated.ready(); }); @@ -733,8 +750,11 @@ TEST(StaticClusterImplTest, InitialHosts) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, cm, false); + NiceMock factory_context; + Envoy::Stats::ScopePtr scope; + EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); + StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, false, factory_context, + std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -761,6 +781,11 @@ TEST(StaticClusterImplTest, EmptyHostname) { NiceMock cm; StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, local_info, cm, false); +NiceMock factory_context; +Envoy::Stats::ScopePtr scope; +EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); +StaticClusterImpl cluster(parseClusterFromJson(json), runtime, false, factory_context, + std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 17029e659303f..f214f5d8efa6a 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -411,6 +411,12 @@ class MockTransportSocketFactoryContext : public TransportSocketFactoryContext { MOCK_METHOD0(sslContextManager, Ssl::ContextManager&()); MOCK_CONST_METHOD0(statsScope, Stats::Scope&()); + MOCK_METHOD0(clusterManager, Upstream::ClusterManager&()); + MOCK_METHOD0(secretManager, Secret::SecretManager&()); + MOCK_METHOD0(local_info, const LocalInfo::LocalInfo&()); + MOCK_METHOD0(dispatcher, Event::Dispatcher&()); + MOCK_METHOD0(random, Envoy::Runtime::RandomGenerator&()); + MOCK_METHOD0(stats, Stats::Store&()); }; class MockListenerFactoryContext : public virtual MockFactoryContext, diff --git a/tools/protodoc/protodoc.bzl b/tools/protodoc/protodoc.bzl index c7ab5c8948890..4b11e8ef34573 100644 --- a/tools/protodoc/protodoc.bzl +++ b/tools/protodoc/protodoc.bzl @@ -78,7 +78,6 @@ def _proto_doc_aspect_impl(target, ctx): return [OutputGroupInfo(rst = transitive_outputs)] proto_doc_aspect = aspect( - implementation = _proto_doc_aspect_impl, attr_aspects = ["deps"], attrs = { "_protoc": attr.label( @@ -92,4 +91,5 @@ proto_doc_aspect = aspect( cfg = "host", ), }, + implementation = _proto_doc_aspect_impl, ) From 0d0b35f22743ce44bd1cd2cc1959494d9b33e5f5 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Tue, 31 Jul 2018 16:54:03 -0700 Subject: [PATCH 2/8] add transport_socket_config_impl.h Signed-off-by: JimmyCYJ --- source/server/transport_socket_config_impl.h | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 source/server/transport_socket_config_impl.h diff --git a/source/server/transport_socket_config_impl.h b/source/server/transport_socket_config_impl.h new file mode 100644 index 0000000000000..22c4fec97e68c --- /dev/null +++ b/source/server/transport_socket_config_impl.h @@ -0,0 +1,52 @@ +#pragma once + +#include "envoy/server/transport_socket_config.h" + +namespace Envoy { +namespace Server { +namespace Configuration { + +/** + * Implementation of TransportSocketFactoryContext. + */ +class TransportSocketFactoryContextImpl : public TransportSocketFactoryContext { + public: + TransportSocketFactoryContextImpl(Ssl::ContextManager& context_manager, Stats::Scope& stats_scope, + Upstream::ClusterManager& cm, + const LocalInfo::LocalInfo& local_info, + Event::Dispatcher& dispatcher, + Envoy::Runtime::RandomGenerator& random, Stats::Store& stats) + : context_manager_(context_manager), stats_scope_(stats_scope), cluster_manager_(cm), + local_info_(local_info), dispatcher_(dispatcher), random_(random), stats_(stats) {} + + Ssl::ContextManager& sslContextManager() override { return context_manager_; } + + Stats::Scope& statsScope() const override { return stats_scope_; } + + Upstream::ClusterManager& clusterManager() override { return cluster_manager_; } + + Secret::SecretManager& secretManager() override { + return cluster_manager_.clusterManagerFactory().secretManager(); + } + + const LocalInfo::LocalInfo& local_info() override { return local_info_; } + + Event::Dispatcher& dispatcher() override { return dispatcher_; } + + Envoy::Runtime::RandomGenerator& random() override { return random_; } + + Stats::Store& stats() override { return stats_; } + + private: + Ssl::ContextManager& context_manager_; + Stats::Scope& stats_scope_; + Upstream::ClusterManager& cluster_manager_; + const LocalInfo::LocalInfo& local_info_; + Event::Dispatcher& dispatcher_; + Envoy::Runtime::RandomGenerator& random_; + Stats::Store& stats_; +}; + +} // namespace Configuration +} // namespace Server +} // namespace Envoy \ No newline at end of file From 9b2d9ab932df29afd1bc0e146149543dad7cd3d2 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Wed, 1 Aug 2018 15:02:48 -0700 Subject: [PATCH 3/8] Fix all tests. Signed-off-by: JimmyCYJ --- source/common/upstream/logical_dns_cluster.cc | 4 +- .../common/upstream/original_dst_cluster.cc | 12 +- source/common/upstream/upstream_impl.cc | 23 +- source/common/upstream/upstream_impl.h | 3 +- source/server/BUILD | 10 +- source/server/listener_manager_impl.cc | 12 +- source/server/transport_socket_config_impl.h | 4 +- test/common/upstream/BUILD | 6 + test/common/upstream/eds_test.cc | 13 +- .../upstream/logical_dns_cluster_test.cc | 31 +- .../upstream/original_dst_cluster_test.cc | 20 +- test/common/upstream/sds_test.cc | 16 +- test/common/upstream/upstream_impl_test.cc | 311 +++++++++++++----- 13 files changed, 327 insertions(+), 138 deletions(-) diff --git a/source/common/upstream/logical_dns_cluster.cc b/source/common/upstream/logical_dns_cluster.cc index cf1fdcc29149d..9a30051fd8695 100644 --- a/source/common/upstream/logical_dns_cluster.cc +++ b/source/common/upstream/logical_dns_cluster.cc @@ -24,8 +24,8 @@ LogicalDnsCluster::LogicalDnsCluster( dns_resolver_(dns_resolver), dns_refresh_rate_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))), - tls_(tls.allocateSlot()), - resolve_timer_(factory_context.dispatcher().createTimer([this]() -> void { startResolve(); })), + tls_(tls.allocateSlot()), resolve_timer_(factory_context.dispatcher().createTimer( + [this]() -> void { startResolve(); })), local_info_(factory_context.local_info()), load_assignment_(cluster.has_load_assignment() ? cluster.load_assignment() diff --git a/source/common/upstream/original_dst_cluster.cc b/source/common/upstream/original_dst_cluster.cc index f3598e31ccba7..3db1e00b80c22 100644 --- a/source/common/upstream/original_dst_cluster.cc +++ b/source/common/upstream/original_dst_cluster.cc @@ -122,14 +122,14 @@ OriginalDstCluster::LoadBalancer::requestOverrideHost(LoadBalancerContext* conte return request_host; } -OriginalDstCluster::OriginalDstCluster(const envoy::api::v2::Cluster& config, - Runtime::Loader& runtime, bool added_via_api, - Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) +OriginalDstCluster::OriginalDstCluster( + const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) : ClusterImplBase(config, runtime, added_via_api, factory_context, std::move(stats_scope)), dispatcher_(factory_context.dispatcher()), - cleanup_interval_ms_(std::chrono::milliseconds( - PROTOBUF_GET_MS_OR_DEFAULT(config, cleanup_interval, 5000))), + cleanup_interval_ms_( + std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(config, cleanup_interval, 5000))), cleanup_timer_(dispatcher_.createTimer([this]() -> void { cleanup(); })) { cleanup_timer_->enableTimer(cleanup_interval_ms_); diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index bf3837a103bc9..628b171dfadd3 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -336,12 +336,13 @@ namespace { Stats::ScopePtr generateStatsScope(const envoy::api::v2::Cluster& config, Stats::Store& stats) { return stats.createScope(fmt::format("cluster.{}.", config.alt_stat_name().empty() - ? config.name() - : std::string(config.alt_stat_name()))); + ? config.name() + : std::string(config.alt_stat_name()))); } Network::TransportSocketFactoryPtr createTransportSocketFactory( - const envoy::api::v2::Cluster& config, Server::Configuration::TransportSocketFactoryContext& factory_context) { + const envoy::api::v2::Cluster& config, + Server::Configuration::TransportSocketFactoryContext& factory_context) { // If the cluster config doesn't have a transport socket configured, override with the default // transport socket implementation based on the tls_context. We copy by value first then override // if necessary. @@ -406,8 +407,8 @@ ClusterSharedPtr ClusterImplBase::create( std::move(stats_scope))); break; case envoy::api::v2::Cluster::LOGICAL_DNS: - new_cluster.reset(new LogicalDnsCluster(cluster, runtime, selected_dns_resolver, - tls, added_via_api, factory_context, + new_cluster.reset(new LogicalDnsCluster(cluster, runtime, selected_dns_resolver, tls, + added_via_api, factory_context, std::move(stats_scope))); break; case envoy::api::v2::Cluster::ORIGINAL_DST: @@ -450,10 +451,10 @@ ClusterSharedPtr ClusterImplBase::create( return std::move(new_cluster); } -ClusterImplBase::ClusterImplBase(const envoy::api::v2::Cluster& cluster, - Runtime::Loader& runtime, bool added_via_api, - Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) +ClusterImplBase::ClusterImplBase( + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + Server::Configuration::TransportSocketFactoryContext& factory_context, + Stats::ScopePtr stats_scope) : runtime_(runtime) { auto socket_factory = createTransportSocketFactory(cluster, factory_context); info_ = std::make_unique(cluster, factory_context.clusterManager().bindConfig(), @@ -999,8 +1000,8 @@ StrictDnsClusterImpl::StrictDnsClusterImpl( const auto& host = lb_endpoint.endpoint().address(); const std::string& url = fmt::format("tcp://{}:{}", host.socket_address().address(), host.socket_address().port_value()); - resolve_targets_.emplace_back( - new ResolveTarget(*this, factory_context.dispatcher(), url, locality_lb_endpoint, lb_endpoint)); + resolve_targets_.emplace_back(new ResolveTarget(*this, factory_context.dispatcher(), url, + locality_lb_endpoint, lb_endpoint)); } } } diff --git a/source/common/upstream/upstream_impl.h b/source/common/upstream/upstream_impl.h index b4bec3831b127..2cd7537272b8d 100644 --- a/source/common/upstream/upstream_impl.h +++ b/source/common/upstream/upstream_impl.h @@ -470,8 +470,7 @@ class ClusterImplBase : public Cluster, protected Logger::Loggable callback) override; protected: - ClusterImplBase(const envoy::api::v2::Cluster& cluster, - Runtime::Loader& runtime, + ClusterImplBase(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, Server::Configuration::TransportSocketFactoryContext& factory_context, Stats::ScopePtr stats_scope); diff --git a/source/server/BUILD b/source/server/BUILD index d60b6ae48e923..130b048592a22 100644 --- a/source/server/BUILD +++ b/source/server/BUILD @@ -352,9 +352,9 @@ envoy_cc_library( ) envoy_cc_library( - name = "transport_socket_config_lib", - hdrs = ["transport_socket_config_impl.h"], - deps = [ - "//include/envoy/server:transport_socket_config_interface", - ], + name = "transport_socket_config_lib", + hdrs = ["transport_socket_config_impl.h"], + deps = [ + "//include/envoy/server:transport_socket_config_interface", + ], ) diff --git a/source/server/listener_manager_impl.cc b/source/server/listener_manager_impl.cc index d118bc58f4314..5008eaafe462b 100644 --- a/source/server/listener_manager_impl.cc +++ b/source/server/listener_manager_impl.cc @@ -14,10 +14,10 @@ #include "common/network/socket_option_factory.h" #include "common/network/utility.h" #include "common/protobuf/utility.h" -#include "server/transport_socket_config_impl.h" #include "server/configuration_impl.h" #include "server/drain_manager_impl.h" +#include "server/transport_socket_config_impl.h" #include "extensions/filters/listener/well_known_names.h" #include "extensions/filters/network/well_known_names.h" @@ -230,11 +230,11 @@ ListenerImpl::ListenerImpl(const envoy::api::v2::Listener& config, const std::st parent_.server_.sslContextManager(), *listener_scope_, parent_.server_.clusterManager(), parent_.server_.localInfo(), parent_.server_.dispatcher(), parent_.server_.random(), parent_.server_.stats()); - addFilterChain(PROTOBUF_GET_WRAPPED_OR_DEFAULT(filter_chain_match, destination_port, 0), - destination_ips, server_names, filter_chain_match.transport_protocol(), - application_protocols, - config_factory.createTransportSocketFactory(*message, factory_context, server_names), - parent_.factory_.createNetworkFilterFactoryList(filter_chain.filters(), *this)); + addFilterChain( + PROTOBUF_GET_WRAPPED_OR_DEFAULT(filter_chain_match, destination_port, 0), destination_ips, + server_names, filter_chain_match.transport_protocol(), application_protocols, + config_factory.createTransportSocketFactory(*message, factory_context, server_names), + parent_.factory_.createNetworkFilterFactoryList(filter_chain.filters(), *this)); need_tls_inspector |= filter_chain_match.transport_protocol() == "tls" || (filter_chain_match.transport_protocol().empty() && diff --git a/source/server/transport_socket_config_impl.h b/source/server/transport_socket_config_impl.h index 22c4fec97e68c..bda630b8c5341 100644 --- a/source/server/transport_socket_config_impl.h +++ b/source/server/transport_socket_config_impl.h @@ -10,7 +10,7 @@ namespace Configuration { * Implementation of TransportSocketFactoryContext. */ class TransportSocketFactoryContextImpl : public TransportSocketFactoryContext { - public: +public: TransportSocketFactoryContextImpl(Ssl::ContextManager& context_manager, Stats::Scope& stats_scope, Upstream::ClusterManager& cm, const LocalInfo::LocalInfo& local_info, @@ -37,7 +37,7 @@ class TransportSocketFactoryContextImpl : public TransportSocketFactoryContext { Stats::Store& stats() override { return stats_; } - private: +private: Ssl::ContextManager& context_manager_; Stats::Scope& stats_scope_; Upstream::ClusterManager& cluster_manager_; diff --git a/test/common/upstream/BUILD b/test/common/upstream/BUILD index 441ce2437613f..789dd66c28a1a 100644 --- a/test/common/upstream/BUILD +++ b/test/common/upstream/BUILD @@ -71,6 +71,7 @@ envoy_cc_test( "//source/common/config:utility_lib", "//source/common/upstream:eds_lib", "//source/extensions/transport_sockets/raw_buffer:config", + "//source/server:transport_socket_config_lib", "//test/mocks/local_info:local_info_mocks", "//test/mocks/runtime:runtime_mocks", "//test/mocks/ssl:ssl_mocks", @@ -171,6 +172,7 @@ envoy_cc_test( "//source/common/upstream:logical_dns_cluster_lib", "//source/common/upstream:upstream_lib", "//source/extensions/transport_sockets/raw_buffer:config", + "//source/server:transport_socket_config_lib", "//test/mocks:common_lib", "//test/mocks/local_info:local_info_mocks", "//test/mocks/network:network_mocks", @@ -193,8 +195,10 @@ envoy_cc_test( "//source/common/upstream:upstream_lib", "//source/extensions/transport_sockets/raw_buffer:config", "//test/mocks:common_lib", + "//test/mocks/local_info:local_info_mocks", "//test/mocks/network:network_mocks", "//test/mocks/runtime:runtime_mocks", + "//test/mocks/server:server_mocks", "//test/mocks/ssl:ssl_mocks", "//test/mocks/upstream:upstream_mocks", "//test/test_common:utility_lib", @@ -282,6 +286,7 @@ envoy_cc_test( "//source/common/network:utility_lib", "//source/common/upstream:eds_lib", "//source/extensions/transport_sockets/raw_buffer:config", + "//source/server:transport_socket_config_lib", "//test/mocks/local_info:local_info_mocks", "//test/mocks/runtime:runtime_mocks", "//test/mocks/ssl:ssl_mocks", @@ -326,6 +331,7 @@ envoy_cc_test( "//source/common/upstream:upstream_includes", "//source/common/upstream:upstream_lib", "//source/extensions/transport_sockets/raw_buffer:config", + "//source/server:transport_socket_config_lib", "//test/mocks:common_lib", "//test/mocks/local_info:local_info_mocks", "//test/mocks/network:network_mocks", diff --git a/test/common/upstream/eds_test.cc b/test/common/upstream/eds_test.cc index 55b0ceb52be94..6dcfa979dd920 100644 --- a/test/common/upstream/eds_test.cc +++ b/test/common/upstream/eds_test.cc @@ -5,11 +5,12 @@ #include "common/config/utility.h" #include "common/upstream/eds.h" +#include "server/transport_socket_config_impl.h" + #include "test/common/upstream/utility.h" #include "test/mocks/local_info/mocks.h" #include "test/mocks/runtime/mocks.h" #include "test/mocks/ssl/mocks.h" -#include "test/mocks/server/mocks.h" #include "test/mocks/upstream/mocks.h" #include "test/test_common/utility.h" @@ -52,10 +53,12 @@ class EdsTest : public testing::Test { EXPECT_CALL(cm_, clusters()).WillOnce(Return(cluster_map)); EXPECT_CALL(cluster, info()).Times(2); EXPECT_CALL(*cluster.info_, addedViaApi()); - NiceMock factory_context; - Envoy::Stats::ScopePtr scope; - EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm_)); - EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_)); + Envoy::Stats::ScopePtr scope = stats_.createScope( + fmt::format("cluster.{}.", eds_cluster_.alt_stat_name().empty() + ? eds_cluster_.name() + : std::string(eds_cluster_.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager_, *scope, cm_, local_info_, dispatcher_, random_, stats_); cluster_.reset( new EdsClusterImpl(eds_cluster_, runtime_, false, factory_context, std::move(scope))); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); diff --git a/test/common/upstream/logical_dns_cluster_test.cc b/test/common/upstream/logical_dns_cluster_test.cc index 0dae3ea7617b9..4264e530a1230 100644 --- a/test/common/upstream/logical_dns_cluster_test.cc +++ b/test/common/upstream/logical_dns_cluster_test.cc @@ -7,6 +7,8 @@ #include "common/network/utility.h" #include "common/upstream/logical_dns_cluster.h" +#include "server/transport_socket_config_impl.h" + #include "test/common/upstream/utility.h" #include "test/mocks/common.h" #include "test/mocks/local_info/mocks.h" @@ -15,7 +17,6 @@ #include "test/mocks/ssl/mocks.h" #include "test/mocks/thread_local/mocks.h" #include "test/mocks/upstream/mocks.h" -#include "test/mocks/server/mocks.h" #include "test/test_common/utility.h" #include "gmock/gmock.h" @@ -36,12 +37,15 @@ class LogicalDnsClusterTest : public testing::Test { void setupFromV1Json(const std::string& json) { resolve_timer_ = new Event::MockTimer(&dispatcher_); NiceMock cm; - NiceMock factory_context; - Envoy::Stats::ScopePtr scope; - EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); - EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_store_)); - cluster_.reset(new LogicalDnsCluster(parseClusterFromJson(json), runtime_, dns_resolver_, tls_, - false, factory_context, std::move(scope))); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats_store_.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); + cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, false, + factory_context, std::move(scope))); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); @@ -52,9 +56,15 @@ class LogicalDnsClusterTest : public testing::Test { void setupFromV2Yaml(const std::string& yaml) { resolve_timer_ = new Event::MockTimer(&dispatcher_); NiceMock cm; - cluster_.reset(new LogicalDnsCluster(parseClusterFromV2Yaml(yaml), runtime_, stats_store_, - ssl_context_manager_, local_info_, dns_resolver_, tls_, cm, - dispatcher_, false)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats_store_.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); + cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, false, + factory_context, std::move(scope))); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); @@ -173,6 +183,7 @@ class LogicalDnsClusterTest : public testing::Test { std::shared_ptr> dns_resolver_{ new NiceMock}; Network::MockActiveDnsQuery active_dns_query_; + NiceMock random_; Network::DnsResolver::ResolveCb dns_callback_; NiceMock tls_; Event::MockTimer* resolve_timer_; diff --git a/test/common/upstream/original_dst_cluster_test.cc b/test/common/upstream/original_dst_cluster_test.cc index 56cc49cbc2722..63749ec3069eb 100644 --- a/test/common/upstream/original_dst_cluster_test.cc +++ b/test/common/upstream/original_dst_cluster_test.cc @@ -9,8 +9,11 @@ #include "common/upstream/original_dst_cluster.h" #include "common/upstream/upstream_impl.h" +#include "server/transport_socket_config_impl.h" + #include "test/common/upstream/utility.h" #include "test/mocks/common.h" +#include "test/mocks/local_info/mocks.h" #include "test/mocks/network/mocks.h" #include "test/mocks/runtime/mocks.h" #include "test/mocks/ssl/mocks.h" @@ -59,12 +62,15 @@ class OriginalDstClusterTest : public testing::Test { void setup(const std::string& json) { NiceMock cm; - NiceMock factory_context; - Envoy::Stats::ScopePtr scope; - EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); - EXPECT_CALL(factory_context, stats()).WillRepeatedly(ReturnRef(stats_store_)); - cluster_.reset(new OriginalDstCluster(parseClusterFromJson(json), runtime_, false, - factory_context, std::move(scope))); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats_store_.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); + cluster_.reset( + new OriginalDstCluster(cluster_config, runtime_, false, factory_context, std::move(scope))); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); @@ -80,6 +86,8 @@ class OriginalDstClusterTest : public testing::Test { NiceMock runtime_; NiceMock dispatcher_; Event::MockTimer* cleanup_timer_; + NiceMock random_; + NiceMock local_info_; }; TEST(OriginalDstClusterConfigTest, BadConfig) { diff --git a/test/common/upstream/sds_test.cc b/test/common/upstream/sds_test.cc index 3d12f6cb5a1eb..d8bbdf8b22bed 100644 --- a/test/common/upstream/sds_test.cc +++ b/test/common/upstream/sds_test.cc @@ -13,12 +13,13 @@ #include "common/protobuf/protobuf.h" #include "common/upstream/eds.h" +#include "server/transport_socket_config_impl.h" + #include "test/common/upstream/utility.h" #include "test/mocks/local_info/mocks.h" #include "test/mocks/runtime/mocks.h" #include "test/mocks/ssl/mocks.h" #include "test/mocks/upstream/mocks.h" -#include "test/mocks/server/mocks.h" #include "test/test_common/environment.h" #include "test/test_common/printers.h" #include "test/test_common/utility.h" @@ -64,10 +65,14 @@ class SdsTest : public testing::Test { EXPECT_CALL(cm_, clusters()).WillOnce(Return(cluster_map)); EXPECT_CALL(cluster, info()).Times(2); EXPECT_CALL(*cluster.info_, addedViaApi()); - Stats::ScopePtr stats_scope; - EXPECT_CALL(factory_context_, stats()).WillRepeatedly(ReturnRef(stats_)); - cluster_.reset(new EdsClusterImpl(sds_cluster_, runtime_, false, factory_context_, - std::move(stats_scope))); + Envoy::Stats::ScopePtr scope = stats_.createScope( + fmt::format("cluster.{}.", sds_cluster_.alt_stat_name().empty() + ? sds_cluster_.name() + : std::string(sds_cluster_.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager_, *scope, cm_, local_info_, dispatcher_, random_, stats_); + cluster_.reset( + new EdsClusterImpl(sds_cluster_, runtime_, false, factory_context, std::move(scope))); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); } @@ -127,7 +132,6 @@ class SdsTest : public testing::Test { Http::MockAsyncClientRequest request_; NiceMock runtime_; NiceMock local_info_; - NiceMock factory_context_; }; TEST_F(SdsTest, Shutdown) { diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index 2e831503e7d28..57da5c4426434 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -15,12 +15,13 @@ #include "common/network/utility.h" #include "common/upstream/upstream_impl.h" +#include "server/transport_socket_config_impl.h" + #include "test/common/upstream/utility.h" #include "test/mocks/common.h" #include "test/mocks/local_info/mocks.h" #include "test/mocks/network/mocks.h" #include "test/mocks/runtime/mocks.h" -#include "test/mocks/server/mocks.h" #include "test/mocks/ssl/mocks.h" #include "test/mocks/upstream/mocks.h" #include "test/test_common/utility.h" @@ -124,7 +125,7 @@ TEST_P(StrictDnsParamTest, ImmediateResolve) { NiceMock runtime; NiceMock local_info; ReadyWatcher initialized; - + NiceMock random; const std::string json = R"EOF( { "name": "name", @@ -144,11 +145,16 @@ TEST_P(StrictDnsParamTest, ImmediateResolve) { return nullptr; })); NiceMock cm; -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); -StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, dns_resolver, false, - factory_context, std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); cluster.initialize([&]() -> void { initialized.ready(); }); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->hosts().size()); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -163,6 +169,7 @@ TEST(StrictDnsClusterImplTest, ZeroHostsHealthChecker) { NiceMock runtime; NiceMock cm; NiceMock local_info; + NiceMock random; ReadyWatcher initialized; const std::string yaml = R"EOF( @@ -174,10 +181,15 @@ TEST(StrictDnsClusterImplTest, ZeroHostsHealthChecker) { )EOF"; ResolverData resolver(*dns_resolver, dispatcher); -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, - factory_context, std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -199,7 +211,7 @@ TEST(StrictDnsClusterImplTest, Basic) { NiceMock dispatcher; NiceMock runtime; NiceMock local_info; - + NiceMock random; // gmock matches in LIFO order which is why these are swapped. ResolverData resolver2(*dns_resolver, dispatcher); ResolverData resolver1(*dns_resolver, dispatcher); @@ -235,11 +247,15 @@ TEST(StrictDnsClusterImplTest, Basic) { )EOF"; NiceMock cm; -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); -StrictDnsClusterImpl cluster(parseClusterFromJson(json), runtime, dns_resolver, false, - factory_context, std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); EXPECT_CALL(runtime.snapshot_, @@ -344,6 +360,7 @@ TEST(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) { NiceMock runtime; NiceMock cm; NiceMock local_info; + NiceMock random; const std::string yaml = R"EOF( name: name @@ -355,10 +372,15 @@ TEST(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) { )EOF"; ResolverData resolver(*dns_resolver, dispatcher); -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, - factory_context, std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -396,7 +418,7 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasic) { NiceMock dispatcher; NiceMock runtime; NiceMock local_info; - + NiceMock random; // gmock matches in LIFO order which is why these are swapped. ResolverData resolver2(*dns_resolver, dispatcher); ResolverData resolver1(*dns_resolver, dispatcher); @@ -449,11 +471,16 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasic) { )EOF"; NiceMock cm; -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); -StaticClusterImpl cluster(parseClusterFromJson(json), runtime, false, factory_context, - std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); + EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); EXPECT_CALL(runtime.snapshot_, @@ -555,7 +582,7 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasicMultiplePriorities) { NiceMock dispatcher; NiceMock runtime; NiceMock local_info; - + NiceMock random; // gmock matches in LIFO order which is why these are swapped. ResolverData resolver3(*dns_resolver, dispatcher); ResolverData resolver2(*dns_resolver, dispatcher); @@ -602,11 +629,15 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasicMultiplePriorities) { )EOF"; NiceMock cm; - NiceMock factory_context; - Envoy::Stats::ScopePtr scope; - EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, dns_resolver, false, - factory_context, std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); ReadyWatcher membership_updated; cluster.prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated.ready(); }); @@ -736,8 +767,11 @@ TEST(HostImplTest, HostnameCanaryAndLocality) { TEST(StaticClusterImplTest, InitialHosts) { Stats::IsolatedStoreImpl stats; Ssl::MockContextManager ssl_context_manager; + NiceMock dispatcher; NiceMock runtime; NiceMock local_info; + NiceMock random; + const std::string yaml = R"EOF( name: staticcluster connect_timeout: 0.25s @@ -750,11 +784,14 @@ TEST(StaticClusterImplTest, InitialHosts) { )EOF"; NiceMock cm; - NiceMock factory_context; - Envoy::Stats::ScopePtr scope; - EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, false, factory_context, - std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -767,6 +804,8 @@ TEST(StaticClusterImplTest, EmptyHostname) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string json = R"EOF( { @@ -779,13 +818,14 @@ TEST(StaticClusterImplTest, EmptyHostname) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, false); -NiceMock factory_context; -Envoy::Stats::ScopePtr scope; -EXPECT_CALL(factory_context, clusterManager()).WillRepeatedly(ReturnRef(cm)); -StaticClusterImpl cluster(parseClusterFromJson(json), runtime, false, factory_context, - std::move(scope)); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -796,9 +836,10 @@ StaticClusterImpl cluster(parseClusterFromJson(json), runtime, false, factory_co TEST(StaticClusterImplTest, LoadAssignmentEmptyHostname) { Stats::IsolatedStoreImpl stats; Ssl::MockContextManager ssl_context_manager; + NiceMock dispatcher; NiceMock runtime; NiceMock local_info; - + NiceMock random; const std::string yaml = R"EOF( name: staticcluster connect_timeout: 0.25s @@ -817,8 +858,14 @@ TEST(StaticClusterImplTest, LoadAssignmentEmptyHostname) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -831,6 +878,8 @@ TEST(StaticClusterImplTest, LoadAssignmentMultiplePriorities) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string yaml = R"EOF( name: staticcluster @@ -868,8 +917,14 @@ TEST(StaticClusterImplTest, LoadAssignmentMultiplePriorities) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -883,6 +938,8 @@ TEST(StaticClusterImplTest, LoadAssignmentLocality) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string yaml = R"EOF( name: staticcluster @@ -913,8 +970,14 @@ TEST(StaticClusterImplTest, LoadAssignmentLocality) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); auto& hosts = cluster.prioritySet().hostSetsPerPriority()[0]->hosts(); @@ -934,6 +997,8 @@ TEST(StaticClusterImplTest, AltStatName) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock random; + NiceMock dispatcher; const std::string yaml = R"EOF( name: staticcluster @@ -945,8 +1010,14 @@ TEST(StaticClusterImplTest, AltStatName) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); // Increment a stat and verify it is emitted with alt_stat_name cluster.info()->stats().upstream_rq_total_.inc(); @@ -958,6 +1029,8 @@ TEST(StaticClusterImplTest, RingHash) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string json = R"EOF( { @@ -970,8 +1043,14 @@ TEST(StaticClusterImplTest, RingHash) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, true); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, true, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -984,6 +1063,8 @@ TEST(StaticClusterImplTest, OutlierDetector) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock random; + NiceMock dispatcher; const std::string json = R"EOF( { @@ -997,8 +1078,14 @@ TEST(StaticClusterImplTest, OutlierDetector) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); Outlier::MockDetector* detector = new Outlier::MockDetector(); EXPECT_CALL(*detector, addChangedStateCb(_)); @@ -1033,6 +1120,8 @@ TEST(StaticClusterImplTest, HealthyStat) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string json = R"EOF( { @@ -1046,8 +1135,14 @@ TEST(StaticClusterImplTest, HealthyStat) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); Outlier::MockDetector* outlier_detector = new NiceMock(); cluster.setOutlierDetector(Outlier::DetectorSharedPtr{outlier_detector}); @@ -1117,6 +1212,8 @@ TEST(StaticClusterImplTest, UrlConfig) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string json = R"EOF( { @@ -1130,8 +1227,14 @@ TEST(StaticClusterImplTest, UrlConfig) { )EOF"; NiceMock cm; - StaticClusterImpl cluster(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); cluster.initialize([] {}); EXPECT_EQ(1024U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); @@ -1163,6 +1266,8 @@ TEST(StaticClusterImplTest, UnsupportedLBType) { NiceMock runtime; NiceMock cm; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string json = R"EOF( { @@ -1175,9 +1280,18 @@ TEST(StaticClusterImplTest, UnsupportedLBType) { } )EOF"; - EXPECT_THROW(StaticClusterImpl(parseClusterFromJson(json), runtime, stats, ssl_context_manager, - local_info, cm, false), - EnvoyException); + EXPECT_THROW( + { + envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl(cluster_config, runtime, false, factory_context, std::move(scope)); + }, + EnvoyException); } TEST(StaticClusterImplTest, MalformedHostIP) { @@ -1185,6 +1299,8 @@ TEST(StaticClusterImplTest, MalformedHostIP) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; const std::string yaml = R"EOF( name: name @@ -1195,11 +1311,18 @@ TEST(StaticClusterImplTest, MalformedHostIP) { )EOF"; NiceMock cm; - EXPECT_THROW_WITH_MESSAGE(StaticClusterImpl(parseClusterFromV2Yaml(yaml), runtime, stats, - ssl_context_manager, local_info, cm, false), - EnvoyException, - "malformed IP address: foo.bar.com. Consider setting resolver_name or " - "setting cluster type to 'STRICT_DNS' or 'LOGICAL_DNS'"); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + EXPECT_THROW_WITH_MESSAGE( + StaticClusterImpl(cluster_config, runtime, false, factory_context, std::move(scope)), + EnvoyException, + "malformed IP address: foo.bar.com. Consider setting resolver_name or " + "setting cluster type to 'STRICT_DNS' or 'LOGICAL_DNS'"); } TEST(ClusterDefinitionTest, BadClusterConfig) { @@ -1239,6 +1362,8 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { Ssl::MockContextManager ssl_context_manager; NiceMock runtime; NiceMock local_info; + NiceMock dispatcher; + NiceMock random; envoy::api::v2::Cluster config; config.set_name("staticcluster"); @@ -1248,7 +1373,12 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { // If the cluster manager gets a source address from the bootstrap proto, use it. NiceMock cm; cm.bind_config_.mutable_source_address()->set_address("1.2.3.5"); - StaticClusterImpl cluster(config, runtime, stats, ssl_context_manager, local_info, cm, false); + Envoy::Stats::ScopePtr scope = stats.createScope(fmt::format( + "cluster.{}.", + config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); EXPECT_EQ("1.2.3.5:0", cluster.info()->sourceAddress()->asString()); } @@ -1257,7 +1387,12 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { { // Verify source address from cluster config is used when present. NiceMock cm; - StaticClusterImpl cluster(config, runtime, stats, ssl_context_manager, local_info, cm, false); + Envoy::Stats::ScopePtr scope = stats.createScope(fmt::format( + "cluster.{}.", + config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); EXPECT_EQ(cluster_address, cluster.info()->sourceAddress()->ip()->addressAsString()); } @@ -1265,7 +1400,12 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { // The source address from cluster config takes precedence over one from the bootstrap proto. NiceMock cm; cm.bind_config_.mutable_source_address()->set_address("1.2.3.5"); - StaticClusterImpl cluster(config, runtime, stats, ssl_context_manager, local_info, cm, false); + Envoy::Stats::ScopePtr scope = stats.createScope(fmt::format( + "cluster.{}.", + config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); EXPECT_EQ(cluster_address, cluster.info()->sourceAddress()->ip()->addressAsString()); } } @@ -1280,6 +1420,7 @@ TEST(ClusterImplTest, CloseConnectionsOnHostHealthFailure) { NiceMock runtime; NiceMock cm; NiceMock local_info; + NiceMock random; ReadyWatcher initialized; const std::string yaml = R"EOF( @@ -1290,8 +1431,16 @@ TEST(ClusterImplTest, CloseConnectionsOnHostHealthFailure) { close_connections_on_host_health_failure: true hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] )EOF"; - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); EXPECT_TRUE(cluster.info()->features() & ClusterInfo::Features::CLOSE_CONNECTIONS_ON_HOST_HEALTH_FAILURE); } @@ -1354,6 +1503,7 @@ TEST(ClusterMetadataTest, Metadata) { NiceMock runtime; NiceMock cm; NiceMock local_info; + NiceMock random; ReadyWatcher initialized; const std::string yaml = R"EOF( @@ -1368,8 +1518,15 @@ TEST(ClusterMetadataTest, Metadata) { value: 0.3 )EOF"; - StrictDnsClusterImpl cluster(parseClusterFromV2Yaml(yaml), runtime, stats, ssl_context_manager, - local_info, dns_resolver, cm, dispatcher, false); + envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); + Envoy::Stats::ScopePtr scope = stats.createScope( + fmt::format("cluster.{}.", cluster_config.alt_stat_name().empty() + ? cluster_config.name() + : std::string(cluster_config.alt_stat_name()))); + Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( + ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, + std::move(scope)); EXPECT_EQ("test_value", Config::Metadata::metadataValue(cluster.info()->metadata(), "com.bar.foo", "baz") .string_value()); From f4a0cc8b252b839c06fb073a6e6c503e0b5d6e31 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Wed, 1 Aug 2018 15:16:34 -0700 Subject: [PATCH 4/8] Revert format changes for bzl files. Signed-off-by: JimmyCYJ --- api/bazel/api_build_system.bzl | 4 --- api/bazel/repositories.bzl | 3 -- bazel/cc_configure.bzl | 7 ++--- bazel/repositories.bzl | 4 +-- bazel/repository_locations.bzl | 56 +++++++++++++++++----------------- tools/protodoc/protodoc.bzl | 2 +- 6 files changed, 33 insertions(+), 43 deletions(-) diff --git a/api/bazel/api_build_system.bzl b/api/bazel/api_build_system.bzl index c573b12551869..497d82c5ccc07 100644 --- a/api/bazel/api_build_system.bzl +++ b/api/bazel/api_build_system.bzl @@ -4,13 +4,9 @@ load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_test") _PY_SUFFIX = "_py" - _CC_SUFFIX = "_cc" - _GO_PROTO_SUFFIX = "_go_proto" - _GO_GRPC_SUFFIX = "_go_grpc" - _GO_IMPORTPATH_PREFIX = "github.com/envoyproxy/data-plane-api/api/" def _Suffix(d, suffix): diff --git a/api/bazel/repositories.bzl b/api/bazel/repositories.bzl index 0288243c458ca..2e497d712fc87 100644 --- a/api/bazel/repositories.bzl +++ b/api/bazel/repositories.bzl @@ -1,9 +1,6 @@ GOOGLEAPIS_SHA = "d642131a6e6582fc226caf9893cb7fe7885b3411" # May 23, 2018 - GOGOPROTO_SHA = "1adfc126b41513cc696b209667c8656ea7aac67c" # v1.0.0 - PROMETHEUS_SHA = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c" # Nov 17, 2017 - OPENCENSUS_SHA = "ab82e5fdec8267dc2a726544b10af97675970847" # May 23, 2018 PGV_GIT_SHA = "f9d2b11e44149635b23a002693b76512b01ae515" diff --git a/bazel/cc_configure.bzl b/bazel/cc_configure.bzl index 3cc25e81ac509..eb1dead6b260a 100644 --- a/bazel/cc_configure.bzl +++ b/bazel/cc_configure.bzl @@ -1,7 +1,4 @@ -load( - "@bazel_tools//tools/cpp:cc_configure.bzl", - _upstream_cc_autoconf_impl = "cc_autoconf_impl", -) +load("@bazel_tools//tools/cpp:cc_configure.bzl", _upstream_cc_autoconf_impl = "cc_autoconf_impl") load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "find_cc") @@ -85,6 +82,7 @@ def cc_autoconf_impl(repository_ctx): return _upstream_cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools) cc_autoconf = repository_rule( + implementation = cc_autoconf_impl, attrs = { "_envoy_cc_wrapper": attr.label(default = "@envoy//bazel:cc_wrapper.py"), }, @@ -120,7 +118,6 @@ cc_autoconf = repository_rule( "VS120COMNTOOLS", "VS140COMNTOOLS", ], - implementation = cc_autoconf_impl, ) def cc_configure(): diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 359085772bfcc..3d231c259ff00 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -126,10 +126,10 @@ def _default_envoy_build_config_impl(ctx): ctx.symlink(ctx.attr.config, "extensions_build_config.bzl") _default_envoy_build_config = repository_rule( + implementation = _default_envoy_build_config_impl, attrs = { "config": attr.label(default = "@envoy//source/extensions:extensions_build_config.bzl"), }, - implementation = _default_envoy_build_config_impl, ) def _default_envoy_api_impl(ctx): @@ -147,10 +147,10 @@ def _default_envoy_api_impl(ctx): ctx.symlink(ctx.path(ctx.attr.api).dirname.get_child(d), d) _default_envoy_api = repository_rule( + implementation = _default_envoy_api_impl, attrs = { "api": attr.label(default = "@envoy//api:BUILD"), }, - implementation = _default_envoy_api_impl, ) # Python dependencies. If these become non-trivial, we might be better off using a virtualenv to diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 9712442aa5130..8cfdd56d3c9d8 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -4,10 +4,14 @@ REPOSITORY_LOCATIONS = dict( commit = "372daf7042ffe3da1335743e7c93d78f1399aba7", # chromium-68.0.3440.75 remote = "https://github.com/google/boringssl", ), + com_google_absl = dict( + commit = "92020a042c0cd46979db9f6f0cb32783dc07765e", # 2018-06-08 + remote = "https://github.com/abseil/abseil-cpp", + ), com_github_apache_thrift = dict( sha256 = "7d59ac4fdcb2c58037ebd4a9da5f9a49e3e034bf75b3f26d9fe48ba3d8806e6b", - strip_prefix = "thrift-0.11.0", urls = ["https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz"], # 0.11.0 + strip_prefix = "thrift-0.11.0", ), com_github_bombela_backward = dict( commit = "44ae9609e860e3428cd057f7052e505b4819eb84", # 2018-02-06 @@ -39,10 +43,6 @@ REPOSITORY_LOCATIONS = dict( commit = "c0d77201039c7b119b18bc7fb991564c602dd75d", remote = "https://github.com/gcovr/gcovr", ), - com_github_google_jwt_verify = dict( - commit = "4eb9e96485b71e00d43acc7207501caafb085b4a", - remote = "https://github.com/google/jwt_verify_lib", - ), com_github_google_libprotobuf_mutator = dict( commit = "c3d2faf04a1070b0b852b0efdef81e1a81ba925e", remote = "https://github.com/google/libprotobuf-mutator", @@ -51,6 +51,22 @@ REPOSITORY_LOCATIONS = dict( commit = "bec3b5ada2c5e5d782dff0b7b5018df646b65cb0", # v1.12.0 remote = "https://github.com/grpc/grpc.git", ), + io_opentracing_cpp = dict( + commit = "3b36b084a4d7fffc196eac83203cf24dfb8696b3", # v1.4.2 + remote = "https://github.com/opentracing/opentracing-cpp", + ), + com_lightstep_tracer_cpp = dict( + commit = "ae6a6bba65f8c4d438a6a3ac855751ca8f52e1dc", + remote = "https://github.com/lightstep/lightstep-tracer-cpp", # v0.7.1 + ), + lightstep_vendored_googleapis = dict( + commit = "d6f78d948c53f3b400bb46996eb3084359914f9b", + remote = "https://github.com/google/googleapis", + ), + com_github_google_jwt_verify = dict( + commit = "4eb9e96485b71e00d43acc7207501caafb085b4a", + remote = "https://github.com/google/jwt_verify_lib", + ), com_github_nodejs_http_parser = dict( # 2018-07-20 snapshot to pick up: # A performance fix, nodejs/http-parser PR 422. @@ -71,24 +87,20 @@ REPOSITORY_LOCATIONS = dict( commit = "f54b0e47a08782a6131cc3d60f94d038fa6e0a51", # v1.1.0 remote = "https://github.com/tencent/rapidjson", ), - com_github_twitter_common_finagle_thrift = dict( - sha256 = "1e3a57d11f94f58745e6b83348ecd4fa74194618704f45444a15bc391fde497a", - strip_prefix = "twitter.common.finagle-thrift-0.3.9/src", - urls = ["https://files.pythonhosted.org/packages/f9/e7/4f80d582578f8489226370762d2cf6bc9381175d1929eba1754e03f70708/twitter.common.finagle-thrift-0.3.9.tar.gz"], # 0.3.9 - ), com_github_twitter_common_lang = dict( sha256 = "56d1d266fd4767941d11c27061a57bc1266a3342e551bde3780f9e9eb5ad0ed1", - strip_prefix = "twitter.common.lang-0.3.9/src", urls = ["https://files.pythonhosted.org/packages/08/bc/d6409a813a9dccd4920a6262eb6e5889e90381453a5f58938ba4cf1d9420/twitter.common.lang-0.3.9.tar.gz"], # 0.3.9 + strip_prefix = "twitter.common.lang-0.3.9/src", ), com_github_twitter_common_rpc = dict( sha256 = "0792b63fb2fb32d970c2e9a409d3d00633190a22eb185145fe3d9067fdaa4514", - strip_prefix = "twitter.common.rpc-0.3.9/src", urls = ["https://files.pythonhosted.org/packages/be/97/f5f701b703d0f25fbf148992cd58d55b4d08d3db785aad209255ee67e2d0/twitter.common.rpc-0.3.9.tar.gz"], # 0.3.9 + strip_prefix = "twitter.common.rpc-0.3.9/src", ), - com_google_absl = dict( - commit = "92020a042c0cd46979db9f6f0cb32783dc07765e", # 2018-06-08 - remote = "https://github.com/abseil/abseil-cpp", + com_github_twitter_common_finagle_thrift = dict( + sha256 = "1e3a57d11f94f58745e6b83348ecd4fa74194618704f45444a15bc391fde497a", + urls = ["https://files.pythonhosted.org/packages/f9/e7/4f80d582578f8489226370762d2cf6bc9381175d1929eba1754e03f70708/twitter.common.finagle-thrift-0.3.9.tar.gz"], # 0.3.9 + strip_prefix = "twitter.common.finagle-thrift-0.3.9/src", ), com_google_googletest = dict( commit = "43863938377a9ea1399c0596269e0890b5c5515a", @@ -102,10 +114,6 @@ REPOSITORY_LOCATIONS = dict( commit = "6a4fec616ec4b20f54d5fb530808b855cb664390", remote = "https://github.com/google/protobuf", ), - com_lightstep_tracer_cpp = dict( - commit = "ae6a6bba65f8c4d438a6a3ac855751ca8f52e1dc", - remote = "https://github.com/lightstep/lightstep-tracer-cpp", # v0.7.1 - ), grpc_httpjson_transcoding = dict( commit = "05a15e4ecd0244a981fdf0348a76658def62fa9c", # 2018-05-30 remote = "https://github.com/grpc-ecosystem/grpc-httpjson-transcoding", @@ -114,14 +122,6 @@ REPOSITORY_LOCATIONS = dict( commit = "0.11.1", remote = "https://github.com/bazelbuild/rules_go", ), - io_opentracing_cpp = dict( - commit = "3b36b084a4d7fffc196eac83203cf24dfb8696b3", # v1.4.2 - remote = "https://github.com/opentracing/opentracing-cpp", - ), - lightstep_vendored_googleapis = dict( - commit = "d6f78d948c53f3b400bb46996eb3084359914f9b", - remote = "https://github.com/google/googleapis", - ), six_archive = dict( sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", strip_prefix = "", @@ -133,4 +133,4 @@ REPOSITORY_LOCATIONS = dict( commit = "eb23aa7a5361cabc02464476dd080389340a5522", # HEAD remote = "https://github.com/google/subpar", ), -) +) \ No newline at end of file diff --git a/tools/protodoc/protodoc.bzl b/tools/protodoc/protodoc.bzl index 4b11e8ef34573..c7ab5c8948890 100644 --- a/tools/protodoc/protodoc.bzl +++ b/tools/protodoc/protodoc.bzl @@ -78,6 +78,7 @@ def _proto_doc_aspect_impl(target, ctx): return [OutputGroupInfo(rst = transitive_outputs)] proto_doc_aspect = aspect( + implementation = _proto_doc_aspect_impl, attr_aspects = ["deps"], attrs = { "_protoc": attr.label( @@ -91,5 +92,4 @@ proto_doc_aspect = aspect( cfg = "host", ), }, - implementation = _proto_doc_aspect_impl, ) From 878ece074c1a46f2c4825d5cf9fa0f796fa292af Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Wed, 1 Aug 2018 15:18:51 -0700 Subject: [PATCH 5/8] add one empty line Signed-off-by: JimmyCYJ --- bazel/repository_locations.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 8cfdd56d3c9d8..7a65f4c956f3a 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -133,4 +133,4 @@ REPOSITORY_LOCATIONS = dict( commit = "eb23aa7a5361cabc02464476dd080389340a5522", # HEAD remote = "https://github.com/google/subpar", ), -) \ No newline at end of file +) From 2005edd534dd7274f5622408b595fd54f9092715 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Wed, 1 Aug 2018 15:50:16 -0700 Subject: [PATCH 6/8] format fix Signed-off-by: JimmyCYJ --- source/server/transport_socket_config_impl.h | 2 +- test/common/upstream/logical_dns_cluster_test.cc | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/source/server/transport_socket_config_impl.h b/source/server/transport_socket_config_impl.h index bda630b8c5341..3f5f3e350c566 100644 --- a/source/server/transport_socket_config_impl.h +++ b/source/server/transport_socket_config_impl.h @@ -49,4 +49,4 @@ class TransportSocketFactoryContextImpl : public TransportSocketFactoryContext { } // namespace Configuration } // namespace Server -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/test/common/upstream/logical_dns_cluster_test.cc b/test/common/upstream/logical_dns_cluster_test.cc index 4264e530a1230..6da8db9cf90af 100644 --- a/test/common/upstream/logical_dns_cluster_test.cc +++ b/test/common/upstream/logical_dns_cluster_test.cc @@ -24,7 +24,6 @@ using testing::Invoke; using testing::NiceMock; -using testing::ReturnRef; using testing::_; namespace Envoy { From cd3ebd8b399bb327ca85bfe923841b0509b50c4f Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Wed, 1 Aug 2018 18:01:28 -0700 Subject: [PATCH 7/8] Revise per comments. Signed-off-by: JimmyCYJ --- .../envoy/server/transport_socket_config.h | 2 +- source/common/upstream/eds.cc | 10 +-- source/common/upstream/eds.h | 3 +- source/common/upstream/logical_dns_cluster.cc | 8 +-- source/common/upstream/logical_dns_cluster.h | 3 +- .../common/upstream/original_dst_cluster.cc | 6 +- source/common/upstream/original_dst_cluster.h | 3 +- source/common/upstream/upstream_impl.cc | 47 +++++++------- source/common/upstream/upstream_impl.h | 14 ++--- source/server/transport_socket_config_impl.h | 2 +- test/common/upstream/eds_test.cc | 2 +- .../upstream/logical_dns_cluster_test.cc | 8 +-- .../upstream/original_dst_cluster_test.cc | 2 +- test/common/upstream/sds_test.cc | 2 +- test/common/upstream/upstream_impl_test.cc | 62 +++++++++---------- 15 files changed, 85 insertions(+), 89 deletions(-) diff --git a/include/envoy/server/transport_socket_config.h b/include/envoy/server/transport_socket_config.h index 9adb43233d3e6..de36c3d963393 100644 --- a/include/envoy/server/transport_socket_config.h +++ b/include/envoy/server/transport_socket_config.h @@ -47,7 +47,7 @@ class TransportSocketFactoryContext { /** * @return information about the local environment the server is running in. */ - virtual const LocalInfo::LocalInfo& local_info() PURE; + virtual const LocalInfo::LocalInfo& localInfo() PURE; /** * @return Event::Dispatcher& the main thread's dispatcher. diff --git a/source/common/upstream/eds.cc b/source/common/upstream/eds.cc index fee384140067a..8272738fe5d4f 100644 --- a/source/common/upstream/eds.cc +++ b/source/common/upstream/eds.cc @@ -18,12 +18,12 @@ namespace Envoy { namespace Upstream { EdsClusterImpl::EdsClusterImpl( - const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) - : BaseDynamicClusterImpl(cluster, runtime, added_via_api, factory_context, - std::move(stats_scope)), - cm_(factory_context.clusterManager()), local_info_(factory_context.local_info()), + Stats::ScopePtr&& stats_scope, bool added_via_api) + : BaseDynamicClusterImpl(cluster, runtime, factory_context, std::move(stats_scope), + added_via_api), + cm_(factory_context.clusterManager()), local_info_(factory_context.localInfo()), cluster_name_(cluster.eds_cluster_config().service_name().empty() ? cluster.name() : cluster.eds_cluster_config().service_name()) { diff --git a/source/common/upstream/eds.h b/source/common/upstream/eds.h index c8c333b6e9c5f..b4c10794e9ccf 100644 --- a/source/common/upstream/eds.h +++ b/source/common/upstream/eds.h @@ -19,9 +19,8 @@ class EdsClusterImpl : public BaseDynamicClusterImpl, Config::SubscriptionCallbacks { public: EdsClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - bool added_via_api, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope); + Stats::ScopePtr&& stats_scope, bool added_via_api); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Secondary; } diff --git a/source/common/upstream/logical_dns_cluster.cc b/source/common/upstream/logical_dns_cluster.cc index 9a30051fd8695..10ffac930685c 100644 --- a/source/common/upstream/logical_dns_cluster.cc +++ b/source/common/upstream/logical_dns_cluster.cc @@ -17,16 +17,16 @@ namespace Upstream { LogicalDnsCluster::LogicalDnsCluster( const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Network::DnsResolverSharedPtr dns_resolver, ThreadLocal::SlotAllocator& tls, bool added_via_api, + Network::DnsResolverSharedPtr dns_resolver, ThreadLocal::SlotAllocator& tls, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) - : ClusterImplBase(cluster, runtime, added_via_api, factory_context, std::move(stats_scope)), + Stats::ScopePtr&& stats_scope, bool added_via_api) + : ClusterImplBase(cluster, runtime, factory_context, std::move(stats_scope), added_via_api), dns_resolver_(dns_resolver), dns_refresh_rate_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))), tls_(tls.allocateSlot()), resolve_timer_(factory_context.dispatcher().createTimer( [this]() -> void { startResolve(); })), - local_info_(factory_context.local_info()), + local_info_(factory_context.localInfo()), load_assignment_(cluster.has_load_assignment() ? cluster.load_assignment() : Config::Utility::translateClusterHosts(cluster.hosts())) { diff --git a/source/common/upstream/logical_dns_cluster.h b/source/common/upstream/logical_dns_cluster.h index cf51b52836fbb..cf3660073762c 100644 --- a/source/common/upstream/logical_dns_cluster.h +++ b/source/common/upstream/logical_dns_cluster.h @@ -30,9 +30,8 @@ class LogicalDnsCluster : public ClusterImplBase { public: LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, Network::DnsResolverSharedPtr dns_resolver, ThreadLocal::SlotAllocator& tls, - bool added_via_api, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope); + Stats::ScopePtr&& stats_scope, bool added_via_api); ~LogicalDnsCluster(); diff --git a/source/common/upstream/original_dst_cluster.cc b/source/common/upstream/original_dst_cluster.cc index 3db1e00b80c22..f519d4c543c41 100644 --- a/source/common/upstream/original_dst_cluster.cc +++ b/source/common/upstream/original_dst_cluster.cc @@ -123,10 +123,10 @@ OriginalDstCluster::LoadBalancer::requestOverrideHost(LoadBalancerContext* conte } OriginalDstCluster::OriginalDstCluster( - const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, bool added_via_api, + const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) - : ClusterImplBase(config, runtime, added_via_api, factory_context, std::move(stats_scope)), + Stats::ScopePtr&& stats_scope, bool added_via_api) + : ClusterImplBase(config, runtime, factory_context, std::move(stats_scope), added_via_api), dispatcher_(factory_context.dispatcher()), cleanup_interval_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(config, cleanup_interval, 5000))), diff --git a/source/common/upstream/original_dst_cluster.h b/source/common/upstream/original_dst_cluster.h index 0fece8f9af33d..74d02a8627700 100644 --- a/source/common/upstream/original_dst_cluster.h +++ b/source/common/upstream/original_dst_cluster.h @@ -25,9 +25,8 @@ namespace Upstream { class OriginalDstCluster : public ClusterImplBase { public: OriginalDstCluster(const envoy::api::v2::Cluster& config, Runtime::Loader& runtime, - bool added_via_api, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope); + Stats::ScopePtr&& stats_scope, bool added_via_api); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 628b171dfadd3..05d1396405b89 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -277,9 +277,10 @@ ClusterInfoImpl::ClusterInfoImpl(const envoy::api::v2::Cluster& config, std::chrono::milliseconds(PROTOBUF_GET_MS_REQUIRED(config, connect_timeout))), per_connection_buffer_limit_bytes_( PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, per_connection_buffer_limit_bytes, 1024 * 1024)), - load_report_stats_(generateLoadReportStats(load_report_stats_store_)), transport_socket_factory_(std::move(socket_factory)), stats_scope_(std::move(stats_scope)), - stats_(generateStats(*stats_scope_)), features_(parseFeatures(config)), + stats_(generateStats(*stats_scope_)), + load_report_stats_(generateLoadReportStats(load_report_stats_store_)), + features_(parseFeatures(config)), http2_settings_(Http::Utility::parseHttp2Settings(config.http2_protocol_options())), resource_managers_(config, runtime, name_), maintenance_mode_runtime_key_(fmt::format("upstream.maintenance_mode.{}", name_)), @@ -398,18 +399,18 @@ ClusterSharedPtr ClusterImplBase::create( switch (cluster.type()) { case envoy::api::v2::Cluster::STATIC: - new_cluster.reset(new StaticClusterImpl(cluster, runtime, added_via_api, factory_context, - std::move(stats_scope))); + new_cluster.reset(new StaticClusterImpl(cluster, runtime, factory_context, + std::move(stats_scope), added_via_api)); break; case envoy::api::v2::Cluster::STRICT_DNS: new_cluster.reset(new StrictDnsClusterImpl(cluster, runtime, selected_dns_resolver, - added_via_api, factory_context, - std::move(stats_scope))); + factory_context, std::move(stats_scope), + added_via_api)); break; case envoy::api::v2::Cluster::LOGICAL_DNS: new_cluster.reset(new LogicalDnsCluster(cluster, runtime, selected_dns_resolver, tls, - added_via_api, factory_context, - std::move(stats_scope))); + factory_context, std::move(stats_scope), + added_via_api)); break; case envoy::api::v2::Cluster::ORIGINAL_DST: if (cluster.lb_policy() != envoy::api::v2::Cluster::ORIGINAL_DST_LB) { @@ -420,8 +421,8 @@ ClusterSharedPtr ClusterImplBase::create( throw EnvoyException(fmt::format( "cluster: cluster type 'original_dst' may not be used with lb_subset_config")); } - new_cluster.reset(new OriginalDstCluster(cluster, runtime, added_via_api, factory_context, - std::move(stats_scope))); + new_cluster.reset(new OriginalDstCluster(cluster, runtime, factory_context, + std::move(stats_scope), added_via_api)); break; case envoy::api::v2::Cluster::EDS: if (!cluster.has_eds_cluster_config()) { @@ -429,8 +430,8 @@ ClusterSharedPtr ClusterImplBase::create( } // We map SDS to EDS, since EDS provides backwards compatibility with SDS. - new_cluster.reset(new EdsClusterImpl(cluster, runtime, added_via_api, factory_context, - std::move(stats_scope))); + new_cluster.reset(new EdsClusterImpl(cluster, runtime, factory_context, std::move(stats_scope), + added_via_api)); break; default: NOT_REACHED_GCOVR_EXCL_LINE; @@ -452,9 +453,9 @@ ClusterSharedPtr ClusterImplBase::create( } ClusterImplBase::ClusterImplBase( - const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) + Stats::ScopePtr&& stats_scope, bool added_via_api) : runtime_(runtime) { auto socket_factory = createTransportSocketFactory(cluster, factory_context); info_ = std::make_unique(cluster, factory_context.clusterManager().bindConfig(), @@ -786,11 +787,11 @@ void PriorityStateManager::updateClusterPrioritySet( } StaticClusterImpl::StaticClusterImpl( - const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, bool added_via_api, + const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) - : ClusterImplBase(cluster, runtime, added_via_api, factory_context, std::move(stats_scope)), - priority_state_manager_(new PriorityStateManager(*this, factory_context.local_info())) { + Stats::ScopePtr&& stats_scope, bool added_via_api) + : ClusterImplBase(cluster, runtime, factory_context, std::move(stats_scope), added_via_api), + priority_state_manager_(new PriorityStateManager(*this, factory_context.localInfo())) { // TODO(dio): Use by-reference when cluster.hosts() is removed. const envoy::api::v2::ClusterLoadAssignment cluster_load_assignment( cluster.has_load_assignment() ? cluster.load_assignment() @@ -969,12 +970,12 @@ bool BaseDynamicClusterImpl::updateDynamicHostList(const HostVector& new_hosts, StrictDnsClusterImpl::StrictDnsClusterImpl( const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Network::DnsResolverSharedPtr dns_resolver, bool added_via_api, + Network::DnsResolverSharedPtr dns_resolver, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope) - : BaseDynamicClusterImpl(cluster, runtime, added_via_api, factory_context, - std::move(stats_scope)), - local_info_(factory_context.local_info()), dns_resolver_(dns_resolver), + Stats::ScopePtr&& stats_scope, bool added_via_api) + : BaseDynamicClusterImpl(cluster, runtime, factory_context, std::move(stats_scope), + added_via_api), + local_info_(factory_context.localInfo()), dns_resolver_(dns_resolver), dns_refresh_rate_ms_( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))) { switch (cluster.dns_lookup_family()) { diff --git a/source/common/upstream/upstream_impl.h b/source/common/upstream/upstream_impl.h index 2cd7537272b8d..4b0989df38611 100644 --- a/source/common/upstream/upstream_impl.h +++ b/source/common/upstream/upstream_impl.h @@ -400,11 +400,11 @@ class ClusterInfoImpl : public ClusterInfo { const std::chrono::milliseconds connect_timeout_; absl::optional idle_timeout_; const uint32_t per_connection_buffer_limit_bytes_; - Stats::IsolatedStoreImpl load_report_stats_store_; - mutable ClusterLoadReportStats load_report_stats_; Network::TransportSocketFactoryPtr transport_socket_factory_; Stats::ScopePtr stats_scope_; mutable ClusterStats stats_; + Stats::IsolatedStoreImpl load_report_stats_store_; + mutable ClusterLoadReportStats load_report_stats_; const uint64_t features_; const Http::Http2Settings http2_settings_; mutable ResourceManagers resource_managers_; @@ -471,9 +471,8 @@ class ClusterImplBase : public Cluster, protected Logger::Loggable PriorityStateManagerPtr; class StaticClusterImpl : public ClusterImplBase { public: StaticClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - bool added_via_api, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope); + Stats::ScopePtr&& stats_scope, bool added_via_api); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } @@ -600,9 +598,9 @@ class BaseDynamicClusterImpl : public ClusterImplBase { class StrictDnsClusterImpl : public BaseDynamicClusterImpl { public: StrictDnsClusterImpl(const envoy::api::v2::Cluster& cluster, Runtime::Loader& runtime, - Network::DnsResolverSharedPtr dns_resolver, bool added_via_api, + Network::DnsResolverSharedPtr dns_resolver, Server::Configuration::TransportSocketFactoryContext& factory_context, - Stats::ScopePtr stats_scope); + Stats::ScopePtr&& stats_scope, bool added_via_api); // Upstream::Cluster InitializePhase initializePhase() const override { return InitializePhase::Primary; } diff --git a/source/server/transport_socket_config_impl.h b/source/server/transport_socket_config_impl.h index 3f5f3e350c566..74e50d35e6b00 100644 --- a/source/server/transport_socket_config_impl.h +++ b/source/server/transport_socket_config_impl.h @@ -29,7 +29,7 @@ class TransportSocketFactoryContextImpl : public TransportSocketFactoryContext { return cluster_manager_.clusterManagerFactory().secretManager(); } - const LocalInfo::LocalInfo& local_info() override { return local_info_; } + const LocalInfo::LocalInfo& localInfo() override { return local_info_; } Event::Dispatcher& dispatcher() override { return dispatcher_; } diff --git a/test/common/upstream/eds_test.cc b/test/common/upstream/eds_test.cc index 6dcfa979dd920..33dd33578df34 100644 --- a/test/common/upstream/eds_test.cc +++ b/test/common/upstream/eds_test.cc @@ -60,7 +60,7 @@ class EdsTest : public testing::Test { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager_, *scope, cm_, local_info_, dispatcher_, random_, stats_); cluster_.reset( - new EdsClusterImpl(eds_cluster_, runtime_, false, factory_context, std::move(scope))); + new EdsClusterImpl(eds_cluster_, runtime_, factory_context, std::move(scope), false)); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); } diff --git a/test/common/upstream/logical_dns_cluster_test.cc b/test/common/upstream/logical_dns_cluster_test.cc index 6da8db9cf90af..ba927f178985f 100644 --- a/test/common/upstream/logical_dns_cluster_test.cc +++ b/test/common/upstream/logical_dns_cluster_test.cc @@ -43,8 +43,8 @@ class LogicalDnsClusterTest : public testing::Test { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); - cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, false, - factory_context, std::move(scope))); + cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, + factory_context, std::move(scope), false)); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); @@ -62,8 +62,8 @@ class LogicalDnsClusterTest : public testing::Test { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); - cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, false, - factory_context, std::move(scope))); + cluster_.reset(new LogicalDnsCluster(cluster_config, runtime_, dns_resolver_, tls_, + factory_context, std::move(scope), false)); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); diff --git a/test/common/upstream/original_dst_cluster_test.cc b/test/common/upstream/original_dst_cluster_test.cc index 63749ec3069eb..a15109db7cf50 100644 --- a/test/common/upstream/original_dst_cluster_test.cc +++ b/test/common/upstream/original_dst_cluster_test.cc @@ -70,7 +70,7 @@ class OriginalDstClusterTest : public testing::Test { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager_, *scope, cm, local_info_, dispatcher_, random_, stats_store_); cluster_.reset( - new OriginalDstCluster(cluster_config, runtime_, false, factory_context, std::move(scope))); + new OriginalDstCluster(cluster_config, runtime_, factory_context, std::move(scope), false)); cluster_->prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated_.ready(); diff --git a/test/common/upstream/sds_test.cc b/test/common/upstream/sds_test.cc index d8bbdf8b22bed..85a7dfb180b54 100644 --- a/test/common/upstream/sds_test.cc +++ b/test/common/upstream/sds_test.cc @@ -72,7 +72,7 @@ class SdsTest : public testing::Test { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager_, *scope, cm_, local_info_, dispatcher_, random_, stats_); cluster_.reset( - new EdsClusterImpl(sds_cluster_, runtime_, false, factory_context, std::move(scope))); + new EdsClusterImpl(sds_cluster_, runtime_, factory_context, std::move(scope), false)); EXPECT_EQ(Cluster::InitializePhase::Secondary, cluster_->initializePhase()); } diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index 57da5c4426434..b8f8621192fab 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -153,8 +153,8 @@ TEST_P(StrictDnsParamTest, ImmediateResolve) { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); cluster.initialize([&]() -> void { initialized.ready(); }); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->hosts().size()); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -188,8 +188,8 @@ TEST(StrictDnsClusterImplTest, ZeroHostsHealthChecker) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -254,8 +254,8 @@ TEST(StrictDnsClusterImplTest, Basic) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); EXPECT_CALL(runtime.snapshot_, @@ -379,8 +379,8 @@ TEST(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); std::shared_ptr health_checker(new MockHealthChecker()); EXPECT_CALL(*health_checker, start()); EXPECT_CALL(*health_checker, addHostCheckCompleteCb(_)); @@ -478,8 +478,8 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasic) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); EXPECT_CALL(runtime.snapshot_, getInteger("circuit_breakers.name.default.max_connections", 43)); EXPECT_EQ(43U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); @@ -636,8 +636,8 @@ TEST(StrictDnsClusterImplTest, LoadAssignmentBasicMultiplePriorities) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); ReadyWatcher membership_updated; cluster.prioritySet().addMemberUpdateCb( [&](uint32_t, const HostVector&, const HostVector&) -> void { membership_updated.ready(); }); @@ -791,7 +791,7 @@ TEST(StaticClusterImplTest, InitialHosts) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -825,7 +825,7 @@ TEST(StaticClusterImplTest, EmptyHostname) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -865,7 +865,7 @@ TEST(StaticClusterImplTest, LoadAssignmentEmptyHostname) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -924,7 +924,7 @@ TEST(StaticClusterImplTest, LoadAssignmentMultiplePriorities) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); EXPECT_EQ(2UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -977,7 +977,7 @@ TEST(StaticClusterImplTest, LoadAssignmentLocality) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); auto& hosts = cluster.prioritySet().hostSetsPerPriority()[0]->hosts(); @@ -1017,7 +1017,7 @@ TEST(StaticClusterImplTest, AltStatName) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); // Increment a stat and verify it is emitted with alt_stat_name cluster.info()->stats().upstream_rq_total_.inc(); @@ -1050,7 +1050,7 @@ TEST(StaticClusterImplTest, RingHash) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, true, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), true); cluster.initialize([] {}); EXPECT_EQ(1UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size()); @@ -1085,7 +1085,7 @@ TEST(StaticClusterImplTest, OutlierDetector) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); Outlier::MockDetector* detector = new Outlier::MockDetector(); EXPECT_CALL(*detector, addChangedStateCb(_)); @@ -1142,7 +1142,7 @@ TEST(StaticClusterImplTest, HealthyStat) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); Outlier::MockDetector* outlier_detector = new NiceMock(); cluster.setOutlierDetector(Outlier::DetectorSharedPtr{outlier_detector}); @@ -1234,7 +1234,7 @@ TEST(StaticClusterImplTest, UrlConfig) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(cluster_config, runtime, factory_context, std::move(scope), false); cluster.initialize([] {}); EXPECT_EQ(1024U, cluster.info()->resourceManager(ResourcePriority::Default).connections().max()); @@ -1289,7 +1289,7 @@ TEST(StaticClusterImplTest, UnsupportedLBType) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl(cluster_config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl(cluster_config, runtime, factory_context, std::move(scope), false); }, EnvoyException); } @@ -1319,7 +1319,7 @@ TEST(StaticClusterImplTest, MalformedHostIP) { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); EXPECT_THROW_WITH_MESSAGE( - StaticClusterImpl(cluster_config, runtime, false, factory_context, std::move(scope)), + StaticClusterImpl(cluster_config, runtime, factory_context, std::move(scope), false), EnvoyException, "malformed IP address: foo.bar.com. Consider setting resolver_name or " "setting cluster type to 'STRICT_DNS' or 'LOGICAL_DNS'"); @@ -1378,7 +1378,7 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(config, runtime, factory_context, std::move(scope), false); EXPECT_EQ("1.2.3.5:0", cluster.info()->sourceAddress()->asString()); } @@ -1392,7 +1392,7 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(config, runtime, factory_context, std::move(scope), false); EXPECT_EQ(cluster_address, cluster.info()->sourceAddress()->ip()->addressAsString()); } @@ -1405,7 +1405,7 @@ TEST(StaticClusterImplTest, SourceAddressPriority) { config.alt_stat_name().empty() ? config.name() : std::string(config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StaticClusterImpl cluster(config, runtime, false, factory_context, std::move(scope)); + StaticClusterImpl cluster(config, runtime, factory_context, std::move(scope), false); EXPECT_EQ(cluster_address, cluster.info()->sourceAddress()->ip()->addressAsString()); } } @@ -1439,8 +1439,8 @@ TEST(ClusterImplTest, CloseConnectionsOnHostHealthFailure) { Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); EXPECT_TRUE(cluster.info()->features() & ClusterInfo::Features::CLOSE_CONNECTIONS_ON_HOST_HEALTH_FAILURE); } @@ -1525,8 +1525,8 @@ TEST(ClusterMetadataTest, Metadata) { : std::string(cluster_config.alt_stat_name()))); Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context( ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); - StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, false, factory_context, - std::move(scope)); + StrictDnsClusterImpl cluster(cluster_config, runtime, dns_resolver, factory_context, + std::move(scope), false); EXPECT_EQ("test_value", Config::Metadata::metadataValue(cluster.info()->metadata(), "com.bar.foo", "baz") .string_value()); From 8c29e8c030c744855b6682a542ed8da966574aa4 Mon Sep 17 00:00:00 2001 From: JimmyCYJ Date: Thu, 2 Aug 2018 14:14:30 -0700 Subject: [PATCH 8/8] Revise per comments. Signed-off-by: JimmyCYJ --- test/common/upstream/upstream_impl_test.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index b8f8621192fab..4334b46717143 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -1280,7 +1280,7 @@ TEST(StaticClusterImplTest, UnsupportedLBType) { } )EOF"; - EXPECT_THROW( + EXPECT_THROW_WITH_MESSAGE( { envoy::api::v2::Cluster cluster_config = parseClusterFromJson(json); Envoy::Stats::ScopePtr scope = stats.createScope( @@ -1291,7 +1291,11 @@ TEST(StaticClusterImplTest, UnsupportedLBType) { ssl_context_manager, *scope, cm, local_info, dispatcher, random, stats); StaticClusterImpl(cluster_config, runtime, factory_context, std::move(scope), false); }, - EnvoyException); + EnvoyException, + "JSON at lines 2-9 does not conform to schema.\n" + " Invalid schema: #/properties/lb_type\n" + " Schema violation: enum\n" + " Offending document key: #/lb_type"); } TEST(StaticClusterImplTest, MalformedHostIP) {