From 65635e0561958f4c6b46c37bf17825c9153b59c1 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Tue, 31 Jan 2017 15:35:05 -0800 Subject: [PATCH] Add targetService attribute. --- contrib/endpoints/repositories.bzl | 2 +- contrib/endpoints/src/api_manager/mixer/mixer.cc | 11 +++++++++++ contrib/endpoints/src/api_manager/mixer/mixer.h | 2 ++ src/envoy/prototype/api_manager_env.cc | 2 +- src/envoy/prototype/api_manager_filter.cc | 3 +-- src/envoy/repositories.bzl | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/contrib/endpoints/repositories.bzl b/contrib/endpoints/repositories.bzl index 7b77aa91c5a..b1f14aae8b5 100644 --- a/contrib/endpoints/repositories.bzl +++ b/contrib/endpoints/repositories.bzl @@ -337,7 +337,7 @@ def servicecontrol_client_repositories(bind=True): def mixer_client_repositories(bind=True): native.git_repository( name = "mixerclient_git", - commit = "1569430f1e27b31e23c029c6bec0d8d5062d9e55", + commit = "80e450a5126960e8e6337c3631cf2ef984038eab", remote = "https://github.com/istio/mixerclient.git", ) diff --git a/contrib/endpoints/src/api_manager/mixer/mixer.cc b/contrib/endpoints/src/api_manager/mixer/mixer.cc index e9ea9a30ea5..53837edaf67 100644 --- a/contrib/endpoints/src/api_manager/mixer/mixer.cc +++ b/contrib/endpoints/src/api_manager/mixer/mixer.cc @@ -23,6 +23,7 @@ namespace mixer { namespace { const std::string kProxyPeerID = "Istio/Proxy"; +const std::string kEnvNameTargetService = "TARGET_SERVICE"; const std::string kAttrNameServiceName = "serviceName"; const std::string kAttrNamePeerId = "peerId"; @@ -41,6 +42,7 @@ const std::string kAttrNameLogMessage = "logMessage"; const std::string kAttrNameResponseTime = "responseTime"; const std::string kAttrNameOriginIp = "originIp"; const std::string kAttrNameOriginHost = "originHost"; +const std::string kAttrNameTargetService = "targetService"; Attributes::Value StringValue(const std::string& str) { Attributes::Value v; @@ -68,6 +70,10 @@ Status Mixer::Init() { options.mixer_server = config_->server_config()->mixer_options().mixer_server(); mixer_client_ = ::istio::mixer_client::CreateMixerClient(options); + auto target_service = getenv(kEnvNameTargetService.c_str()); + if (target_service) { + target_service_ = target_service; + } return Status::OK; } @@ -93,6 +99,9 @@ void Mixer::FillCommonAttributes(const service_control::OperationInfo& info, if (!info.client_host.empty()) { attr->attributes[kAttrNameOriginHost] = StringValue(info.client_host); } + if (!target_service_.empty()) { + attr->attributes[kAttrNameTargetService] = StringValue(target_service_); + } } void Mixer::FillCheckAttributes(const service_control::CheckRequestInfo& info, @@ -143,6 +152,7 @@ Status Mixer::Report(const service_control::ReportRequestInfo& info) { ::istio::mixer_client::Attributes attributes; FillReportAttributes(info, &attributes); env_->LogInfo("Send Report: "); + env_->LogInfo(attributes.DebugString()); mixer_client_->Report( attributes, [this](const ::google::protobuf::util::Status& status) { if (status.ok()) { @@ -163,6 +173,7 @@ void Mixer::Check( ::istio::mixer_client::Attributes attributes; FillCheckAttributes(info, &attributes); env_->LogInfo("Send Check: "); + env_->LogInfo(attributes.DebugString()); mixer_client_->Check( attributes, [this, on_done](const ::google::protobuf::util::Status& status) { diff --git a/contrib/endpoints/src/api_manager/mixer/mixer.h b/contrib/endpoints/src/api_manager/mixer/mixer.h index b020d2636f9..81276e1227d 100644 --- a/contrib/endpoints/src/api_manager/mixer/mixer.h +++ b/contrib/endpoints/src/api_manager/mixer/mixer.h @@ -66,6 +66,8 @@ class Mixer : public service_control::Interface { const Config* config_; // The mixer client std::unique_ptr<::istio::mixer_client::MixerClient> mixer_client_; + // Target service + std::string target_service_; }; } // namespace mixer diff --git a/src/envoy/prototype/api_manager_env.cc b/src/envoy/prototype/api_manager_env.cc index 6b1619a6faa..f8536bcc10a 100644 --- a/src/envoy/prototype/api_manager_env.cc +++ b/src/envoy/prototype/api_manager_env.cc @@ -103,7 +103,7 @@ class HTTPRequest : public Http::Message { virtual void body(Buffer::InstancePtr &&body) override {} virtual HeaderMap *trailers() override { return nullptr; } virtual void trailers(HeaderMapPtr &&trailers) override {} - virtual std::string bodyAsString() override { return ""; } + virtual std::string bodyAsString() const override { return ""; } }; class HTTPRequestCallbacks : public AsyncClient::Callbacks { diff --git a/src/envoy/prototype/api_manager_filter.cc b/src/envoy/prototype/api_manager_filter.cc index d616ddfdf0f..87a3beeb48a 100644 --- a/src/envoy/prototype/api_manager_filter.cc +++ b/src/envoy/prototype/api_manager_filter.cc @@ -195,8 +195,7 @@ class Instance : public Http::StreamFilter, bool initiating_call_; std::string getRouteVirtualHost(HeaderMap& headers) const { - const Router::Route* route = - decoder_callbacks_->routeTable().route(headers); + const Router::Route* route = decoder_callbacks_->route(); if (route && route->routeEntry()) { return route->routeEntry()->virtualHost().name(); } diff --git a/src/envoy/repositories.bzl b/src/envoy/repositories.bzl index dd36a23d456..e19efc6dce1 100644 --- a/src/envoy/repositories.bzl +++ b/src/envoy/repositories.bzl @@ -629,6 +629,6 @@ cc_test( native.new_git_repository( name = "envoy_git", remote = "https://github.com/lyft/envoy.git", - commit = "c36bb76e304ab4c5584a07303e2953a170888319", + commit = "39f42378fa41c10996d4c3ffba534951de30ceb8", build_file_content = BUILD, )