-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added quota contoll without the service control client library #93
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
Changes from 12 commits
5b4d586
60f5d07
8ee01ed
74ed244
a405357
13a4e2d
7fade41
02dcb85
628987a
aec3b35
9c9de97
9e6e1e1
bf01f88
0667b00
f6c4a8d
c3a8a49
6256968
9a2bda2
f24268f
5f016a4
b7d4a42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| info->quota_rule_ = nullptr; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part was not clear when I created this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
| 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"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allocate quota call to service control is not needed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment