-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Enable check cache and refactory mixer config loading #197
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* 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 "src/envoy/mixer/config.h" | ||
|
||
using ::istio::mixer_client::Attributes; | ||
|
||
namespace Http { | ||
namespace Mixer { | ||
namespace { | ||
|
||
// The Json object name for mixer-server. | ||
const std::string kJsonNameMixerServer("mixer_server"); | ||
|
||
// The Json object name for static attributes. | ||
const std::string kJsonNameMixerAttributes("mixer_attributes"); | ||
|
||
// The Json object name to specify attributes which will be forwarded | ||
// to the upstream istio proxy. | ||
const std::string kJsonNameForwardAttributes("forward_attributes"); | ||
|
||
// The Json object name for quota name and amount. | ||
const std::string kJsonNameQuotaName("quota_name"); | ||
const std::string kJsonNameQuotaAmount("quota_amount"); | ||
|
||
// The Json object name for check cache keys. | ||
const std::string kJsonNameCheckCacheKeys("check_cache_keys"); | ||
|
||
void ReadString(const Json::Object& json, const std::string& name, | ||
std::string* value) { | ||
if (json.hasObject(name)) { | ||
*value = json.getString(name); | ||
} | ||
} | ||
|
||
void ReadStringMap(const Json::Object& json, const std::string& name, | ||
std::map<std::string, std::string>* map) { | ||
if (json.hasObject(name)) { | ||
json.getObject(name)->iterate( | ||
[map](const std::string& key, const Json::Object& obj) -> bool { | ||
(*map)[key] = obj.asString(); | ||
return true; | ||
}); | ||
} | ||
} | ||
|
||
void ReadStringVector(const Json::Object& json, const std::string& name, | ||
std::vector<std::string>* value) { | ||
if (json.hasObject(name)) { | ||
auto v = json.getStringArray(name); | ||
value->swap(v); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
void MixerConfig::Load(const Json::Object& json) { | ||
ReadString(json, kJsonNameMixerServer, &mixer_server); | ||
|
||
ReadStringMap(json, kJsonNameMixerAttributes, &mixer_attributes); | ||
ReadStringMap(json, kJsonNameForwardAttributes, &forward_attributes); | ||
|
||
ReadString(json, kJsonNameQuotaName, "a_name); | ||
ReadString(json, kJsonNameQuotaAmount, "a_amount); | ||
|
||
ReadStringVector(json, kJsonNameCheckCacheKeys, &check_cache_keys); | ||
} | ||
|
||
void MixerConfig::ExtractQuotaAttributes(Attributes* attr) const { | ||
if (!quota_name.empty()) { | ||
attr->attributes[ ::istio::mixer_client::kQuotaName] = | ||
Attributes::StringValue(quota_name); | ||
|
||
int64_t amount = 1; // default amount to 1. | ||
if (!quota_amount.empty()) { | ||
amount = std::stoi(quota_amount); | ||
} | ||
attr->attributes[ ::istio::mixer_client::kQuotaAmount] = | ||
Attributes::Int64Value(amount); | ||
} | ||
} | ||
|
||
} // namespace Mixer | ||
} // namespace Http |
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,53 @@ | ||
/* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "precompiled/precompiled.h" | ||
|
||
#include "envoy/json/json_object.h" | ||
#include "include/attribute.h" | ||
|
||
namespace Http { | ||
namespace Mixer { | ||
|
||
// A config for mixer filter | ||
struct MixerConfig { | ||
// the mixer server address | ||
std::string mixer_server; | ||
|
||
// These static attributes will be send to mixer in both | ||
// Check and Report. | ||
std::map<std::string, std::string> mixer_attributes; | ||
|
||
// These attributes will be forwarded to upstream. | ||
std::map<std::string, std::string> forward_attributes; | ||
|
||
// Quota attributes. | ||
std::string quota_name; | ||
std::string quota_amount; | ||
|
||
// The attribute names for check cache. | ||
std::vector<std::string> check_cache_keys; | ||
|
||
// Load the config from envoy config. | ||
void Load(const Json::Object& json); | ||
|
||
// Extract quota attributes. | ||
void ExtractQuotaAttributes(::istio::mixer_client::Attributes* attr) const; | ||
}; | ||
|
||
} // namespace Mixer | ||
} // namespace Http |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I may lose some context here. Just wondering what is the relation between
mixer_attributes
andforward_attributes?
And why we need a standalone quota attributes?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.
mixer_attributes will be send to mixer server
forward_attributes will be forwarded to upstream so that next hop proxy can send them to mixer server.
Above attributes are for Check and Report.
Quota is a separate call. Here we use some standalone attributes to trigger the calls.
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.
Will
mixer_attributes
andforward_attributes
have overlap/different entries?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.
If they have overlapped entries, mixer_attributes win.