From cbcaee1a5ae61aee7b7e537322cf114cb6d72b88 Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Mon, 13 Feb 2017 11:39:53 -0800 Subject: [PATCH 1/4] get-attributes-from-conf --- src/envoy/mixer/http_control.cc | 13 ++++--------- src/envoy/mixer/http_control.h | 3 ++- src/envoy/mixer/http_filter.cc | 11 ++++++++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/envoy/mixer/http_control.cc b/src/envoy/mixer/http_control.cc index 6ae266ef088..679e1d02b14 100644 --- a/src/envoy/mixer/http_control.cc +++ b/src/envoy/mixer/http_control.cc @@ -134,19 +134,14 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info, } // namespace -HttpControl::HttpControl(const std::string& mixer_server) { +HttpControl::HttpControl(const std::string& mixer_server, + const std::map& attributes) { ::istio::mixer_client::MixerClientOptions options; options.mixer_server = mixer_server; mixer_client_ = ::istio::mixer_client::CreateMixerClient(options); - auto source_service = getenv(kEnvNameSourceService.c_str()); - if (source_service) { - source_service_ = source_service; - } - auto target_service = getenv(kEnvNameTargetService.c_str()); - if (target_service) { - target_service_ = target_service; - } + source_service_ = attributes.at(kAttrNameTargetService); + target_service_ = attributes.at(kAttrNameSourceService); } void HttpControl::FillCheckAttributes(const HeaderMap& header_map, diff --git a/src/envoy/mixer/http_control.h b/src/envoy/mixer/http_control.h index 312016e419c..5b63972234a 100644 --- a/src/envoy/mixer/http_control.h +++ b/src/envoy/mixer/http_control.h @@ -37,7 +37,8 @@ typedef std::shared_ptr HttpRequestDataPtr; class HttpControl final : public Logger::Loggable { public: // The constructor. - HttpControl(const std::string& mixer_server); + HttpControl(const std::string& mixer_server, + const std::map& attributes); // Make mixer check call. void Check(HttpRequestDataPtr request_data, HeaderMap& headers, diff --git a/src/envoy/mixer/http_filter.cc b/src/envoy/mixer/http_filter.cc index ec209b1ff98..4f73ee904ac 100644 --- a/src/envoy/mixer/http_filter.cc +++ b/src/envoy/mixer/http_filter.cc @@ -96,7 +96,16 @@ class Config : public Logger::Loggable { __func__); } - http_control_ = std::make_shared(mixer_server); + std::map attributes; + if (config.hasObject("attributes")) { + for (const std::string& attr : config.getStringArray("attributes")) { + attributes[attr] = config.getString(attr); + } + } else { + log().warn("No attributes is specified in the config: {}", __func__); + } + + http_control_ = std::make_shared(mixer_server, attributes); log().debug("Called Mixer::Config contructor with mixer_server: ", mixer_server); } From 3d4fda101a1bd8343a5e7a712e93d5b9ddb36427 Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Mon, 13 Feb 2017 12:51:04 -0800 Subject: [PATCH 2/4] Send all attributes. --- src/envoy/mixer/http_control.cc | 13 +++++++------ src/envoy/mixer/http_control.h | 8 +++----- src/envoy/mixer/http_filter.cc | 3 ++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/envoy/mixer/http_control.cc b/src/envoy/mixer/http_control.cc index 679e1d02b14..f50fac1f2ff 100644 --- a/src/envoy/mixer/http_control.cc +++ b/src/envoy/mixer/http_control.cc @@ -134,22 +134,23 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info, } // namespace -HttpControl::HttpControl(const std::string& mixer_server, - const std::map& attributes) { +HttpControl::HttpControl( + const std::string& mixer_server, + const std::map&& attributes) { ::istio::mixer_client::MixerClientOptions options; options.mixer_server = mixer_server; mixer_client_ = ::istio::mixer_client::CreateMixerClient(options); - source_service_ = attributes.at(kAttrNameTargetService); - target_service_ = attributes.at(kAttrNameSourceService); + config_attributes_ = std::move(attributes); } void HttpControl::FillCheckAttributes(const HeaderMap& header_map, Attributes* attr) { FillRequestHeaderAttributes(header_map, attr); - SetStringAttribute(kAttrNameSourceService, source_service_, attr); - SetStringAttribute(kAttrNameTargetService, target_service_, attr); + for (auto attribute : config_attributes_) { + SetStringAttribute(attribute.first, attribute.second, attr); + } } void HttpControl::Check(HttpRequestDataPtr request_data, HeaderMap& headers, diff --git a/src/envoy/mixer/http_control.h b/src/envoy/mixer/http_control.h index 5b63972234a..32352dc53bd 100644 --- a/src/envoy/mixer/http_control.h +++ b/src/envoy/mixer/http_control.h @@ -38,7 +38,7 @@ class HttpControl final : public Logger::Loggable { public: // The constructor. HttpControl(const std::string& mixer_server, - const std::map& attributes); + const std::map&& attributes); // Make mixer check call. void Check(HttpRequestDataPtr request_data, HeaderMap& headers, @@ -56,10 +56,8 @@ class HttpControl final : public Logger::Loggable { // The mixer client std::unique_ptr<::istio::mixer_client::MixerClient> mixer_client_; - // Source service - std::string source_service_; - // Target service - std::string target_service_; + // The attributes read from the config file. + std::map config_attributes_; }; } // namespace Mixer diff --git a/src/envoy/mixer/http_filter.cc b/src/envoy/mixer/http_filter.cc index 4f73ee904ac..b1d7be81057 100644 --- a/src/envoy/mixer/http_filter.cc +++ b/src/envoy/mixer/http_filter.cc @@ -105,7 +105,8 @@ class Config : public Logger::Loggable { log().warn("No attributes is specified in the config: {}", __func__); } - http_control_ = std::make_shared(mixer_server, attributes); + http_control_ = + std::make_shared(mixer_server, std::move(attributes)); log().debug("Called Mixer::Config contructor with mixer_server: ", mixer_server); } From 0acfab63bf205aaef4d0a349bb3920bcfe0ee1dc Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Mon, 13 Feb 2017 13:46:36 -0800 Subject: [PATCH 3/4] Remove unused const strings. --- src/envoy/mixer/http_control.cc | 16 ++++------------ src/envoy/mixer/http_control.h | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/envoy/mixer/http_control.cc b/src/envoy/mixer/http_control.cc index f50fac1f2ff..870d70956fb 100644 --- a/src/envoy/mixer/http_control.cc +++ b/src/envoy/mixer/http_control.cc @@ -38,12 +38,6 @@ const std::string kAttrNameResponseTime = "response.time"; const std::string kAttrNameOriginIp = "origin.ip"; const std::string kAttrNameOriginHost = "origin.host"; -const std::string kEnvNameSourceService = "SOURCE_SERVICE"; -const std::string kEnvNameTargetService = "TARGET_SERVICE"; - -const std::string kAttrNameSourceService = "source.service"; -const std::string kAttrNameTargetService = "target.service"; - Attributes::Value StringValue(const std::string& str) { Attributes::Value v; v.type = Attributes::Value::STRING; @@ -134,21 +128,19 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info, } // namespace -HttpControl::HttpControl( - const std::string& mixer_server, - const std::map&& attributes) { +HttpControl::HttpControl(const std::string& mixer_server, + std::map&& attributes) + : config_attributes_(std::move(attributes)) { ::istio::mixer_client::MixerClientOptions options; options.mixer_server = mixer_server; mixer_client_ = ::istio::mixer_client::CreateMixerClient(options); - - config_attributes_ = std::move(attributes); } void HttpControl::FillCheckAttributes(const HeaderMap& header_map, Attributes* attr) { FillRequestHeaderAttributes(header_map, attr); - for (auto attribute : config_attributes_) { + for (const auto& attribute : config_attributes_) { SetStringAttribute(attribute.first, attribute.second, attr); } } diff --git a/src/envoy/mixer/http_control.h b/src/envoy/mixer/http_control.h index 32352dc53bd..bf52e49a81a 100644 --- a/src/envoy/mixer/http_control.h +++ b/src/envoy/mixer/http_control.h @@ -38,7 +38,7 @@ class HttpControl final : public Logger::Loggable { public: // The constructor. HttpControl(const std::string& mixer_server, - const std::map&& attributes); + std::map&& attributes); // Make mixer check call. void Check(HttpRequestDataPtr request_data, HeaderMap& headers, From 94f55a7cbc128891c04521e58e7b37c378e07c1e Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Mon, 13 Feb 2017 15:52:03 -0800 Subject: [PATCH 4/4] Address comment. --- src/envoy/mixer/http_filter.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/envoy/mixer/http_filter.cc b/src/envoy/mixer/http_filter.cc index b1d7be81057..a37ac032ee1 100644 --- a/src/envoy/mixer/http_filter.cc +++ b/src/envoy/mixer/http_filter.cc @@ -101,8 +101,6 @@ class Config : public Logger::Loggable { for (const std::string& attr : config.getStringArray("attributes")) { attributes[attr] = config.getString(attr); } - } else { - log().warn("No attributes is specified in the config: {}", __func__); } http_control_ =