Skip to content

Commit

Permalink
mixer: add hash policy for maglev (envoyproxy#2456)
Browse files Browse the repository at this point in the history
* add hash policy for mixer

Signed-off-by: Kuat Yessenov <kuat@google.com>

* fix test

Signed-off-by: Kuat Yessenov <kuat@google.com>

* name the workspace

Signed-off-by: Kuat Yessenov <kuat@google.com>

* update upstream

Signed-off-by: Kuat Yessenov <kuat@google.com>

* fix tests

Signed-off-by: Kuat Yessenov <kuat@google.com>
  • Loading branch information
kyessenov authored and istio-testing committed Oct 11, 2019
1 parent def0974 commit 3781be0
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 23 deletions.
7 changes: 4 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
################################################################################
#
workspace(name = "io_istio_proxy")

# http_archive is not a native function since bazel 0.19
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand All @@ -35,10 +36,10 @@ bind(
# 1. Determine SHA256 `wget https://github.com/envoyproxy/envoy-wasm/archive/$COMMIT.tar.gz && sha256sum $COMMIT.tar.gz`
# 2. Update .bazelrc and .bazelversion files.
#
# envoy-wasm commit date: 10/09/2019
ENVOY_SHA = "ec03328688895d99c9f5ae4fd7f8459ef3e95212"
# envoy-wasm commit date: 10/11/2019
ENVOY_SHA = "29b71643c999af4e31ba86d41740edbef71c73fe"

ENVOY_SHA256 = "4abf05fd040b56af630b624068d462035bd986bccf775f821b755fd3c0df8083"
ENVOY_SHA256 = "2a29684ebc13736eb012e0aaaedc08860ddfdb07dec55f37c7e9a100a4bcd7f3"

LOCAL_ENVOY_PROJECT = "/PATH/TO/ENVOY"

Expand Down
2 changes: 1 addition & 1 deletion include/istio/control/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ cc_library(
"request_handler.h",
],
visibility = ["//visibility:public"],
deps = ["//src/istio/authn:context_proto_cc"],
deps = ["//src/istio/authn:context_proto_cc_proto"],
)
6 changes: 3 additions & 3 deletions src/envoy/http/authn/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ envoy_cc_library(
"//src/envoy/http/jwt_auth:jwt_lib",
"//src/envoy/utils:filter_names_lib",
"//src/envoy/utils:utils_lib",
"//src/istio/authn:context_proto_cc",
"//src/istio/authn:context_proto_cc_proto",
],
)

Expand All @@ -66,7 +66,7 @@ envoy_cc_library(
"//src/envoy/utils:authn_lib",
"//src/envoy/utils:filter_names_lib",
"//src/envoy/utils:utils_lib",
"//src/istio/authn:context_proto_cc",
"//src/istio/authn:context_proto_cc_proto",
"@envoy//source/exe:envoy_common_lib",
],
)
Expand All @@ -76,7 +76,7 @@ envoy_cc_test_library(
hdrs = ["test_utils.h"],
repository = "@envoy",
deps = [
"//src/istio/authn:context_proto_cc",
"//src/istio/authn:context_proto_cc_proto",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* limitations under the License.
*/

#include <fstream>
#include <iostream>

#include "test/integration/http_integration.h"
#include "test/integration/utility.h"

Expand Down Expand Up @@ -51,7 +54,37 @@ class JwtVerificationFilterIntegrationTest
0, FakeHttpConnection::Type::HTTP1, version_, timeSystem()));
registerPort("upstream_1",
fake_upstreams_.back()->localAddress()->ip()->port());
createTestServer(ConfigPath(), {"http"});

// upstream envoy hardcodes workspace name, so this code is duplicated
const std::string path = ConfigPath();
const std::string json_path =
TestEnvironment::runfilesPath(path, "io_istio_proxy");
std::string out_json_string =
TestEnvironment::readFileToStringForTest(json_path);

// Substitute ports.
for (const auto& it : port_map_) {
const std::regex port_regex("\\{\\{ " + it.first + " \\}\\}");
out_json_string = std::regex_replace(out_json_string, port_regex,
std::to_string(it.second));
}

// Substitute paths and other common things.
out_json_string = TestEnvironment::substitute(out_json_string, version_);

const std::string extension =
absl::EndsWith(path, ".yaml") ? ".yaml" : ".json";
const std::string out_json_path =
TestEnvironment::temporaryPath(path + ".with.ports" + extension);
TestEnvironment::createParentPath(out_json_path);
{
std::ofstream out_json_file(out_json_path);
out_json_file << out_json_string;
}

test_server_ =
createIntegrationTestServer(out_json_path, nullptr, timeSystem());
registerTestServerPorts({"http"});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/envoy/http/mixer/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Filter::ReadPerRouteConfig(

FilterHeadersStatus Filter::decodeHeaders(HeaderMap& headers, bool) {
ENVOY_LOG(debug, "Called Mixer::Filter : {}", __func__);
request_total_size_ += headers.byteSize();
request_total_size_ += headers.refreshByteSize();

::istio::control::http::Controller::PerRouteConfig config;
auto route = decoder_callbacks_->route();
Expand Down Expand Up @@ -103,7 +103,7 @@ FilterDataStatus Filter::decodeData(Buffer::Instance& data, bool end_stream) {

FilterTrailersStatus Filter::decodeTrailers(HeaderMap& trailers) {
ENVOY_LOG(debug, "Called Mixer::Filter : {}", __func__);
request_total_size_ += trailers.byteSize();
request_total_size_ += trailers.refreshByteSize();
if (state_ == Calling) {
return FilterTrailersStatus::StopIteration;
}
Expand Down
8 changes: 6 additions & 2 deletions src/envoy/http/mixer/report_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ class ReportData : public ::istio::control::http::ReportData,
response_total_size_(info.bytesSent()),
request_total_size_(request_total_size) {
if (response_headers != nullptr) {
response_total_size_ += response_headers->byteSize();
response_total_size_ +=
(response_headers->byteSize() ? response_headers->byteSize().value()
: response_headers->byteSizeInternal());
}
if (response_trailers != nullptr) {
response_total_size_ += response_trailers->byteSize();
response_total_size_ += (response_trailers->byteSize()
? response_trailers->byteSize().value()
: response_trailers->byteSizeInternal());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/envoy/utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ envoy_cc_library(
":filter_names_lib",
":utils_lib",
"//include/istio/utils:attribute_names_header",
"//src/istio/authn:context_proto_cc",
"//src/istio/authn:context_proto_cc_proto",
"//src/istio/utils:attribute_names_lib",
"//src/istio/utils:utils_lib",
"@envoy//source/exe:envoy_common_lib",
Expand Down
16 changes: 12 additions & 4 deletions src/envoy/utils/grpc_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ GrpcTransport<RequestType, ResponseType>::GrpcTransport(
: async_client_(std::move(async_client)),
response_(response),
serialized_forward_attributes_(serialized_forward_attributes),
on_done_(on_done),
request_(async_client_->send(
descriptor(), request, *this, parent_span,
absl::optional<std::chrono::milliseconds>(kGrpcRequestTimeoutMs))) {
on_done_(on_done) {
ENVOY_LOG(debug, "Sending {} request: {}", descriptor().name(),
request.DebugString());
Envoy::Http::AsyncClient::RequestOptions options;
options.setTimeout(kGrpcRequestTimeoutMs);
Protobuf::RepeatedPtrField<envoy::api::v2::route::RouteAction::HashPolicy>
hash_policy;
hash_policy.Add()->mutable_header()->set_header_name(
kIstioAttributeHeader.get());
hash_policy.Add()->mutable_header()->set_header_name(
Envoy::Http::Headers::get().Host.get());
options.setHashPolicy(hash_policy);
request_ =
async_client_->send(descriptor(), request, *this, parent_span, options);
}

template <class RequestType, class ResponseType>
Expand Down
2 changes: 1 addition & 1 deletion src/istio/control/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cc_library(
deps = [
"//include/istio/control/http:headers_lib",
"//include/istio/utils:attribute_names_header",
"//src/istio/authn:context_proto_cc",
"//src/istio/authn:context_proto_cc_proto",
"//src/istio/control:common_lib",
"//src/istio/utils:attribute_names_lib",
"//src/istio/utils:utils_lib",
Expand Down
6 changes: 4 additions & 2 deletions test/integration/int_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class Http1ClientConnection : public ClientConnection {
dispatcher),
stats_(),
network_connection_(std::move(network_connection)),
http_connection_(*network_connection_, stats_, *this),
http_connection_(*network_connection_, stats_, *this,
Envoy::Http::DEFAULT_MAX_HEADERS_COUNT),
read_filter_{std::make_shared<HttpClientReadFilter>(client.name(), id,
http_connection_)} {
network_connection_->addReadFilter(read_filter_);
Expand Down Expand Up @@ -297,7 +298,8 @@ class Http2ClientConnection : public ClientConnection {
settings_(),
network_connection_(std::move(network_connection)),
http_connection_(*network_connection_, *this, stats_, settings_,
max_request_headers_kb),
max_request_headers_kb,
Envoy::Http::DEFAULT_MAX_HEADERS_COUNT),
read_filter_{std::make_shared<HttpClientReadFilter>(client.name(), id,
http_connection_)} {
network_connection_->addReadFilter(read_filter_);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/int_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ ServerConnection::ServerConnection(
http_connection_ =
std::make_unique<Envoy::Http::Http1::ServerConnectionImpl>(
network_connection, scope, *this, Envoy::Http::Http1Settings(),
max_request_headers_kb);
max_request_headers_kb, Envoy::Http::DEFAULT_MAX_HEADERS_COUNT);
break;
case Envoy::Http::CodecClient::Type::HTTP2: {
Envoy::Http::Http2Settings settings;
Expand All @@ -320,7 +320,7 @@ ServerConnection::ServerConnection(
http_connection_ =
std::make_unique<Envoy::Http::Http2::ServerConnectionImpl>(
network_connection, *this, scope, settings,
max_request_headers_kb);
max_request_headers_kb, Envoy::Http::DEFAULT_MAX_HEADERS_COUNT);
} break;
default:
ENVOY_LOG(error,
Expand All @@ -330,7 +330,7 @@ ServerConnection::ServerConnection(
http_connection_ =
std::make_unique<Envoy::Http::Http1::ServerConnectionImpl>(
network_connection, scope, *this, Envoy::Http::Http1Settings(),
max_request_headers_kb);
max_request_headers_kb, Envoy::Http::DEFAULT_MAX_HEADERS_COUNT);
break;
}
}
Expand Down

0 comments on commit 3781be0

Please sign in to comment.