Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion include/istio/utils/attributes_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
namespace istio {
namespace utils {

const char kMixerMetadataKey[] = "istio.mixer";

// Builder class to add attribute to protobuf Attributes.
// Its usage:
// builder(attribute).Add("key", value)
Expand Down Expand Up @@ -142,7 +144,9 @@ class AttributesBuilder {
}

for (const auto &filter : filter_state) {
AddProtoStructStringMap(filter.first, filter.second);
if (FiltersToIgnore().find(filter.first) == FiltersToIgnore().end()) {
AddProtoStructStringMap(filter.first, filter.second);
}
}
}

Expand All @@ -152,6 +156,12 @@ class AttributesBuilder {
}

private:
const std::unordered_set<std::string> &FiltersToIgnore() {
static const auto *filters =
new std::unordered_set<std::string>{kMixerMetadataKey};
return *filters;
}

::istio::mixer::v1::Attributes *attributes_;
};

Expand Down
5 changes: 2 additions & 3 deletions src/envoy/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "src/envoy/utils/utils.h"
#include "include/istio/utils/attributes_builder.h"
#include "mixer/v1/attributes.pb.h"

using ::google::protobuf::Message;
Expand Down Expand Up @@ -142,16 +143,14 @@ Status ParseJsonMessage(const std::string& json, Message* output) {
void CheckResponseInfoToStreamInfo(
const istio::mixerclient::CheckResponseInfo& check_response,
StreamInfo::StreamInfo& stream_info) {
static std::string metadata_key = "istio.mixer";

if (!check_response.response_status.ok()) {
stream_info.setResponseFlag(
StreamInfo::ResponseFlag::UnauthorizedExternalService);
ProtobufWkt::Struct metadata;
auto& fields = *metadata.mutable_fields();
fields["status"].set_string_value(
check_response.response_status.ToString());
stream_info.setDynamicMetadata(metadata_key, metadata);
stream_info.setDynamicMetadata(istio::utils::kMixerMetadataKey, metadata);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ TEST(AttributesBuilderTest, TestReportAttributes) {
listval.mutable_list_value()->add_values()->set_string_value("c");
(*struct_obj.mutable_fields())["list"] = listval;
filter_metadata["foo.bar.com"] = struct_obj;
filter_metadata["istio.mixer"] = struct_obj; // to be ignored

EXPECT_CALL(mock_data, GetDestinationIpPort(_, _))
.WillOnce(Invoke([](std::string *ip, int *port) -> bool {
Expand Down
1 change: 1 addition & 0 deletions src/istio/control/tcp/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ TEST(AttributesBuilderTest, TestReportAttributes) {
listval.mutable_list_value()->add_values()->set_string_value("c");
(*struct_obj.mutable_fields())["list"] = listval;
filter_metadata["foo.bar.com"] = struct_obj;
filter_metadata["istio.mixer"] = struct_obj; // to be ignored

EXPECT_CALL(mock_data, GetDestinationIpPort(_, _))
.Times(4)
Expand Down