Skip to content

Commit

Permalink
Merge from master to firebase (#237)
Browse files Browse the repository at this point in the history
* Simple TCP server to show how to retrieve original dest IP:port after an iptables redirect (#38)

* Simple TCP server to show how to retrieve original dest IP:port after an iptables redirect

* Fixed style.

* Rebase Envoy (#41)

* Update prototype to use iptables (#42)

* Rebase to fixed Envoy (#43)

* Handle HEAD request. (#34)

* Handle HEAD request.

* Try with GET if HEAD fails.

* Address comments.

* Format file.

* Expose bazel target (#48)

* Try again (#49)

* Integrate with mixer client. (#55)

* Integrate with mixer client.

* Restore  repositories.bzl back.

* Add originIp and originHost attributes. (#56)

* Add uuid-dev dependency in README.md (#45)

* Extract originIp and OriginHost. (#57)

* Extract originIp and OriginHost.

* Make header x-forwarded-host const.

* Update buckets for UI. (#58)

* Update buckets for UI.

* Only update time_distribution.

* Add targetService attribute. (#59)

* Use envoy new access_log handler for sending Report. (#60)

* use access_log handler.

* Not to use Loggable base class.

* Update to the latest envoy with #396. (#61)

* Fix tclap dependency fetching error (#62)

* Integrate mixer client directly with envoy. (#66)

* Integrate mixer client directly with envoy.

* Send response header in Report.

* rename filter name from esp to mixer.

* add README.

* Add release binary script. (#68)

* Push tar.gz to GCS (#69)

* Push tar.gz to GCS

* Rename envoy_esp

* Remove mixer_client from api_manager. (#72)

* Update mixer client SHA. (#74)

* Update readme. (#73)

* Adds Jenkinsfile and updates release-binary to create a SHA. (#71)

* Adds Jenkinsfile and update release-binary
* Update Jenkinsfile and gitignore
* Fixes typo and use normal build Node
* Uses default bazel config
* Using batch mode
* Update bazel memory settings
* Do not use Jenkins bazel env
* Set .bazelrc for postsubmit

* Update grpc and protobuf (#70)

* protobuf v3.2.0
* grpc v1.1.1
* Align auth lib with grpc 1.1.1

* Add sourceService. (#78)

* Add script to build docker image. (#77)

* Add script to build docker image.

* Add start_envoy for docker image.

* Use official attribute names (#80)

* Use official attribute names

* fix format

* Creates a KEY for mixer client dep. Updates release-binary (#79)

* Updated mixer repo to use a key for commit

* release-binary skip build if file exists.

* Update src/envoy/mixer/README. (#82)

* Fix src/envoy/mixer/README.md (#85)

* Get attributes from envoy config. (#87)

* Send all attributes.

* Remove unused const strings.

* Address comment.

* updated SHA to point to newer envoy with RDS API feature (#94)

* Disable travis on stable branches (#96)

* Publish debug binaries (no release yet) (#98)

* Copies the binary instead of linking for release (#102)

* Not to use api_key if its service is not actived. (#109)

* Update envoy and add c-ares (#107)

* Update envoy and add c-ares depedencies

* Update release script with debug and normal binary

* remove debug ls

* formatting

* Send StatusCode Attributes to Mixer. (#110)

* Add send_attribute filter. (#115)

* Add send_attribute filter.

* Fix format

* rename variable serialized_attributes_

* Address the comments.

* Fail request if api_key is not valid. (#116)

* Fail request if api_key is not valid.

* Format code.

* Update comments.

* Address comment.

* Rename response.http.code (#125)

* Send headers as string map. (#129)

* Send headers as string map.

* Remove origin.ip and origin.host.

* Fix format

* unify bazel's docker build targets with other istio repos (#127)

* update base debug docker image reference (#133)

* Update postsubmit to create docker images (#132)

* Adding config release for bazel build (#135)

* Fix mixer client crash. (#136)

* Get mixerclient with response parsing. (#138)

* Update nghttp2 to sync with envoy (#140)

* Fix src/envoy/mixer/README.md

* Update nghttp2 to sync with envoy

* update

* fix typo

* Populate origin.user attribute from the SAN field of client cert (#142)

* Test

* test

* test

* revert file

* address comments

* test

* fix typo

* fix format

* fix format

* Update to latest mixer_client. (#145)

* Update to latest mixer_client.

* Updated the sha.

* Not call report if decodeHeaders is not called. (#150)

* Update mixerclient with sync-ed grpc write and fail-fast. (#155)

* Update mixerclient with sync-ed write and fail-fast.

* Update to latest test.

* Update again

* Update envoy to PR553 (#156)

* Update envoy to PR553

* Update libevent to 2.1.8

* Uses a specific version of the Shared Pipeline lib (#158)

* Update lyft/envoy commit Id to latest. (#161)

* Update lyft/envoy commit Id to latest.

* Remove the comment about pull request

* Add new line - will delete in next commit.

* Update repositories.bzl (#169)

* Always set response latency (#172)

* Update mixerclient to sync_transport change. (#178)

* Use opaque config to turn on/off forward attribute and mixer filter (#179)

* Modify mixer filter

* Swap defaults

* Make the filter decoder only

* cache mixer disabled decision

* Fix a bug in opaque config change and test it out (#182)

* Fix a bug and test it out

* Update filter type

* Update README.md

* Update mixer client to mixer api with gogoproto. (#184)

* Move .bazelrc to tools/bazel.rc (#186)

* Move .bazelrc to tools/bazel.rc

* Update Jenkinsfile with latest version of pipeline

* Support apikey based traffic restriction (#189)

* b/36368559 support apikey based traffic restriction

* Fixed code formatting

* Fix crash in unreachable/overloaded RDS (#190)

* Add mixer client end to end integration test. (#177)

* Add mixer client end to end integration test.

* Split some repositories into a separate file.

* use real mixer for fake mixer_server.

* Test repository

* use mixer bzl file.

* Use mixer repositories

* Not to use mixer repository.

* Add return line at the end of WORKSPACE.

* Fix broken link (#193)

* Make quota call (#192)

* hookup quota call

* Make quota call.

* Update indent.

* Update envoy and update configs (#195)

* Update envoy and update configs

* Use gcc-4.9 for travis

* Use bazel 0.4.5

* Fix SHA of lightstep-tracer-common

* Enable check cache and refactory mixer config loading  (#197)

* Refactory the mixer config loading.

* fix format

* Add integration test.

* updated README.md

* s/send/sent/

* Split into separate tests. (#201)

* Update README on how to enable check cache. (#204)

* Update README on how to enable check cache.

* Update the comment.

* build: support Envoy native Bazel build. (#210)

* build: support Envoy native Bazel build.

This patch switches the Envoy build from src/envoy/repositories.bzl to
using the upstream native build.

See envoyproxy/envoy#663 for the corresponding changes
on the Envoy side.

* Use Envoy master with BUILD.wip rename merged.

* Fix clang-format issues.

* Fixes bazel.rc issues (#212)

* Fixes bazel rc issues

* Update Jenkins to latest pipeline version

* Fix go build (#224)

* Use TranscoderInputStream to reduce confusion around ByteCount() (#225)

* Add TranscoderInputStream to reduce confusion

* fix_format

* Merge latest changes from rate_limiting to master (#221)

* Point to googleapi in service control client. (#91)

* Point to googleapi in service control client.

* Use git repository for service-control-client.

* Merge latest changes from master (#104)

* Get attributes from envoy config. (#87)

* Send all attributes.

* Remove unused const strings.

* Address comment.

* updated SHA to point to newer envoy with RDS API feature (#94)

* Disable travis on stable branches (#96)

* Publish debug binaries (no release yet) (#98)

* Copies the binary instead of linking for release (#102)

* Extract quota config from service config. (#101)

* Add metric_cost in config.

* Remove group rules.

* Call loadQuotaConfig in config::create.

* Update latest update from master branch (#106)

* Get attributes from envoy config. (#87)

* Send all attributes.

* Remove unused const strings.

* Address comment.

* updated SHA to point to newer envoy with RDS API feature (#94)

* Disable travis on stable branches (#96)

* Publish debug binaries (no release yet) (#98)

* Copies the binary instead of linking for release (#102)

* Added quota contoll without the service control client library (#93)

* Added quota contoll without the service control client library

* Applied code review

* Applied code review

* Resolve conflicts

* Resolve conflicts

* Fixed format error reported by script/check-style

* Fixed a bug at Aggregated::GetAuthToken that causes Segmentation Fault

* Changed usage of template funcion

* Applied latest changes from the repo

* Applied latest changes from the repo

* Applied latest changes from the repo

* Adde comments

* Updated log information

* Applied #101

* Changed metric_cost_map to metric_cost_vector

* Fixed test case compilation error

* Fixed test case compilation error

* Add unit test for quota config. (#108)

* Add unit test for quota config.

* Add comments.

* Update test specifics.

* Merge latest changes from master branch (#112)

* Get attributes from envoy config. (#87)

* Send all attributes.

* Remove unused const strings.

* Address comment.

* updated SHA to point to newer envoy with RDS API feature (#94)

* Disable travis on stable branches (#96)

* Publish debug binaries (no release yet) (#98)

* Copies the binary instead of linking for release (#102)

* Not to use api_key if its service is not actived. (#109)

* If QuotaControl service is not available, return utils::Status::OK (#113)

* If QuotaControl service is not available, return utils::Status::OK

* Updated comment

* Return HTTP status code 429 on google.rpc.Code.RESOURCE_EXHAUSTED (#119)

* Fixed incorrectly resolved conflicts (#123)

* Added unit test cases for rate limiting (#124)

* Fixed incorrectly resolved conflicts

* Added unit test cases for rate limiting

* Added unit test cases for rate limiting

* Added unit test cases for rate limiting

* Added unit test cases for rate limiting

* Added unit test cases for rate limiting

* Added unit test cases for rate limiting

* Rename response.http.code (#125) (#128)

* Added handling of error code QUOTA_SYSTEM_UNAVAILABLE (#148)

* Integrated service control client library with quota cache aggregation (#149)

* Fixed error on merge (#151)

* Integrated service control client library with quota cache aggregation

* Fixed error on merge

* Fixed the compatibility issue with the latest update on esp (#152)

* Removed copied proto files (#208)

* Set default allocate quota request timeout to 1sec and applied latest service control client library change (#211)

* Merged key_restriction related changes from master (#213)

* Merge latest changes from master branch (#217)

* Not call report if decodeHeaders is not called. (#150)

* Update mixerclient with sync-ed grpc write and fail-fast. (#155)

* Update mixerclient with sync-ed write and fail-fast.

* Update to latest test.

* Update again

* Update envoy to PR553 (#156)

* Update envoy to PR553

* Update libevent to 2.1.8

* Uses a specific version of the Shared Pipeline lib (#158)

* Update lyft/envoy commit Id to latest. (#161)

* Update lyft/envoy commit Id to latest.

* Remove the comment about pull request

* Add new line - will delete in next commit.

* Update repositories.bzl (#169)

* Always set response latency (#172)

* Update mixerclient to sync_transport change. (#178)

* Use opaque config to turn on/off forward attribute and mixer filter (#179)

* Modify mixer filter

* Swap defaults

* Make the filter decoder only

* cache mixer disabled decision

* Fix a bug in opaque config change and test it out (#182)

* Fix a bug and test it out

* Update filter type

* Update README.md

* Update mixer client to mixer api with gogoproto. (#184)

* Move .bazelrc to tools/bazel.rc (#186)

* Move .bazelrc to tools/bazel.rc

* Update Jenkinsfile with latest version of pipeline

* Support apikey based traffic restriction (#189)

* b/36368559 support apikey based traffic restriction

* Fixed code formatting

* Fix crash in unreachable/overloaded RDS (#190)

* Add mixer client end to end integration test. (#177)

* Add mixer client end to end integration test.

* Split some repositories into a separate file.

* use real mixer for fake mixer_server.

* Test repository

* use mixer bzl file.

* Use mixer repositories

* Not to use mixer repository.

* Add return line at the end of WORKSPACE.

* Fix broken link (#193)

* Make quota call (#192)

* hookup quota call

* Make quota call.

* Update indent.

* Update envoy and update configs (#195)

* Update envoy and update configs

* Use gcc-4.9 for travis

* Use bazel 0.4.5

* Fix SHA of lightstep-tracer-common

* Enable check cache and refactory mixer config loading  (#197)

* Refactory the mixer config loading.

* fix format

* Add integration test.

* updated README.md

* s/send/sent/

* Split into separate tests. (#201)

* Update README on how to enable check cache. (#204)

* Update README on how to enable check cache.

* Update the comment.

* build: support Envoy native Bazel build. (#210)

* build: support Envoy native Bazel build.

This patch switches the Envoy build from src/envoy/repositories.bzl to
using the upstream native build.

See envoyproxy/envoy#663 for the corresponding changes
on the Envoy side.

* Use Envoy master with BUILD.wip rename merged.

* Fix clang-format issues.

* Fixes bazel.rc issues (#212)

* Fixes bazel rc issues

* Update Jenkins to latest pipeline version

* Updated the commit id of cloudendpoints/service-control-client-cxx (#218)

* Update commitid of cloudendpoints/service-control-client-cxx repo (#220)

* Send delta metrics for intermediate reports. (#219)

* Send delta metrics for intermediate reports.

* Move last_request_bytes/last_response_bytes to RequestContext.

* Handle final report.

* Address comment.

* Update attributes to match the canonical attribute list. (#232)

* Update response.http.code to response.code and response.latency to response.duration to line up with the canonical attributes in istio/istio.github.io/docs/concepts/attributes.md

* Format according to clang-format

* Add envoy Buffer based TranscoderInputStream (#231)

* Add envoy Buffer based TranscoderInputStream

* fix format

* A few doc changes for consistency across repos. (#235)

* Add repositories.bzl

* Added missing export setting in bazel configuration (#236)

* Added export missing in bazel configuration

* Added export missing in bazel configuration
  • Loading branch information
sarvaniv authored Apr 10, 2017
1 parent e00681a commit 9442a83
Show file tree
Hide file tree
Showing 87 changed files with 3,788 additions and 593 deletions.
30 changes: 16 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
sudo: required
dist: xenial

dist: trusty

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.9
- g++-4.9
- wget

branches:
except:
- stable

lang: go

go:
- 1.7.x
language: cpp

jdk:
- oraclejdk8

env:
- BAZEL_VERSION=0.4.3

addons:
apt:
packages:
- wget
- BAZEL_VERSION=0.4.5

cache:
directories:
Expand All @@ -35,12 +37,12 @@ before_install:
- sudo dpkg -i bazel_${BAZEL_VERSION}-linux-x86_64.deb
- sudo apt-get -f install -qqy uuid-dev
- cd ${TRAVIS_BUILD_DIR}
- mv .bazelrc .bazelrc.orig
- cat .bazelrc.travis .bazelrc.orig > .bazelrc
- mv tools/bazel.rc tools/bazel.rc.orig
- cat tools/bazel.rc.travis tools/bazel.rc.orig > tools/bazel.rc

script:
- script/check-style
- bazel --output_base=${HOME}/bazel/outbase test //...
- CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 bazel --output_base=${HOME}/bazel/outbase test //...

notifications:
slack: istio-dev:wEEEbaabdP5ieCgDOFetA9nX
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ config_setting(
},
visibility = ["//visibility:public"],
)

load("@io_bazel_rules_go//go:def.bzl", "go_prefix")

go_prefix("istio.io/proxy")
40 changes: 4 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
# Contributing guidelines
# Contribution guidelines

So, you want to hack on the Istio Proxy? Yay!

- [Contributor license agreements](#contributor-license-agreements)
- [Contributing a patch](#contributing-a-patch)

## Contributor license agreements

We'd love to accept your patches! Before we can take them, you have to jump a
few legal hurdles.

Please fill out the [Google CLA](https://cla.developers.google.com).

Once you are CLA'ed, we'll be able to accept your pull requests. This is necessary
because you own the copyright to your changes, even after your contribution
becomes part of this project. So this agreement simply gives us permission
to use and redistribute your contributions as part of the project.

***NOTE***: Only original source code from you and other people that have
signed the CLA can be accepted into the repository. This policy does not
apply to [third_party](third_party/) and [vendor](vendor/).

## Contributing a patch

If you're working on an existing issue, simply respond to the issue and express
interest in working on it. This helps other people know that the issue is
active, and hopefully prevents duplicated efforts.

If you want to work on a new idea of relatively small scope:

1. Submit an issue describing your proposed change to the repo in question.
1. The repo owners will respond to your issue promptly.
1. If your proposed change is accepted, and you haven't already done so, sign a
Contributor License Agreement (see details above).
1. Fork the repo, develop, and test your changes.
1. Submit a pull request.
So, you want to hack on the Istio proxy? Yay! Please refer to Istio's overall
[contribution guidelines](https://github.com/istio/istio/blob/master/CONTRIBUTING.md)
to find out how you can help.
29 changes: 13 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!groovy

@Library('testutils')
@Library('testutils@stable-3e4d089')

import org.istio.testutils.Utilities
import org.istio.testutils.GitUtilities
Expand All @@ -12,20 +12,17 @@ def utils = new Utilities()
def bazel = new Bazel()

mainFlow(utils) {
pullRequest(utils) {
node {
gitUtils.initialize()
// Proxy does build work correctly with Hazelcast.
// Must use .bazelrc.jenkins
bazel.setVars('', '')
}

if (utils.runStage('PRESUBMIT')) {
presubmit(gitUtils, bazel)
}
if (utils.runStage('POSTSUBMIT')) {
postsubmit(gitUtils, bazel, utils)
}
node {
gitUtils.initialize()
// Proxy does build work correctly with Hazelcast.
// Must use .bazelrc.jenkins
bazel.setVars('', '')
}
if (utils.runStage('PRESUBMIT')) {
presubmit(gitUtils, bazel)
}
if (utils.runStage('POSTSUBMIT')) {
postsubmit(gitUtils, bazel, utils)
}
}

Expand Down Expand Up @@ -62,4 +59,4 @@ def postsubmit(gitUtils, bazel, utils) {
utils.publishDockerImages(images, tags, 'release')
}
}
}
}
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ Server Side Features:

- *Monitoring & Logging*. The Proxy can report server-side metrics and logs to the Mixer.

To learn more...

- User guide coming soon!
- [Contributing to the project](./CONTRIBUTING.md)

### Filing issues

If you have a question about an Istio proxy or have a problem using one, please
[file an issue](https://github.com/istio/proxy/issues/new).
Please see [istio.io](https://istio.io)
to learn about the overall Istio project and how to get in touch with us. To learn how you can
contribute to any of the Istio components, including the proxy, please
see the Istio [contribution guidelines](https://github.com/istio/istio/blob/master/CONTRIBUTING.md).
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@ http_file(
url = "https://storage.googleapis.com/istio-build/manager/ubuntu_xenial_debug-" + DEBUG_BASE_IMAGE_SHA + ".tar.gz",
sha256 = DEBUG_BASE_IMAGE_SHA,
)

# Following go repositories are for building go integration test for mixer filter.
git_repository(
name = "io_bazel_rules_go",
commit = "2d9f328a9723baf2d037ba9db28d9d0e30683938", # Apr 6, 2017 (buildifier fix)
remote = "https://github.com/bazelbuild/rules_go.git",
)

git_repository(
name = "org_pubref_rules_protobuf",
commit = "d42e895387c658eda90276aea018056fcdcb30e4", # Mar 07 2017 (gogo* support)
remote = "https://github.com/pubref/rules_protobuf",
)

load("//src/envoy/mixer/integration_test:repositories.bzl", "go_mixer_repositories")
go_mixer_repositories()
4 changes: 4 additions & 0 deletions contrib/endpoints/include/api_manager/method.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class MethodInfo {

// Get the names of url system parameters
virtual const std::set<std::string> &system_query_parameter_names() const = 0;

// Get quota metric cost vector
virtual const std::vector<std::pair<std::string, int>> &metric_cost_vector()
const = 0;
};

} // namespace api_manager
Expand Down
21 changes: 15 additions & 6 deletions contrib/endpoints/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def googleapis_repositories(protobuf_repo="@protobuf_git//", bind=True):
licenses(["notice"])
load("{}:protobuf.bzl", "cc_proto_library")
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
exports_files(glob(["google/**"]))
Expand Down Expand Up @@ -254,16 +254,18 @@ cc_proto_library(
"google/api/control.proto",
"google/api/documentation.proto",
"google/api/endpoint.proto",
"google/api/experimental/authorization_config.proto",
"google/api/experimental/experimental.proto",
"google/api/http.proto",
"google/api/label.proto",
"google/api/log.proto",
"google/api/logging.proto",
"google/api/metric.proto",
"google/api/experimental/experimental.proto",
"google/api/experimental/authorization_config.proto",
"google/api/monitored_resource.proto",
"google/api/monitoring.proto",
"google/api/quota.proto",
"google/api/service.proto",
"google/api/source_info.proto",
"google/api/system_parameter.proto",
"google/api/usage.proto",
],
Expand Down Expand Up @@ -292,10 +294,9 @@ cc_proto_library(
)
""".format(protobuf_repo)


native.new_git_repository(
name = "googleapis_git",
commit = "412867fb105722fb9d2cd9af90af1f8f120de238",
commit = "2fe0050bd2a6d4c6ba798c0311f0b149b8997314",
remote = "https://github.com/googleapis/googleapis.git",
build_file_content = BUILD,
)
Expand Down Expand Up @@ -326,7 +327,7 @@ def servicecontrol_client_repositories(bind=True):

native.git_repository(
name = "servicecontrol_client_git",
commit = "d739d755365c6a13d0b4164506fd593f53932f5d",
commit = "3d1a30d9221e700542eeaaf20eab69faddb63894",
remote = "https://github.com/cloudendpoints/service-control-client-cxx.git",
)

Expand All @@ -335,3 +336,11 @@ def servicecontrol_client_repositories(bind=True):
name = "servicecontrol_client",
actual = "@servicecontrol_client_git//:service_control_client_lib",
)
native.bind(
name = "quotacontrol",
actual = "@servicecontrol_client_git//proto:quotacontrol",
)
native.bind(
name = "quotacontrol_genproto",
actual = "@servicecontrol_client_git//proto:quotacontrol_genproto",
)
2 changes: 2 additions & 0 deletions contrib/endpoints/src/api_manager/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ cc_library(
"method_impl.cc",
"path_matcher.cc",
"path_matcher_node.cc",
"quota_control.cc",
"quota_control.h",
"request_handler.cc",
],
linkopts = select({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ServiceAccountToken {

// JWT token for accessing the http endpoints defined in Firebase Rules.
JWT_TOKEN_FOR_AUTHORIZATION_SERVICE,
JWT_TOKEN_FOR_QUOTA_CONTROL,
JWT_TOKEN_TYPE_MAX,
};
// Set audience. Only calcualtes JWT token with specified audience.
Expand Down
3 changes: 3 additions & 0 deletions contrib/endpoints/src/api_manager/check_workflow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "contrib/endpoints/src/api_manager/check_security_rules.h"
#include "contrib/endpoints/src/api_manager/check_service_control.h"
#include "contrib/endpoints/src/api_manager/fetch_metadata.h"
#include "contrib/endpoints/src/api_manager/quota_control.h"

using ::google::api_manager::utils::Status;

Expand All @@ -36,6 +37,8 @@ void CheckWorkflow::RegisterAll() {
Register(CheckServiceControl);
// Check Security Rules.
Register(CheckSecurityRules);
// Quota control
Register(QuotaControl);
}

void CheckWorkflow::Register(CheckHandler handler) {
Expand Down
20 changes: 20 additions & 0 deletions contrib/endpoints/src/api_manager/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ MethodInfoImpl *Config::GetOrCreateMethodInfoImpl(const string &name,
return i->second.get();
}

bool Config::LoadQuotaRule(ApiManagerEnvInterface *env) {
for (const auto &rule : service_.quota().metric_rules()) {
auto method = utils::FindOrNull(method_map_, rule.selector());
if (method) {
for (auto &metric_cost : rule.metric_costs()) {
(*method)->add_metric_cost(metric_cost.first, metric_cost.second);
}
} else {
env->LogError("Metric rule with selector " + rule.selector() +
"is mismatched.");
return false;
}
}

return true;
}

bool Config::LoadHttpMethods(ApiManagerEnvInterface *env,
PathMatcherBuilder *pmb) {
std::set<std::string> all_urls, urls_with_options;
Expand Down Expand Up @@ -443,6 +460,9 @@ std::unique_ptr<Config> Config::Create(ApiManagerEnvInterface *env,
if (!config->LoadBackends(env)) {
return nullptr;
}
if (!config->LoadQuotaRule(env)) {
return nullptr;
}
return config;
}

Expand Down
3 changes: 3 additions & 0 deletions contrib/endpoints/src/api_manager/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "contrib/endpoints/src/api_manager/method_impl.h"
#include "contrib/endpoints/src/api_manager/path_matcher.h"
#include "contrib/endpoints/src/api_manager/proto/server_config.pb.h"
#include "google/api/quota.pb.h"
#include "google/api/service.pb.h"

namespace google {
Expand Down Expand Up @@ -113,6 +114,8 @@ class Config {
// Load SystemParameters info to MethodInfo.
bool LoadSystemParameters(ApiManagerEnvInterface *env);

bool LoadQuotaRule(ApiManagerEnvInterface *env);

// Gets the MethodInfoImpl creating it if necessary
MethodInfoImpl *GetOrCreateMethodInfoImpl(const std::string &name,
const std::string &api_name,
Expand Down
Loading

0 comments on commit 9442a83

Please sign in to comment.