From d64136b76ef8d2a18280e3e066df311cb33404ed Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Thu, 26 Jan 2017 12:21:03 -0800 Subject: [PATCH 1/2] Integrate with mixer client. --- WORKSPACE | 40 +- contrib/endpoints/repositories.bzl | 362 +----------------- contrib/endpoints/src/api_manager/mixer/BUILD | 6 +- .../endpoints/src/api_manager/mixer/mixer.cc | 255 +++++------- .../endpoints/src/api_manager/mixer/mixer.h | 6 +- repositories.bzl | 155 -------- src/envoy/prototype/api_manager_filter.cc | 9 +- src/envoy/prototype/envoy-esp.conf | 12 - src/envoy/prototype/server_config.pb.txt | 4 +- 9 files changed, 138 insertions(+), 711 deletions(-) delete mode 100644 repositories.bzl diff --git a/WORKSPACE b/WORKSPACE index bbafd205918..a5aae5e766d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,29 +16,42 @@ # load( - "//:repositories.bzl", - "boringssl_repositories", - "protobuf_repositories", - "googletest_repositories", + "//contrib/endpoints:repositories.bzl", + "mixer_client_repositories", + "servicecontrol_client_repositories", ) -boringssl_repositories() - -protobuf_repositories() - -googletest_repositories() +mixer_client_repositories() + +# Workaround for Bazel > 0.4.0 since it needs newer protobuf.bzl from: +# https://github.com/google/protobuf/pull/2246 +# Do not use this git_repository for anything else than protobuf.bzl +new_git_repository( + name = "protobuf_bzl", + # Injecting an empty BUILD file to prevent using any build target + build_file_content = "", + commit = "05090726144b6e632c50f47720ff51049bfcbef6", + remote = "https://github.com/google/protobuf.git", +) load( - "//contrib/endpoints:repositories.bzl", + "@mixerclient_git//:repositories.bzl", + "boringssl_repositories", + "protobuf_repositories", + "googletest_repositories", + "googleapis_repositories", "grpc_repositories", "mixerapi_repositories", - "servicecontrol_client_repositories", ) +boringssl_repositories() +protobuf_repositories() +googletest_repositories() +googleapis_repositories() grpc_repositories() +mixerapi_repositories(protobuf_repo="@protobuf_bzl//") -mixerapi_repositories() - +# This has to run after googleapis_respoistories. servicecontrol_client_repositories() load( @@ -47,3 +60,4 @@ load( ) envoy_repositories() + diff --git a/contrib/endpoints/repositories.bzl b/contrib/endpoints/repositories.bzl index f3df61722a2..d3cc60350e5 100644 --- a/contrib/endpoints/repositories.bzl +++ b/contrib/endpoints/repositories.bzl @@ -14,314 +14,8 @@ # ################################################################################ # -def zlib_repositories(bind=True): - BUILD = """ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# - -licenses(["notice"]) - -exports_files(["README"]) - -cc_library( - name = "zlib", - srcs = [ - "adler32.c", - "crc32.c", - "crc32.h", - "deflate.c", - "deflate.h", - "infback.c", - "inffast.c", - "inffast.h", - "inffixed.h", - "inflate.c", - "inflate.h", - "inftrees.c", - "inftrees.h", - "trees.c", - "trees.h", - "zconf.h", - "zutil.c", - "zutil.h", - ], - hdrs = [ - "zlib.h", - ], - copts = [ - "-Wno-shift-negative-value", - "-Wno-unknown-warning-option", - ], - defines = [ - "Z_SOLO", - ], - visibility = [ - "//visibility:public", - ], -) -""" - - native.new_git_repository( - name = "zlib_git", - build_file_content = BUILD, - commit = "50893291621658f355bc5b4d450a8d06a563053d", # v1.2.8 - remote = "https://github.com/madler/zlib.git", - ) - - native.bind( - name = "zlib", - actual = "@zlib_git//:zlib" - ) - -def nanopb_repositories(bind=True): - BUILD = """ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# - -licenses(["notice"]) - -exports_files(["LICENSE.txt"]) - -cc_library( - name = "nanopb", - srcs = [ - "pb.h", - "pb_common.c", - "pb_common.h", - "pb_decode.c", - "pb_decode.h", - "pb_encode.c", - "pb_encode.h", - ], - hdrs = [":includes"], - visibility = [ - "//visibility:public", - ], -) - -genrule( - name = "includes", - srcs = [ - "pb.h", - "pb_common.h", - "pb_decode.h", - "pb_encode.h", - ], - outs = [ - "third_party/nanopb/pb.h", - "third_party/nanopb/pb_common.h", - "third_party/nanopb/pb_decode.h", - "third_party/nanopb/pb_encode.h", - ], - cmd = "mkdir -p $(@D)/third_party/nanopb && cp $(SRCS) $(@D)/third_party/nanopb", -) -""" - - native.new_git_repository( - name = "nanopb_git", - build_file_content = BUILD, - commit = "f8ac463766281625ad710900479130c7fcb4d63b", - remote = "https://github.com/nanopb/nanopb.git", - ) - - native.bind( - name = "nanopb", - actual = "@nanopb_git//:nanopb", - ) - -def grpc_repositories(bind=True): - zlib_repositories(bind) - nanopb_repositories(bind) - - native.git_repository( - name = "grpc_git", - commit = "d28417c856366df704200f544e72d31056931bce", - remote = "https://github.com/grpc/grpc.git", - ) - - if bind: - native.bind( - name = "gpr", - actual = "@grpc_git//:gpr", - ) - - native.bind( - name = "grpc", - actual = "@grpc_git//:grpc", - ) - - native.bind( - name = "grpc_cpp_plugin", - actual = "@grpc_git//:grpc_cpp_plugin", - ) - - native.bind( - name = "grpc++", - actual = "@grpc_git//:grpc++", - ) - - native.bind( - name = "grpc_lib", - actual = "@grpc_git//:grpc++_reflection", - ) - -def googleapis_repositories(protobuf_repo="@protobuf_git//", bind=True): - BUILD = """ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# - -licenses(["notice"]) - -load("{}:protobuf.bzl", "cc_proto_library") - -exports_files(glob(["google/**"])) - -cc_proto_library( - name = "servicecontrol", - srcs = [ - "google/api/servicecontrol/v1/check_error.proto", - "google/api/servicecontrol/v1/distribution.proto", - "google/api/servicecontrol/v1/log_entry.proto", - "google/api/servicecontrol/v1/metric_value.proto", - "google/api/servicecontrol/v1/operation.proto", - "google/api/servicecontrol/v1/service_controller.proto", - "google/logging/type/http_request.proto", - "google/logging/type/log_severity.proto", - "google/rpc/error_details.proto", - "google/rpc/status.proto", - "google/type/money.proto", - ], - include = ".", - visibility = ["//visibility:public"], - deps = [ - ":service_config", - ], - protoc = "//external:protoc", - default_runtime = "//external:protobuf", -) - -cc_proto_library( - name = "service_config", - srcs = [ - "google/api/annotations.proto", - "google/api/auth.proto", - "google/api/backend.proto", - "google/api/billing.proto", - "google/api/consumer.proto", - "google/api/context.proto", - "google/api/control.proto", - "google/api/documentation.proto", - "google/api/endpoint.proto", - "google/api/http.proto", - "google/api/label.proto", - "google/api/log.proto", - "google/api/logging.proto", - "google/api/metric.proto", - "google/api/monitored_resource.proto", - "google/api/monitoring.proto", - "google/api/service.proto", - "google/api/system_parameter.proto", - "google/api/usage.proto", - ], - include = ".", - visibility = ["//visibility:public"], - deps = [ - "//external:cc_wkt_protos", - ], - protoc = "//external:protoc", - default_runtime = "//external:protobuf", -) - -cc_proto_library( - name = "cloud_trace", - srcs = [ - "google/devtools/cloudtrace/v1/trace.proto", - ], - include = ".", - default_runtime = "//external:protobuf", - protoc = "//external:protoc", - visibility = ["//visibility:public"], - deps = [ - ":service_config", - "//external:cc_wkt_protos", - ], -) -""".format(protobuf_repo) - - - native.new_git_repository( - name = "googleapis_git", - commit = "db1d4547dc56a798915e0eb2c795585385922165", - remote = "https://github.com/googleapis/googleapis.git", - build_file_content = BUILD, - ) - - if bind: - native.bind( - name = "servicecontrol", - actual = "@googleapis_git//:servicecontrol", - ) - - native.bind( - name = "servicecontrol_genproto", - actual = "@googleapis_git//:servicecontrol_genproto", - ) - - native.bind( - name = "service_config", - actual = "@googleapis_git//:service_config", - ) - - native.bind( - name = "cloud_trace", - actual = "@googleapis_git//:cloud_trace", - ) def servicecontrol_client_repositories(bind=True): - googleapis_repositories(bind=bind) - native.git_repository( name = "servicecontrol_client_git", commit = "d739d755365c6a13d0b4164506fd593f53932f5d", @@ -334,51 +28,15 @@ def servicecontrol_client_repositories(bind=True): actual = "@servicecontrol_client_git//:service_control_client_lib", ) -def mixerapi_repositories(protobuf_repo="@protobuf_git//", bind=True): - BUILD = """ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# -licenses(["notice"]) - -load("{}:protobuf.bzl", "cc_proto_library") - -cc_proto_library( - name = "mixer_api_cc_proto", - srcs = glob( - ["mixer/api/v1/*.proto"], - ), - default_runtime = "//external:protobuf", - protoc = "//external:protoc", - visibility = ["//visibility:public"], - deps = [ - "//external:cc_wkt_protos", - "//external:servicecontrol", - ], -) -""".format(protobuf_repo) - - native.new_git_repository( - name = "mixerapi_git", - commit = "fc5a396185edc72d06d1937f30a8148a37d4fc1b", - remote = "https://github.com/istio/api.git", - build_file_content = BUILD, +def mixer_client_repositories(bind=True): + native.git_repository( + name = "mixerclient_git", + commit = "1569430f1e27b31e23c029c6bec0d8d5062d9e55", + remote = "https://github.com/istio/mixerclient.git", ) + if bind: - native.bind( - name = "mixer_api_cc_proto", - actual = "@mixerapi_git//:mixer_api_cc_proto", - ) + native.bind( + name = "mixer_client_lib", + actual = "@mixerclient_git//:mixer_client_lib", + ) diff --git a/contrib/endpoints/src/api_manager/mixer/BUILD b/contrib/endpoints/src/api_manager/mixer/BUILD index 8082c61e201..affe09c7ddd 100644 --- a/contrib/endpoints/src/api_manager/mixer/BUILD +++ b/contrib/endpoints/src/api_manager/mixer/BUILD @@ -32,11 +32,11 @@ cc_library( ], }), deps = [ - "//external:grpc++", - "//external:mixer_api_cc_proto", - "//external:protobuf", "//contrib/endpoints/src/api_manager:impl_headers", "//contrib/endpoints/src/api_manager/service_control", "//contrib/endpoints/src/api_manager/utils", + "//external:grpc++", + "//external:mixer_client_lib", + "//external:protobuf", ], ) diff --git a/contrib/endpoints/src/api_manager/mixer/mixer.cc b/contrib/endpoints/src/api_manager/mixer/mixer.cc index 0c0bb5d793e..47f6c4a8a2f 100644 --- a/contrib/endpoints/src/api_manager/mixer/mixer.cc +++ b/contrib/endpoints/src/api_manager/mixer/mixer.cc @@ -14,169 +14,103 @@ */ #include "contrib/endpoints/src/api_manager/mixer/mixer.h" -#include -#include "mixer/api/v1/service.pb.h" - using ::google::api_manager::utils::Status; -using ::google::protobuf::util::error::Code; -using ::google::protobuf::Map; +using ::istio::mixer_client::Attributes; namespace google { namespace api_manager { namespace mixer { namespace { -const char kMixerServiceName[] = "istio.mixer.v1.Mixer"; - -enum AttributeIndex { - ATTR_SERVICE_NAME = 0, - ATTR_PEER_ID, - ATTR_OPERATION_NAME, - ATTR_API_KEY, - ATTR_RESPONSE_CODE, - ATTR_URL, - ATTR_LOCATION, - ATTR_API_NAME, - ATTR_API_VERSION, - ATTR_API_METHOD, - ATTR_REQUEST_SIZE, - ATTR_RESPONSE_SIZE, - ATTR_LOG_MESSAGE, -}; - -struct AttributeDict { - int index; - std::string name; -} kAttributeNames[] = { - { - ATTR_SERVICE_NAME, "serviceName", - }, - { - ATTR_PEER_ID, "peerId", - }, - { - ATTR_OPERATION_NAME, "operationName", - }, - { - ATTR_API_KEY, "apiKey", - }, - { - ATTR_RESPONSE_CODE, "responseCode", - }, - { - ATTR_URL, "URL", - }, - { - ATTR_LOCATION, "location", - }, - { - ATTR_API_NAME, "apiName", - }, - { - ATTR_API_VERSION, "apiVersion", - }, - { - ATTR_API_METHOD, "apiMethod", - }, - { - ATTR_REQUEST_SIZE, "requestSize", - }, - { - ATTR_RESPONSE_SIZE, "responesSize", - }, - { - ATTR_LOG_MESSAGE, "logMessage", - }, -}; - -void SetAttributeDict(Map* dict) { - for (auto attr : kAttributeNames) { - (*dict)[attr.index] = attr.name; - } +const std::string kAttrNameServiceName = "serviceName"; +const std::string kAttrNamePeerId = "peerId"; +const std::string kAttrNameOperationName = "operationName"; +const std::string kAttrNameApiKey = "apiKey"; +const std::string kAttrNameResponseCode = "responseCode"; +const std::string kAttrNameURL = "url"; +const std::string kAttrNameLocation = "location"; +const std::string kAttrNameApiName = "apiName"; +const std::string kAttrNameApiVersion = "apiVersion"; +const std::string kAttrNameApiMethod = "apiMethod"; +const std::string kAttrNameRequestSize = "requestSize"; +const std::string kAttrNameResponseSize = "responseSize"; +const std::string kAttrNameLogMessage = "logMessage"; + +Attributes::Value StringValue(const std::string& str) { + Attributes::Value v; + v.type = Attributes::Value::STRING; + v.str_v = str; + return v; } -void CovertToPb(const service_control::CheckRequestInfo& info, - const std::string& service_name, - ::istio::mixer::v1::Attributes* attr) { - SetAttributeDict(attr->mutable_dictionary()); - - auto* str_attrs = attr->mutable_string_attributes(); - (*str_attrs)[ATTR_SERVICE_NAME] = service_name; - (*str_attrs)[ATTR_PEER_ID] = "Proxy"; - (*str_attrs)[ATTR_OPERATION_NAME] = info.operation_name; - (*str_attrs)[ATTR_API_KEY] = info.api_key; +Attributes::Value Int64Value(int64_t value) { + Attributes::Value v; + v.type = Attributes::Value::INT64; + v.value.int64_v = value; + return v; } -void CovertToPb(const service_control::ReportRequestInfo& info, - const std::string& service_name, - ::istio::mixer::v1::Attributes* attr) { - SetAttributeDict(attr->mutable_dictionary()); +void FillCheckAttributes(const service_control::CheckRequestInfo& info, + const std::string& service_name, + ::istio::mixer_client::Attributes* attr) { + attr->attributes[kAttrNameServiceName] = StringValue(service_name); + attr->attributes[kAttrNamePeerId] = StringValue("Proxy"); + attr->attributes[kAttrNameOperationName] = StringValue(info.operation_name); + attr->attributes[kAttrNameApiKey] = StringValue(info.api_key); +} - auto* str_attrs = attr->mutable_string_attributes(); - (*str_attrs)[ATTR_SERVICE_NAME] = service_name; - (*str_attrs)[ATTR_PEER_ID] = "Proxy"; - (*str_attrs)[ATTR_OPERATION_NAME] = info.operation_name; - (*str_attrs)[ATTR_API_KEY] = info.api_key; +void FillReportAttributes(const service_control::ReportRequestInfo& info, + const std::string& service_name, + ::istio::mixer_client::Attributes* attr) { + attr->attributes[kAttrNameServiceName] = StringValue(service_name); + attr->attributes[kAttrNamePeerId] = StringValue("Proxy"); + attr->attributes[kAttrNameOperationName] = StringValue(info.operation_name); + attr->attributes[kAttrNameApiKey] = StringValue(info.api_key); - (*str_attrs)[ATTR_URL] = info.url; - (*str_attrs)[ATTR_LOCATION] = info.location; + attr->attributes[kAttrNameURL] = StringValue(info.url); + attr->attributes[kAttrNameLocation] = StringValue(info.location); - (*str_attrs)[ATTR_API_NAME] = info.api_name; - (*str_attrs)[ATTR_API_VERSION] = info.api_version; - (*str_attrs)[ATTR_API_METHOD] = info.api_method; + attr->attributes[kAttrNameApiName] = StringValue(info.api_name); + attr->attributes[kAttrNameApiVersion] = StringValue(info.api_version); + attr->attributes[kAttrNameApiMethod] = StringValue(info.api_method); - (*str_attrs)[ATTR_LOG_MESSAGE] = info.log_message; + attr->attributes[kAttrNameLogMessage] = StringValue(info.log_message); - auto* int_attrs = attr->mutable_int64_attributes(); - (*int_attrs)[ATTR_RESPONSE_CODE] = info.response_code; - (*int_attrs)[ATTR_REQUEST_SIZE] = info.request_size; - (*int_attrs)[ATTR_RESPONSE_SIZE] = info.response_size; + attr->attributes[kAttrNameResponseCode] = Int64Value(info.response_code); + attr->attributes[kAttrNameRequestSize] = Int64Value(info.request_size); + attr->attributes[kAttrNameResponseSize] = Int64Value(info.response_size); } } // namespace Mixer::Mixer(ApiManagerEnvInterface* env, const Config* config) - : env_(env), request_index_(0), config_(config) {} + : env_(env), config_(config) {} Mixer::~Mixer() {} -Status Mixer::Init() { return Status::OK; } +Status Mixer::Init() { + ::istio::mixer_client::MixerClientOptions options; + options.mixer_server = + config_->server_config()->mixer_options().mixer_server(); + mixer_client_ = ::istio::mixer_client::CreateMixerClient(options); + return Status::OK; +} Status Mixer::Close() { return Status::OK; } Status Mixer::Report(const service_control::ReportRequestInfo& info) { - std::unique_ptr grpc_request(new GRPCRequest([this]( - Status status, std::string&& body) { - if (status.ok()) { - // Handle 200 response - ::istio::mixer::v1::ReportResponse response; - if (!response.ParseFromString(body)) { - status = - Status(Code::INVALID_ARGUMENT, std::string("Invalid response")); - env_->LogError(std::string("Failed parse report response: ") + body); - } - env_->LogInfo(std::string("Report response: ") + response.DebugString()); - } else { - env_->LogError(std::string("Failed to call Mixer::report, Error: ") + - status.ToString()); - } - })); - - ::istio::mixer::v1::ReportRequest request; - request.set_request_index(++request_index_); - CovertToPb(info, config_->service_name(), request.mutable_attribute_update()); - env_->LogInfo(std::string("Send Report: ") + request.DebugString()); - - std::string request_body; - request.SerializeToString(&request_body); - - grpc_request - ->set_server(config_->server_config()->mixer_options().mixer_server()) - .set_service(kMixerServiceName) - .set_method("Report") - .set_body(request_body); - - env_->RunGRPCRequest(std::move(grpc_request)); + ::istio::mixer_client::Attributes attributes; + FillReportAttributes(info, config_->service_name(), &attributes); + env_->LogInfo("Send Report: "); + mixer_client_->Report( + attributes, [this](const ::google::protobuf::util::Status& status) { + if (status.ok()) { + env_->LogInfo("Report response: OK"); + } else { + env_->LogError(std::string("Failed to call Mixer::report, Error: ") + + status.ToString()); + } + }); return Status::OK; } @@ -185,40 +119,23 @@ void Mixer::Check( cloud_trace::CloudTraceSpan* parent_span, std::function on_done) { - std::unique_ptr grpc_request(new GRPCRequest([this, on_done]( - Status status, std::string&& body) { - if (status.ok()) { - // Handle 200 response - ::istio::mixer::v1::CheckResponse response; - if (!response.ParseFromString(body)) { - status = - Status(Code::INVALID_ARGUMENT, std::string("Invalid response")); - env_->LogError(std::string("Failed parse check response: ") + body); - } - env_->LogInfo(std::string("Check response: ") + response.DebugString()); - } else { - env_->LogError(std::string("Failed to call Mixer::check, Error: ") + - status.ToString()); - } - service_control::CheckResponseInfo info; - on_done(status, info); - })); - - ::istio::mixer::v1::CheckRequest request; - request.set_request_index(++request_index_); - CovertToPb(info, config_->service_name(), request.mutable_attribute_update()); - env_->LogInfo(std::string("Send Check: ") + request.DebugString()); - - std::string request_body; - request.SerializeToString(&request_body); - - grpc_request - ->set_server(config_->server_config()->mixer_options().mixer_server()) - .set_service(kMixerServiceName) - .set_method("Check") - .set_body(request_body); - - env_->RunGRPCRequest(std::move(grpc_request)); + ::istio::mixer_client::Attributes attributes; + FillCheckAttributes(info, config_->service_name(), &attributes); + env_->LogInfo("Send Check: "); + mixer_client_->Check( + attributes, + [this, on_done](const ::google::protobuf::util::Status& status) { + if (status.ok()) { + env_->LogInfo("Check response: OK"); + } else { + env_->LogError(std::string("Failed to call Mixer::check, Error: ") + + status.ToString()); + } + service_control::CheckResponseInfo info; + on_done(Status(status.error_code(), status.error_message(), + Status::SERVICE_CONTROL), + info); + }); } Status Mixer::GetStatistics(service_control::Statistics* esp_stat) const { diff --git a/contrib/endpoints/src/api_manager/mixer/mixer.h b/contrib/endpoints/src/api_manager/mixer/mixer.h index 0318a5f06f1..4cf2d1f54a7 100644 --- a/contrib/endpoints/src/api_manager/mixer/mixer.h +++ b/contrib/endpoints/src/api_manager/mixer/mixer.h @@ -18,6 +18,7 @@ #include "contrib/endpoints/include/api_manager/env_interface.h" #include "contrib/endpoints/src/api_manager/config.h" #include "contrib/endpoints/src/api_manager/service_control/interface.h" +#include "include/client.h" namespace google { namespace api_manager { @@ -51,9 +52,10 @@ class Mixer : public service_control::Interface { // The Api Manager environment interface. ApiManagerEnvInterface* env_; - int64_t request_index_; - + // The config. const Config* config_; + // The mixer client + std::unique_ptr<::istio::mixer_client::MixerClient> mixer_client_; }; } // namespace mixer diff --git a/repositories.bzl b/repositories.bzl deleted file mode 100644 index 8764aa24d32..00000000000 --- a/repositories.bzl +++ /dev/null @@ -1,155 +0,0 @@ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# -def boringssl_repositories(bind=True): - native.git_repository( - name = "boringssl", - commit = "12c35d69008ae6b8486e435447445240509f7662", # 2016-10-24 - remote = "https://boringssl.googlesource.com/boringssl", - ) - - if bind: - native.bind( - name = "boringssl_crypto", - actual = "@boringssl//:crypto", - ) - - native.bind( - name = "libssl", - actual = "@boringssl//:ssl", - ) - - -def protobuf_repositories(bind=True): - native.git_repository( - name = "protobuf_git", - commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0 - remote = "https://github.com/google/protobuf.git", - ) - - if bind: - native.bind( - name = "protoc", - actual = "@protobuf_git//:protoc", - ) - - native.bind( - name = "protobuf", - actual = "@protobuf_git//:protobuf", - ) - - native.bind( - name = "cc_wkt_protos", - actual = "@protobuf_git//:cc_wkt_protos", - ) - - native.bind( - name = "cc_wkt_protos_genproto", - actual = "@protobuf_git//:cc_wkt_protos_genproto", - ) - - native.bind( - name = "protobuf_compiler", - actual = "@protobuf_git//:protoc_lib", - ) - - native.bind( - name = "protobuf_clib", - actual = "@protobuf_git//:protobuf_lite", - ) - - -def googletest_repositories(bind=True): - BUILD = """ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -# - -cc_library( - name = "googletest", - srcs = [ - "googletest/src/gtest-all.cc", - "googlemock/src/gmock-all.cc", - ], - hdrs = glob([ - "googletest/include/**/*.h", - "googlemock/include/**/*.h", - "googletest/src/*.cc", - "googletest/src/*.h", - "googlemock/src/*.cc", - ]), - includes = [ - "googlemock", - "googletest", - "googletest/include", - "googlemock/include", - ], - visibility = ["//visibility:public"], -) - -cc_library( - name = "googletest_main", - srcs = ["googlemock/src/gmock_main.cc"], - visibility = ["//visibility:public"], - deps = [":googletest"], -) - -cc_library( - name = "googletest_prod", - hdrs = [ - "googletest/include/gtest/gtest_prod.h", - ], - includes = [ - "googletest/include", - ], - visibility = ["//visibility:public"], -) -""" - native.new_git_repository( - name = "googletest_git", - build_file_content = BUILD, - commit = "d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0", - remote = "https://github.com/google/googletest.git", - ) - - if bind: - native.bind( - name = "googletest", - actual = "@googletest_git//:googletest", - ) - - native.bind( - name = "googletest_main", - actual = "@googletest_git//:googletest_main", - ) - - native.bind( - name = "googletest_prod", - actual = "@googletest_git//:googletest_prod", - ) diff --git a/src/envoy/prototype/api_manager_filter.cc b/src/envoy/prototype/api_manager_filter.cc index 2fca48de23c..4ccd9e6d120 100644 --- a/src/envoy/prototype/api_manager_filter.cc +++ b/src/envoy/prototype/api_manager_filter.cc @@ -214,13 +214,16 @@ class Instance : public Http::StreamFilter, status.ToJson()); if (!status.ok() && state_ != Responded) { state_ = Responded; - Utility::sendLocalReply(*decoder_callbacks_, Code(status.HttpCode()), - status.ToJson()); + decoder_callbacks_->dispatcher().post([this, status]() { + Utility::sendLocalReply(*decoder_callbacks_, Code(status.HttpCode()), + status.ToJson()); + }); return; } state_ = Complete; if (!initiating_call_) { - decoder_callbacks_->continueDecoding(); + decoder_callbacks_->dispatcher().post( + [this]() { decoder_callbacks_->continueDecoding(); }); } } diff --git a/src/envoy/prototype/envoy-esp.conf b/src/envoy/prototype/envoy-esp.conf index 11690bed565..d3ec54f405d 100644 --- a/src/envoy/prototype/envoy-esp.conf +++ b/src/envoy/prototype/envoy-esp.conf @@ -73,18 +73,6 @@ } ] }, - { - "name": "mixer_server", - "connect_timeout_ms": 5000, - "type": "strict_dns", - "lb_type": "round_robin", - "features": "http2", - "hosts": [ - { - "url": "tcp://localhost:9091" - } - ] - }, { "name": "api_manager", "connect_timeout_ms": 5000, diff --git a/src/envoy/prototype/server_config.pb.txt b/src/envoy/prototype/server_config.pb.txt index 9703886cc9e..19cb6cbb2c0 100644 --- a/src/envoy/prototype/server_config.pb.txt +++ b/src/envoy/prototype/server_config.pb.txt @@ -2,5 +2,5 @@ cloud_tracing_config { force_disable: true } mixer_options { - mixer_server: "mixer_server" -} \ No newline at end of file + mixer_server: "localhost:9091" +} From bd2423b99e9be3469f976357c727253aa3dff893 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Thu, 26 Jan 2017 21:08:35 -0800 Subject: [PATCH 2/2] Restore repositories.bzl back. --- WORKSPACE | 32 +-- contrib/endpoints/repositories.bzl | 314 ++++++++++++++++++++++++++++- repositories.bzl | 155 ++++++++++++++ 3 files changed, 483 insertions(+), 18 deletions(-) create mode 100644 repositories.bzl diff --git a/WORKSPACE b/WORKSPACE index a5aae5e766d..95dcdde5cdc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,14 +15,32 @@ ################################################################################ # +load( + "//:repositories.bzl", + "boringssl_repositories", + "protobuf_repositories", + "googletest_repositories", +) + +boringssl_repositories() + +protobuf_repositories() + +googletest_repositories() + load( "//contrib/endpoints:repositories.bzl", + "grpc_repositories", "mixer_client_repositories", "servicecontrol_client_repositories", ) +grpc_repositories() + mixer_client_repositories() +servicecontrol_client_repositories() + # Workaround for Bazel > 0.4.0 since it needs newer protobuf.bzl from: # https://github.com/google/protobuf/pull/2246 # Do not use this git_repository for anything else than protobuf.bzl @@ -36,28 +54,14 @@ new_git_repository( load( "@mixerclient_git//:repositories.bzl", - "boringssl_repositories", - "protobuf_repositories", - "googletest_repositories", - "googleapis_repositories", - "grpc_repositories", "mixerapi_repositories", ) -boringssl_repositories() -protobuf_repositories() -googletest_repositories() -googleapis_repositories() -grpc_repositories() mixerapi_repositories(protobuf_repo="@protobuf_bzl//") -# This has to run after googleapis_respoistories. -servicecontrol_client_repositories() - load( "//src/envoy:repositories.bzl", "envoy_repositories", ) envoy_repositories() - diff --git a/contrib/endpoints/repositories.bzl b/contrib/endpoints/repositories.bzl index d3cc60350e5..7b77aa91c5a 100644 --- a/contrib/endpoints/repositories.bzl +++ b/contrib/endpoints/repositories.bzl @@ -14,8 +14,314 @@ # ################################################################################ # +def zlib_repositories(bind=True): + BUILD = """ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# + +licenses(["notice"]) + +exports_files(["README"]) + +cc_library( + name = "zlib", + srcs = [ + "adler32.c", + "crc32.c", + "crc32.h", + "deflate.c", + "deflate.h", + "infback.c", + "inffast.c", + "inffast.h", + "inffixed.h", + "inflate.c", + "inflate.h", + "inftrees.c", + "inftrees.h", + "trees.c", + "trees.h", + "zconf.h", + "zutil.c", + "zutil.h", + ], + hdrs = [ + "zlib.h", + ], + copts = [ + "-Wno-shift-negative-value", + "-Wno-unknown-warning-option", + ], + defines = [ + "Z_SOLO", + ], + visibility = [ + "//visibility:public", + ], +) +""" + + native.new_git_repository( + name = "zlib_git", + build_file_content = BUILD, + commit = "50893291621658f355bc5b4d450a8d06a563053d", # v1.2.8 + remote = "https://github.com/madler/zlib.git", + ) + + native.bind( + name = "zlib", + actual = "@zlib_git//:zlib" + ) + +def nanopb_repositories(bind=True): + BUILD = """ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# + +licenses(["notice"]) + +exports_files(["LICENSE.txt"]) + +cc_library( + name = "nanopb", + srcs = [ + "pb.h", + "pb_common.c", + "pb_common.h", + "pb_decode.c", + "pb_decode.h", + "pb_encode.c", + "pb_encode.h", + ], + hdrs = [":includes"], + visibility = [ + "//visibility:public", + ], +) + +genrule( + name = "includes", + srcs = [ + "pb.h", + "pb_common.h", + "pb_decode.h", + "pb_encode.h", + ], + outs = [ + "third_party/nanopb/pb.h", + "third_party/nanopb/pb_common.h", + "third_party/nanopb/pb_decode.h", + "third_party/nanopb/pb_encode.h", + ], + cmd = "mkdir -p $(@D)/third_party/nanopb && cp $(SRCS) $(@D)/third_party/nanopb", +) +""" + + native.new_git_repository( + name = "nanopb_git", + build_file_content = BUILD, + commit = "f8ac463766281625ad710900479130c7fcb4d63b", + remote = "https://github.com/nanopb/nanopb.git", + ) + + native.bind( + name = "nanopb", + actual = "@nanopb_git//:nanopb", + ) + +def grpc_repositories(bind=True): + zlib_repositories(bind) + nanopb_repositories(bind) + + native.git_repository( + name = "grpc_git", + commit = "d28417c856366df704200f544e72d31056931bce", + remote = "https://github.com/grpc/grpc.git", + ) + + if bind: + native.bind( + name = "gpr", + actual = "@grpc_git//:gpr", + ) + + native.bind( + name = "grpc", + actual = "@grpc_git//:grpc", + ) + + native.bind( + name = "grpc_cpp_plugin", + actual = "@grpc_git//:grpc_cpp_plugin", + ) + + native.bind( + name = "grpc++", + actual = "@grpc_git//:grpc++", + ) + + native.bind( + name = "grpc_lib", + actual = "@grpc_git//:grpc++_reflection", + ) + +def googleapis_repositories(protobuf_repo="@protobuf_git//", bind=True): + BUILD = """ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# + +licenses(["notice"]) + +load("{}:protobuf.bzl", "cc_proto_library") + +exports_files(glob(["google/**"])) + +cc_proto_library( + name = "servicecontrol", + srcs = [ + "google/api/servicecontrol/v1/check_error.proto", + "google/api/servicecontrol/v1/distribution.proto", + "google/api/servicecontrol/v1/log_entry.proto", + "google/api/servicecontrol/v1/metric_value.proto", + "google/api/servicecontrol/v1/operation.proto", + "google/api/servicecontrol/v1/service_controller.proto", + "google/logging/type/http_request.proto", + "google/logging/type/log_severity.proto", + "google/rpc/error_details.proto", + "google/rpc/status.proto", + "google/type/money.proto", + ], + include = ".", + visibility = ["//visibility:public"], + deps = [ + ":service_config", + ], + protoc = "//external:protoc", + default_runtime = "//external:protobuf", +) + +cc_proto_library( + name = "service_config", + srcs = [ + "google/api/annotations.proto", + "google/api/auth.proto", + "google/api/backend.proto", + "google/api/billing.proto", + "google/api/consumer.proto", + "google/api/context.proto", + "google/api/control.proto", + "google/api/documentation.proto", + "google/api/endpoint.proto", + "google/api/http.proto", + "google/api/label.proto", + "google/api/log.proto", + "google/api/logging.proto", + "google/api/metric.proto", + "google/api/monitored_resource.proto", + "google/api/monitoring.proto", + "google/api/service.proto", + "google/api/system_parameter.proto", + "google/api/usage.proto", + ], + include = ".", + visibility = ["//visibility:public"], + deps = [ + "//external:cc_wkt_protos", + ], + protoc = "//external:protoc", + default_runtime = "//external:protobuf", +) + +cc_proto_library( + name = "cloud_trace", + srcs = [ + "google/devtools/cloudtrace/v1/trace.proto", + ], + include = ".", + default_runtime = "//external:protobuf", + protoc = "//external:protoc", + visibility = ["//visibility:public"], + deps = [ + ":service_config", + "//external:cc_wkt_protos", + ], +) +""".format(protobuf_repo) + + + native.new_git_repository( + name = "googleapis_git", + commit = "db1d4547dc56a798915e0eb2c795585385922165", + remote = "https://github.com/googleapis/googleapis.git", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "servicecontrol", + actual = "@googleapis_git//:servicecontrol", + ) + + native.bind( + name = "servicecontrol_genproto", + actual = "@googleapis_git//:servicecontrol_genproto", + ) + + native.bind( + name = "service_config", + actual = "@googleapis_git//:service_config", + ) + + native.bind( + name = "cloud_trace", + actual = "@googleapis_git//:cloud_trace", + ) def servicecontrol_client_repositories(bind=True): + googleapis_repositories(bind=bind) + native.git_repository( name = "servicecontrol_client_git", commit = "d739d755365c6a13d0b4164506fd593f53932f5d", @@ -36,7 +342,7 @@ def mixer_client_repositories(bind=True): ) if bind: - native.bind( - name = "mixer_client_lib", - actual = "@mixerclient_git//:mixer_client_lib", - ) + native.bind( + name = "mixer_client_lib", + actual = "@mixerclient_git//:mixer_client_lib", + ) diff --git a/repositories.bzl b/repositories.bzl new file mode 100644 index 00000000000..8764aa24d32 --- /dev/null +++ b/repositories.bzl @@ -0,0 +1,155 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# +def boringssl_repositories(bind=True): + native.git_repository( + name = "boringssl", + commit = "12c35d69008ae6b8486e435447445240509f7662", # 2016-10-24 + remote = "https://boringssl.googlesource.com/boringssl", + ) + + if bind: + native.bind( + name = "boringssl_crypto", + actual = "@boringssl//:crypto", + ) + + native.bind( + name = "libssl", + actual = "@boringssl//:ssl", + ) + + +def protobuf_repositories(bind=True): + native.git_repository( + name = "protobuf_git", + commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0 + remote = "https://github.com/google/protobuf.git", + ) + + if bind: + native.bind( + name = "protoc", + actual = "@protobuf_git//:protoc", + ) + + native.bind( + name = "protobuf", + actual = "@protobuf_git//:protobuf", + ) + + native.bind( + name = "cc_wkt_protos", + actual = "@protobuf_git//:cc_wkt_protos", + ) + + native.bind( + name = "cc_wkt_protos_genproto", + actual = "@protobuf_git//:cc_wkt_protos_genproto", + ) + + native.bind( + name = "protobuf_compiler", + actual = "@protobuf_git//:protoc_lib", + ) + + native.bind( + name = "protobuf_clib", + actual = "@protobuf_git//:protobuf_lite", + ) + + +def googletest_repositories(bind=True): + BUILD = """ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# + +cc_library( + name = "googletest", + srcs = [ + "googletest/src/gtest-all.cc", + "googlemock/src/gmock-all.cc", + ], + hdrs = glob([ + "googletest/include/**/*.h", + "googlemock/include/**/*.h", + "googletest/src/*.cc", + "googletest/src/*.h", + "googlemock/src/*.cc", + ]), + includes = [ + "googlemock", + "googletest", + "googletest/include", + "googlemock/include", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "googletest_main", + srcs = ["googlemock/src/gmock_main.cc"], + visibility = ["//visibility:public"], + deps = [":googletest"], +) + +cc_library( + name = "googletest_prod", + hdrs = [ + "googletest/include/gtest/gtest_prod.h", + ], + includes = [ + "googletest/include", + ], + visibility = ["//visibility:public"], +) +""" + native.new_git_repository( + name = "googletest_git", + build_file_content = BUILD, + commit = "d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0", + remote = "https://github.com/google/googletest.git", + ) + + if bind: + native.bind( + name = "googletest", + actual = "@googletest_git//:googletest", + ) + + native.bind( + name = "googletest_main", + actual = "@googletest_git//:googletest_main", + ) + + native.bind( + name = "googletest_prod", + actual = "@googletest_git//:googletest_prod", + )