Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add targetService attribute. #59

Merged
merged 1 commit into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/endpoints/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
11 changes: 11 additions & 0 deletions contrib/endpoints/src/api_manager/mixer/mixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions contrib/endpoints/src/api_manager/mixer/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/prototype/api_manager_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/envoy/prototype/api_manager_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)