Skip to content

Commit

Permalink
Get attributes from envoy config. (envoyproxy#87)
Browse files Browse the repository at this point in the history
* Send all attributes.

* Remove unused const strings.

* Address comment.
  • Loading branch information
chowchow316 authored Feb 14, 2017
1 parent 88cfb24 commit d5a878a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
24 changes: 6 additions & 18 deletions src/envoy/mixer/http_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const std::string kAttrNameResponseTime = "response.time";
const std::string kAttrNameOriginIp = "origin.ip";
const std::string kAttrNameOriginHost = "origin.host";

const std::string kEnvNameSourceService = "SOURCE_SERVICE";
const std::string kEnvNameTargetService = "TARGET_SERVICE";

const std::string kAttrNameSourceService = "source.service";
const std::string kAttrNameTargetService = "target.service";

Attributes::Value StringValue(const std::string& str) {
Attributes::Value v;
v.type = Attributes::Value::STRING;
Expand Down Expand Up @@ -134,27 +128,21 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info,

} // namespace

HttpControl::HttpControl(const std::string& mixer_server) {
HttpControl::HttpControl(const std::string& mixer_server,
std::map<std::string, std::string>&& attributes)
: config_attributes_(std::move(attributes)) {
::istio::mixer_client::MixerClientOptions options;
options.mixer_server = mixer_server;
mixer_client_ = ::istio::mixer_client::CreateMixerClient(options);

auto source_service = getenv(kEnvNameSourceService.c_str());
if (source_service) {
source_service_ = source_service;
}
auto target_service = getenv(kEnvNameTargetService.c_str());
if (target_service) {
target_service_ = target_service;
}
}

void HttpControl::FillCheckAttributes(const HeaderMap& header_map,
Attributes* attr) {
FillRequestHeaderAttributes(header_map, attr);

SetStringAttribute(kAttrNameSourceService, source_service_, attr);
SetStringAttribute(kAttrNameTargetService, target_service_, attr);
for (const auto& attribute : config_attributes_) {
SetStringAttribute(attribute.first, attribute.second, attr);
}
}

void HttpControl::Check(HttpRequestDataPtr request_data, HeaderMap& headers,
Expand Down
9 changes: 4 additions & 5 deletions src/envoy/mixer/http_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ typedef std::shared_ptr<HttpRequestData> HttpRequestDataPtr;
class HttpControl final : public Logger::Loggable<Logger::Id::http> {
public:
// The constructor.
HttpControl(const std::string& mixer_server);
HttpControl(const std::string& mixer_server,
std::map<std::string, std::string>&& attributes);

// Make mixer check call.
void Check(HttpRequestDataPtr request_data, HeaderMap& headers,
Expand All @@ -55,10 +56,8 @@ class HttpControl final : public Logger::Loggable<Logger::Id::http> {

// The mixer client
std::unique_ptr<::istio::mixer_client::MixerClient> mixer_client_;
// Source service
std::string source_service_;
// Target service
std::string target_service_;
// The attributes read from the config file.
std::map<std::string, std::string> config_attributes_;
};

} // namespace Mixer
Expand Down
10 changes: 9 additions & 1 deletion src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ class Config : public Logger::Loggable<Logger::Id::http> {
__func__);
}

http_control_ = std::make_shared<HttpControl>(mixer_server);
std::map<std::string, std::string> attributes;
if (config.hasObject("attributes")) {
for (const std::string& attr : config.getStringArray("attributes")) {
attributes[attr] = config.getString(attr);
}
}

http_control_ =
std::make_shared<HttpControl>(mixer_server, std::move(attributes));
log().debug("Called Mixer::Config contructor with mixer_server: ",
mixer_server);
}
Expand Down

0 comments on commit d5a878a

Please sign in to comment.