Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5b4d586
Added quota contoll without the service control client library
mangchiandjjoe Feb 14, 2017
60f5d07
Applied code review
mangchiandjjoe Feb 15, 2017
8ee01ed
Applied code review
mangchiandjjoe Feb 15, 2017
74ed244
Resolve conflicts
mangchiandjjoe Feb 15, 2017
a405357
Resolve conflicts
mangchiandjjoe Feb 15, 2017
13a4e2d
Fixed format error reported by script/check-style
mangchiandjjoe Feb 15, 2017
7fade41
Fixed a bug at Aggregated::GetAuthToken that causes Segmentation Fault
mangchiandjjoe Feb 15, 2017
02dcb85
Changed usage of template funcion
mangchiandjjoe Feb 16, 2017
628987a
Applied latest changes from the repo
mangchiandjjoe Feb 16, 2017
aec3b35
Applied latest changes from the repo
mangchiandjjoe Feb 16, 2017
9c9de97
Applied latest changes from the repo
mangchiandjjoe Feb 16, 2017
9e6e1e1
Merge pull request #1 from istio/rate_limiting
mangchiandjjoe Feb 16, 2017
bf01f88
Adde comments
mangchiandjjoe Feb 16, 2017
0667b00
Merge pull request #2 from istio/rate_limiting
mangchiandjjoe Feb 16, 2017
f6c4a8d
Updated log information
mangchiandjjoe Feb 17, 2017
c3a8a49
Merge pull request #3 from istio/rate_limiting
mangchiandjjoe Feb 17, 2017
6256968
Applied #101
mangchiandjjoe Feb 17, 2017
9a2bda2
Changed metric_cost_map to metric_cost_vector
mangchiandjjoe Feb 17, 2017
f24268f
Merge pull request #4 from istio/rate_limiting
mangchiandjjoe Feb 17, 2017
5f016a4
Fixed test case compilation error
mangchiandjjoe Feb 17, 2017
b7d4a42
Fixed test case compilation error
mangchiandjjoe Feb 17, 2017
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: 2 additions & 0 deletions contrib/endpoints/src/api_manager/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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 @@ -64,6 +64,7 @@ class ServiceAccountToken {
enum JWT_TOKEN_TYPE {
JWT_TOKEN_FOR_SERVICE_CONTROL = 0,
JWT_TOKEN_FOR_CLOUD_TRACING,
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 @@ -18,6 +18,7 @@
#include "contrib/endpoints/src/api_manager/check_auth.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 @@ -33,6 +34,8 @@ void CheckWorkflow::RegisterAll() {
Register(CheckAuth);
// Checks service control.
Register(CheckServiceControl);
// Quota control
Register(QuotaControl);
}

void CheckWorkflow::Register(CheckHandler handler) {
Expand Down
1 change: 1 addition & 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
12 changes: 12 additions & 0 deletions contrib/endpoints/src/api_manager/context/request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ void RequestContext::FillCheckRequestInfo(
info->allow_unregistered_calls = method()->allow_unregistered_calls();
}

void RequestContext::FillAllocateQuotaRequestInfo(
service_control::QuotaRequestInfo *info) {
FillOperationInfo(info);

info->client_ip = request_->GetClientIP();
info->method_name = this->method_call_.method_info->name();

// TODO(jaebong) need to set quota rule and metric rule

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

info->quota_rule_ = nullptr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can assume method_info has a function

get_metric_cost_map().

it return map<string, int>*.

if nullptr, or empty in size, not need to call Quota.

Otherwise, just pass the pointer to info.

In the proto, use that to construct quota metric lists. in the request proto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part was not clear when I created this PR.
The changes are included in #101.
Can I change this after the PR merge?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

info->metric_rule_ = nullptr;
}

void RequestContext::FillReportRequestInfo(
Response *response, service_control::ReportRequestInfo *info) {
FillOperationInfo(info);
Expand Down
3 changes: 3 additions & 0 deletions contrib/endpoints/src/api_manager/context/request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class RequestContext {
// Fill CheckRequestInfo
void FillCheckRequestInfo(service_control::CheckRequestInfo *info);

// FillAllocateQuotaRequestInfo
void FillAllocateQuotaRequestInfo(service_control::QuotaRequestInfo *info);

// Fill ReportRequestInfo
void FillReportRequestInfo(Response *response,
service_control::ReportRequestInfo *info);
Expand Down
18 changes: 18 additions & 0 deletions contrib/endpoints/src/api_manager/proto/server_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ message ServiceControlConfig {
// The intermediate reports for streaming calls should not be more frequent
// than this value (in seconds)
int32 intermediate_report_min_interval = 7;

// Quota aggregator config
QuotaAggregatorConfig quota_aggregator_config = 8;

// Timeout in milliseconds on service control allocate quota requests.
// If the value is <= 0, default timeout is 5000 milliseconds.
int32 quota_timeout_ms = 9;
}

// Check aggregator config
Expand All @@ -82,6 +89,17 @@ message CheckAggregatorConfig {
int32 response_expiration_ms = 3;
}

// Quota aggregator config
message QuotaAggregatorConfig {
// The maximum number of cache entries that can be kept in the aggregation
// cache. Cache is disabled when entries <= 0.
int32 cache_entries = 1;

// The maximum milliseconds before aggregated quota requests are refreshed to
// the server.
int32 refresh_interval_ms = 2;
}

// Report aggregator config
message ReportAggregatorConfig {
// The maximum number of cache entries that can be kept in the aggregation
Expand Down
54 changes: 54 additions & 0 deletions contrib/endpoints/src/api_manager/quota_control.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2017 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.
//
////////////////////////////////////////////////////////////////////////////////
//
#include <iostream>

#include "contrib/endpoints/src/api_manager/cloud_trace/cloud_trace.h"
#include "contrib/endpoints/src/api_manager/quota_control.h"
#include "google/protobuf/stubs/status.h"

using ::google::api_manager::utils::Status;
using ::google::protobuf::util::error::Code;

namespace google {
namespace api_manager {

void QuotaControl(std::shared_ptr<context::RequestContext> context,
std::function<void(Status status)> continuation) {
std::shared_ptr<cloud_trace::CloudTraceSpan> trace_span(
CreateSpan(context->cloud_trace(), "QuotaControl"));

if (!context->service_context()->service_control()) {
TRACE(trace_span) << "Service control check is not needed";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocate quota call to service control is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to support the flag. Are we going to create a flag to enable or disable quota control in a service configuration?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my previous comment is for the message for trace_space.

we don't need a flag in service config to enable/disable quota. if there is Quota field with metrics, it is enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you correct the trace message?

continuation(Status::OK);
return;
}

service_control::QuotaRequestInfo info;
context->FillAllocateQuotaRequestInfo(&info);
context->service_context()->service_control()->Quota(
info, trace_span.get(),
[context, continuation, trace_span](utils::Status status) {

TRACE(trace_span) << "Quota service control request returned with "
<< "status " << status.ToString();

continuation(status);
});
}

} // namespace service_control_client
} // namespace google
33 changes: 33 additions & 0 deletions contrib/endpoints/src/api_manager/quota_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2017 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.
//
////////////////////////////////////////////////////////////////////////////////
//
#ifndef API_MANAGER_QUOTA_CONTROL_H_
#define API_MANAGER_QUOTA_CONTROL_H_

#include "contrib/endpoints/include/api_manager/utils/status.h"
#include "contrib/endpoints/src/api_manager/context/request_context.h"

namespace google {
namespace api_manager {

// Call service control quota.
void QuotaControl(std::shared_ptr<context::RequestContext>,
std::function<void(utils::Status)>);

} // namespace api_manager
} // namespace google

#endif // API_MANAGER_QUOTA_CONTROL_H_
Loading