Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 4 additions & 9 deletions src/envoy/mixer/http_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,14 @@ 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) {
::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;
}
source_service_ = attributes.at(kAttrNameTargetService);

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.

keep the map in the class member.

// the attributes read from the config file.
std::map<std::string, std::string>& config_attributes_;

In the Check() call, set all of them to the attributes data structure.

target_service_ = attributes.at(kAttrNameSourceService);
}

void HttpControl::FillCheckAttributes(const HeaderMap& header_map,
Expand Down
3 changes: 2 additions & 1 deletion 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);

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.

use

std::map<std::string, std::string>&& attributes

call it by std::move()

to reduce a copy


// Make mixer check call.
void Check(HttpRequestDataPtr request_data, HeaderMap& headers,
Expand Down
11 changes: 10 additions & 1 deletion src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ 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, attributes);
log().debug("Called Mixer::Config contructor with mixer_server: ",
mixer_server);
}
Expand Down