Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
18 changes: 7 additions & 11 deletions src/envoy/mixer/http_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,23 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info,

} // namespace

HttpControl::HttpControl(const std::string& mixer_server) {
HttpControl::HttpControl(
const std::string& mixer_server,
const std::map<std::string, std::string>&& attributes) {

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 "const"

::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;
}
config_attributes_ = std::move(attributes);

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.

do this in ":" line

}

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

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 these const string definitions. such as kEnvNameTargetService, and kAttribName


SetStringAttribute(kAttrNameSourceService, source_service_, attr);
SetStringAttribute(kAttrNameTargetService, target_service_, attr);
for (auto attribute : config_attributes_) {

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.

const auto &

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,
const 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
12 changes: 11 additions & 1 deletion src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ 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);
}
} else {
log().warn("No attributes is specified in the config: {}", __func__);

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.

Not need to log a warn, just remove the whole else {}.

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.

This needs to be extended to include upstream_cluster. @rshriram did something similar for the fault injection filter. Basically, the problem is that if you have two upstream clusters "service_a" and "service_b" in the same http connection manager (say via weighted cluster block), you need to send two different sets of attributes about "a" and "b". Maybe make "attributes" a list of JSON objects that have "upstream_cluster" and "attributes" list.

You do not have to do this in the same PR, but send a follow-up PR that allows this customization.

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.

I'm also OK with restricting mixer attributes to be same for all service versions. The drawback is that we cannot do gradual config change for the mixer attributes. The whole idea of service versions is that we can customize what set of attributes to send for a subset of the service destination pods.

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.

Open https://github.com/istio/proxy/issues/88 for first issue. Did not quite understand the second issue yet. Will open a separate issue once I understand it.

}

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