diff --git a/src/envoy/mixer/config.cc b/src/envoy/mixer/config.cc index ec635f2647d..2a4ae7f260d 100644 --- a/src/envoy/mixer/config.cc +++ b/src/envoy/mixer/config.cc @@ -51,6 +51,9 @@ const std::string kDisableTcpCheckCalls("disable_tcp_check_calls"); const std::string kV2Config("v2"); +// The name for the mixer server cluster. +const std::string kDefaultMixerClusterName("mixer_server"); + void ReadStringMap(const Json::Object& json, const std::string& name, Attributes* attributes) { if (json.hasObject(name)) { @@ -62,7 +65,8 @@ void ReadStringMap(const Json::Object& json, const std::string& name, } } -void ReadTransportConfig(const Json::Object& json, TransportConfig* config) { +void ReadLegacyTransportConfig(const Json::Object& json, + TransportConfig* config) { // Default is open, unless it specifically set to "close" config->set_network_fail_policy(TransportConfig::FAIL_OPEN); if (json.hasObject(kNetworkFailPolicy) && @@ -110,13 +114,21 @@ void HttpMixerConfig::Load(const Json::Object& json) { legacy_quotas.push_back({json.getString(kQuotaName), amount}); } - ReadTransportConfig(json, http_config.mutable_transport()); + TransportConfig* transport_config = http_config.mutable_transport(); + ReadLegacyTransportConfig(json, transport_config); has_v2_config = ReadV2Config(json, &http_config); if (has_v2_config) { // If v2 config is valid, clear v1 legacy_quotas. legacy_quotas.clear(); } + + check_cluster = transport_config->check_cluster().empty() + ? kDefaultMixerClusterName + : transport_config->check_cluster(); + report_cluster = transport_config->report_cluster().empty() + ? kDefaultMixerClusterName + : transport_config->report_cluster(); } void HttpMixerConfig::CreateLegacyRouteConfig( @@ -135,12 +147,20 @@ void HttpMixerConfig::CreateLegacyRouteConfig( void TcpMixerConfig::Load(const Json::Object& json) { ReadStringMap(json, kMixerAttributes, tcp_config.mutable_mixer_attributes()); - ReadTransportConfig(json, tcp_config.mutable_transport()); + TransportConfig* transport_config = tcp_config.mutable_transport(); + ReadLegacyTransportConfig(json, transport_config); tcp_config.set_disable_check_calls( json.getBoolean(kDisableTcpCheckCalls, false)); ReadV2Config(json, &tcp_config); + + check_cluster = transport_config->check_cluster().empty() + ? kDefaultMixerClusterName + : transport_config->check_cluster(); + report_cluster = transport_config->report_cluster().empty() + ? kDefaultMixerClusterName + : transport_config->report_cluster(); } } // namespace Mixer diff --git a/src/envoy/mixer/config.h b/src/envoy/mixer/config.h index 490ad2347f9..453c2c4bdf7 100644 --- a/src/envoy/mixer/config.h +++ b/src/envoy/mixer/config.h @@ -39,6 +39,10 @@ struct HttpMixerConfig { std::vector<::istio::quota::Requirement> legacy_quotas; // If true, v2 config is valid. bool has_v2_config; + // check cluster + std::string check_cluster; + // report cluster + std::string report_cluster; // Create per route legacy config. static void CreateLegacyRouteConfig( @@ -54,6 +58,10 @@ struct TcpMixerConfig { // The Tcp client config. ::istio::mixer::v1::config::client::TcpClientConfig tcp_config; + // check cluster + std::string check_cluster; + // report cluster + std::string report_cluster; }; } // namespace Mixer diff --git a/src/envoy/mixer/grpc_transport.cc b/src/envoy/mixer/grpc_transport.cc index 4f44be63a09..22ac2c48808 100644 --- a/src/envoy/mixer/grpc_transport.cc +++ b/src/envoy/mixer/grpc_transport.cc @@ -35,9 +35,6 @@ const LowerCaseString kB3Sampled("x-b3-sampled"); const LowerCaseString kB3Flags("x-b3-flags"); const LowerCaseString kOtSpanContext("x-ot-span-context"); -// The name for the mixer server cluster. -const char* kMixerServerClusterName = "mixer_server"; - inline void CopyHeaderEntry(const HeaderEntry* entry, const LowerCaseString& key, Http::HeaderMap& headers) { @@ -109,14 +106,16 @@ void GrpcTransport::Cancel() { template typename GrpcTransport::Func -GrpcTransport::GetFunc(Upstream::ClusterManager& cm, - const HeaderMap* headers) { - return [&cm, headers](const RequestType& request, ResponseType* response, - istio::mixer_client::DoneFunc on_done) +GrpcTransport::GetFunc( + Upstream::ClusterManager& cm, const std::string& cluster_name, + const HeaderMap* headers) { + return [&cm, cluster_name, headers](const RequestType& request, + ResponseType* response, + istio::mixer_client::DoneFunc on_done) -> istio::mixer_client::CancelFunc { auto transport = new GrpcTransport( Grpc::AsyncClientPtr( - new Grpc::AsyncClientImpl(cm, kMixerServerClusterName)), + new Grpc::AsyncClientImpl(cm, cluster_name.c_str())), request, headers, response, on_done); return [transport]() { transport->Cancel(); }; }; @@ -142,9 +141,11 @@ const google::protobuf::MethodDescriptor& ReportTransport::descriptor() { // explicitly instantiate CheckTransport and ReportTransport template CheckTransport::Func CheckTransport::GetFunc( - Upstream::ClusterManager& cm, const HeaderMap* headers); + Upstream::ClusterManager& cm, const std::string& cluster_name, + const HeaderMap* headers); template ReportTransport::Func ReportTransport::GetFunc( - Upstream::ClusterManager& cm, const HeaderMap* headers); + Upstream::ClusterManager& cm, const std::string& cluster_name, + const HeaderMap* headers); } // namespace Mixer } // namespace Http diff --git a/src/envoy/mixer/grpc_transport.h b/src/envoy/mixer/grpc_transport.h index fd12a63c207..b50464c47f1 100644 --- a/src/envoy/mixer/grpc_transport.h +++ b/src/envoy/mixer/grpc_transport.h @@ -39,6 +39,7 @@ class GrpcTransport : public Grpc::TypedAsyncRequestCallbacks, istio::mixer_client::DoneFunc on_done)>; static Func GetFunc(Upstream::ClusterManager& cm, + const std::string& cluster_name, const HeaderMap* headers = nullptr); GrpcTransport(Grpc::AsyncClientPtr async_client, const RequestType& request, diff --git a/src/envoy/mixer/http_filter.cc b/src/envoy/mixer/http_filter.cc index 700038e88f8..b0fd86a28f4 100644 --- a/src/envoy/mixer/http_filter.cc +++ b/src/envoy/mixer/http_filter.cc @@ -438,7 +438,8 @@ class Instance : public Http::StreamDecoderFilter, HeaderUpdate header_update(&headers); cancel_check_ = handler_->Check( &check_data, &header_update, - CheckTransport::GetFunc(mixer_control_.cm(), &headers), + CheckTransport::GetFunc(mixer_control_.cm(), + mixer_control_.check_cluster(), &headers), [this](const Status& status) { completeCheck(status); }); initiating_call_ = false; diff --git a/src/envoy/mixer/mixer_control.cc b/src/envoy/mixer/mixer_control.cc index 2430b533852..356f36c996f 100644 --- a/src/envoy/mixer/mixer_control.cc +++ b/src/envoy/mixer/mixer_control.cc @@ -45,9 +45,11 @@ class EnvoyTimer : public ::istio::mixer_client::Timer { void CreateEnvironment(Upstream::ClusterManager& cm, Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random, + const std::string& check_cluster, + const std::string& report_cluster, ::istio::mixer_client::Environment* env) { - env->check_transport = CheckTransport::GetFunc(cm, nullptr); - env->report_transport = ReportTransport::GetFunc(cm); + env->check_transport = CheckTransport::GetFunc(cm, check_cluster, nullptr); + env->report_transport = ReportTransport::GetFunc(cm, report_cluster); env->timer_create_func = [&dispatcher](std::function timer_cb) -> std::unique_ptr<::istio::mixer_client::Timer> { @@ -70,10 +72,13 @@ HttpMixerControl::HttpMixerControl(const HttpMixerConfig& mixer_config, ::istio::mixer_control::http::Controller::Options options( mixer_config.http_config, mixer_config.legacy_quotas); - CreateEnvironment(cm, dispatcher, random, &options.env); + check_cluster_ = mixer_config.check_cluster; + report_cluster_ = mixer_config.report_cluster; - controller_ = ::istio::mixer_control::http::Controller::Create(options); + CreateEnvironment(cm, dispatcher, random, check_cluster_, report_cluster_, + &options.env); + controller_ = ::istio::mixer_control::http::Controller::Create(options); has_v2_config_ = mixer_config.has_v2_config; } @@ -85,7 +90,11 @@ TcpMixerControl::TcpMixerControl(const TcpMixerConfig& mixer_config, ::istio::mixer_control::tcp::Controller::Options options( mixer_config.tcp_config); - CreateEnvironment(cm, dispatcher, random, &options.env); + check_cluster_ = mixer_config.check_cluster; + report_cluster_ = mixer_config.report_cluster; + + CreateEnvironment(cm, dispatcher, random, check_cluster_, report_cluster_, + &options.env); controller_ = ::istio::mixer_control::tcp::Controller::Create(options); diff --git a/src/envoy/mixer/mixer_control.h b/src/envoy/mixer/mixer_control.h index d9e97b83f11..a72679f4ab1 100644 --- a/src/envoy/mixer/mixer_control.h +++ b/src/envoy/mixer/mixer_control.h @@ -36,6 +36,10 @@ class HttpMixerControl final : public ThreadLocal::ThreadLocalObject { Upstream::ClusterManager& cm() { return cm_; } + const std::string& check_cluster() const { return check_cluster_; } + + const std::string& report_cluster() const { return report_cluster_; } + ::istio::mixer_control::http::Controller* controller() { return controller_.get(); } @@ -49,6 +53,10 @@ class HttpMixerControl final : public ThreadLocal::ThreadLocalObject { std::unique_ptr<::istio::mixer_control::http::Controller> controller_; // has v2 config; bool has_v2_config_; + // check cluster + std::string check_cluster_; + // report cluster + std::string report_cluster_; }; class TcpMixerControl final : public ThreadLocal::ThreadLocalObject { @@ -66,6 +74,10 @@ class TcpMixerControl final : public ThreadLocal::ThreadLocalObject { return report_interval_ms_; } + const std::string& check_cluster() const { return check_cluster_; } + + const std::string& report_cluster() const { return report_cluster_; } + Event::Dispatcher& dispatcher() { return dispatcher_; } private: @@ -76,6 +88,11 @@ class TcpMixerControl final : public ThreadLocal::ThreadLocalObject { std::chrono::milliseconds report_interval_ms_; Event::Dispatcher& dispatcher_; + + // check cluster + std::string check_cluster_; + // report cluster + std::string report_cluster_; }; } // namespace Mixer