forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate with quota parser (envoyproxy#258)
* Integrate with quota parser * Add optimization for service context lookup.
- Loading branch information
Showing
21 changed files
with
310 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* Copyright 2017 Istio Authors. 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 "client_context.h" | ||
|
||
using ::istio::mixer::v1::config::client::ServiceConfig; | ||
|
||
namespace istio { | ||
namespace mixer_control { | ||
namespace http { | ||
|
||
ClientContext::ClientContext(const Controller::Options& data) | ||
: ClientContextBase(data.config.transport(), data.env), | ||
config_(data.config), | ||
legacy_quotas_(data.legacy_quotas) {} | ||
|
||
ClientContext::ClientContext( | ||
std::unique_ptr<::istio::mixer_client::MixerClient> mixer_client, | ||
const ::istio::mixer::v1::config::client::HttpClientConfig& config, | ||
const std::vector<::istio::quota::Requirement>& legacy_quotas) | ||
: ClientContextBase(std::move(mixer_client)), | ||
config_(config), | ||
legacy_quotas_(legacy_quotas) {} | ||
|
||
void ClientContext::AddLegacyQuotas( | ||
std::vector<::istio::quota::Requirement>* quotas) const { | ||
quotas->insert(quotas->end(), legacy_quotas_.begin(), legacy_quotas_.end()); | ||
} | ||
|
||
const std::string& ClientContext::GetServiceName( | ||
const std::string& service_name) const { | ||
if (service_name.empty()) { | ||
return config_.default_destination_service(); | ||
} | ||
const auto& config_map = config_.service_configs(); | ||
auto it = config_map.find(service_name); | ||
if (it == config_map.end()) { | ||
return config_.default_destination_service(); | ||
} | ||
return service_name; | ||
} | ||
|
||
// Get the service config by the name. | ||
const ServiceConfig& ClientContext::GetServiceConfig( | ||
const std::string& service_name) const { | ||
const auto& config_map = config_.service_configs(); | ||
auto it = config_map.find(service_name); | ||
// The name should be a valid one checked by GetServiceName() | ||
GOOGLE_CHECK(it != config_map.end()); | ||
return it->second; | ||
} | ||
|
||
} // namespace http | ||
} // namespace mixer_control | ||
} // namespace istio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright 2017 Istio Authors. 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 "service_context.h" | ||
|
||
using ::istio::mixer::v1::config::client::ServiceConfig; | ||
|
||
namespace istio { | ||
namespace mixer_control { | ||
namespace http { | ||
|
||
ServiceContext::ServiceContext(std::shared_ptr<ClientContext> client_context, | ||
const ServiceConfig& config) | ||
: client_context_(client_context), service_config_(config) { | ||
// Merge client config mixer attributes. | ||
service_config_.mutable_mixer_attributes()->MergeFrom( | ||
client_context->config().mixer_attributes()); | ||
|
||
// Build quota parser | ||
for (const auto& quota : service_config_.quota_spec()) { | ||
quota_parsers_.push_back( | ||
std::move(::istio::quota::ConfigParser::Create(quota))); | ||
} | ||
} | ||
|
||
// Add static mixer attributes. | ||
void ServiceContext::AddStaticAttributes(RequestContext* request) const { | ||
if (service_config_.has_mixer_attributes()) { | ||
request->attributes.MergeFrom(service_config_.mixer_attributes()); | ||
} | ||
} | ||
|
||
// Add quota requirements from quota configs. | ||
void ServiceContext::AddQuotas(RequestContext* request) const { | ||
for (const auto& parser : quota_parsers_) { | ||
parser->GetRequirements(request->attributes, &request->quotas); | ||
} | ||
} | ||
|
||
} // namespace http | ||
} // namespace mixer_control | ||
} // namespace istio |
Oops, something went wrong.