forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
RFC prototype: encode cluster meta data into upstream header #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lambdai
wants to merge
11
commits into
istiobase
Choose a base branch
from
istiohttppool
base: istiobase
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fa975bd
add files
lambdai fac35bf
extension build
lambdai 5eacb32
another sample
lambdai de8c2cf
adding generic to cluster_sensitive
lambdai 7818090
to be revert: default cluster sensitive
lambdai 6785f9a
use sub upstream
lambdai a5f75a0
to be revert
lambdai 550cbf9
make cluster_sensitive generic
lambdai fb5138d
add cluster sensitive upstream test
lambdai 0425700
fix format
lambdai ed09565
doc
lambdai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
api/envoy/extensions/upstreams/http/cluster_sensitive/v3/BUILD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
17 changes: 17 additions & 0 deletions
17
api/envoy/extensions/upstreams/http/cluster_sensitive/v3/http_connection_pool.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.upstreams.http.cluster_sensitive.v3; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.upstreams.http.cluster_sensitive.v3"; | ||
| option java_outer_classname = "HttpConnectionPoolProtoOuterClass"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Http Connection Pool] | ||
|
|
||
| // A connection pool which forwards downstream HTTP as HTTP to upstream. | ||
| // [#extension: envoy.upstreams.http.cluster_sensitive] | ||
| message HttpConnectionPoolProto { | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_extension( | ||
| name = "config", | ||
| srcs = [ | ||
| "config.cc", | ||
| ], | ||
| hdrs = [ | ||
| "config.h", | ||
| ], | ||
| security_posture = "robust_to_untrusted_downstream", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| ":upstream_request_lib", | ||
| "//source/extensions/upstreams/http/http:upstream_request_lib", | ||
| "//source/extensions/upstreams/http/tcp:upstream_request_lib", | ||
| "@envoy_api//envoy/extensions/upstreams/http/cluster_sensitive/v3:pkg_cc_proto", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "upstream_request_lib", | ||
| deps = [ | ||
| ":http_upstream_request_lib", | ||
| ":tcp_upstream_request_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "http_upstream_request_lib", | ||
| srcs = [ | ||
| "http_upstream_request.cc", | ||
| ], | ||
| hdrs = [ | ||
| "http_upstream_request.h", | ||
| ], | ||
| deps = [ | ||
| "//include/envoy/http:codes_interface", | ||
| "//include/envoy/http:conn_pool_interface", | ||
| "//include/envoy/http:filter_interface", | ||
| "//include/envoy/upstream:cluster_manager_interface", | ||
| "//include/envoy/upstream:upstream_interface", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:minimal_logger_lib", | ||
| "//source/common/http:codes_lib", | ||
| "//source/common/http:header_map_lib", | ||
| "//source/common/http:headers_lib", | ||
| "//source/common/http:message_lib", | ||
| "//source/common/network:application_protocol_lib", | ||
| "//source/common/network:transport_socket_options_lib", | ||
| "//source/common/router:router_lib", | ||
| "//source/common/upstream:load_balancer_lib", | ||
| "//source/extensions/common/proxy_protocol:proxy_protocol_header_lib", | ||
| "//source/extensions/upstreams/http/http:upstream_request_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "tcp_upstream_request_lib", | ||
| deps = [ | ||
| "//source/extensions/upstreams/http/http:upstream_request_lib", | ||
| ], | ||
| ) |
32 changes: 32 additions & 0 deletions
32
source/extensions/upstreams/http/cluster_sensitive/config.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include "extensions/upstreams/http/cluster_sensitive/config.h" | ||
|
|
||
| #include "extensions/upstreams/http/cluster_sensitive/http_upstream_request.h" | ||
| #include "extensions/upstreams/http/tcp/upstream_request.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Upstreams { | ||
| namespace Http { | ||
| namespace ClusterSensitive { | ||
|
|
||
| Router::GenericConnPoolPtr ClusterSensitiveGenericConnPoolFactory::createGenericConnPool( | ||
| Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, | ||
| absl::optional<Envoy::Http::Protocol> downstream_protocol, | ||
| Upstream::LoadBalancerContext* ctx) const { | ||
| if (is_connect) { | ||
| auto ret = std::make_unique<Upstreams::Http::Tcp::TcpConnPool>(cm, is_connect, route_entry, | ||
| downstream_protocol, ctx); | ||
| return (ret->valid() ? std::move(ret) : nullptr); | ||
| } | ||
| auto ret = std::make_unique<Upstreams::Http::ClusterSensitive::HttpConnPool>( | ||
| cm, is_connect, route_entry, downstream_protocol, ctx); | ||
| return (ret->valid() ? std::move(ret) : nullptr); | ||
| } | ||
|
|
||
| REGISTER_FACTORY(ClusterSensitiveGenericConnPoolFactory, Router::GenericConnPoolFactory); | ||
|
|
||
| } // namespace ClusterSensitive | ||
| } // namespace Http | ||
| } // namespace Upstreams | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
40 changes: 40 additions & 0 deletions
40
source/extensions/upstreams/http/cluster_sensitive/config.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/extensions/upstreams/http/cluster_sensitive/v3/http_connection_pool.pb.h" | ||
| #include "envoy/registry/registry.h" | ||
| #include "envoy/router/router.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Upstreams { | ||
| namespace Http { | ||
| namespace ClusterSensitive { | ||
|
|
||
| /** | ||
| * Config registration for the HttpConnPool. @see Router::GenericConnPoolFactory | ||
| */ | ||
| class ClusterSensitiveGenericConnPoolFactory : public Router::GenericConnPoolFactory { | ||
| public: | ||
| std::string name() const override { | ||
| return "envoy.filters.connection_pools.http.cluster_sensitive"; | ||
| } | ||
| std::string category() const override { return "envoy.upstreams"; } | ||
| Router::GenericConnPoolPtr | ||
| createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, | ||
| const Router::RouteEntry& route_entry, | ||
| absl::optional<Envoy::Http::Protocol> downstream_protocol, | ||
| Upstream::LoadBalancerContext* ctx) const override; | ||
|
|
||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
| return std::make_unique< | ||
| envoy::extensions::upstreams::http::cluster_sensitive::v3::HttpConnectionPoolProto>(); | ||
| } | ||
| }; | ||
|
|
||
| DECLARE_FACTORY(ClusterSensitiveGenericConnPoolFactory); | ||
|
|
||
| } // namespace ClusterSensitive | ||
| } // namespace Http | ||
| } // namespace Upstreams | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
75 changes: 75 additions & 0 deletions
75
source/extensions/upstreams/http/cluster_sensitive/http_upstream_request.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #include "extensions/upstreams/http/cluster_sensitive/http_upstream_request.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
|
|
||
| #include "envoy/event/dispatcher.h" | ||
| #include "envoy/event/timer.h" | ||
| #include "envoy/grpc/status.h" | ||
| #include "envoy/http/conn_pool.h" | ||
| #include "envoy/upstream/cluster_manager.h" | ||
| #include "envoy/upstream/upstream.h" | ||
|
|
||
| #include "common/common/assert.h" | ||
| #include "common/common/utility.h" | ||
| #include "common/http/codes.h" | ||
| #include "common/http/header_map_impl.h" | ||
| #include "common/http/headers.h" | ||
| #include "common/http/message_impl.h" | ||
| #include "common/http/utility.h" | ||
| #include "common/router/router.h" | ||
|
|
||
| using Envoy::Router::GenericConnectionPoolCallbacks; | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Upstreams { | ||
| namespace Http { | ||
| namespace ClusterSensitive { | ||
|
|
||
| void HttpConnPool::newStream(GenericConnectionPoolCallbacks* callbacks) { | ||
| callbacks_ = callbacks; | ||
| // It's possible for a reset to happen inline within the newStream() call. In this case, we | ||
| // might get deleted inline as well. Only write the returned handle out if it is not nullptr to | ||
| // deal with this case. | ||
| Envoy::Http::ConnectionPool::Cancellable* handle = | ||
| conn_pool_->newStream(callbacks->upstreamToDownstream(), *this); | ||
| if (handle) { | ||
| conn_pool_stream_handle_ = handle; | ||
| } | ||
| } | ||
|
|
||
| bool HttpConnPool::cancelAnyPendingStream() { | ||
| if (conn_pool_stream_handle_) { | ||
| conn_pool_stream_handle_->cancel(ConnectionPool::CancelPolicy::Default); | ||
| conn_pool_stream_handle_ = nullptr; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| absl::optional<Envoy::Http::Protocol> HttpConnPool::protocol() const { | ||
| return conn_pool_->protocol(); | ||
| } | ||
|
|
||
| void HttpConnPool::onPoolFailure(ConnectionPool::PoolFailureReason reason, | ||
| absl::string_view transport_failure_reason, | ||
| Upstream::HostDescriptionConstSharedPtr host) { | ||
| callbacks_->onPoolFailure(reason, transport_failure_reason, host); | ||
| } | ||
|
|
||
| void HttpConnPool::onPoolReady(Envoy::Http::RequestEncoder& request_encoder, | ||
| Upstream::HostDescriptionConstSharedPtr host, | ||
| const StreamInfo::StreamInfo& info) { | ||
| conn_pool_stream_handle_ = nullptr; | ||
| auto upstream = | ||
| std::make_unique<HttpUpstream>(callbacks_->upstreamToDownstream(), &request_encoder, host); | ||
| callbacks_->onPoolReady(std::move(upstream), host, | ||
| request_encoder.getStream().connectionLocalAddress(), info); | ||
| } | ||
|
|
||
| } // namespace ClusterSensitive | ||
| } // namespace Http | ||
| } // namespace Upstreams | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
110 changes: 110 additions & 0 deletions
110
source/extensions/upstreams/http/cluster_sensitive/http_upstream_request.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "envoy/http/codes.h" | ||
| #include "envoy/http/conn_pool.h" | ||
|
|
||
| #include "common/common/logger.h" | ||
| #include "common/config/well_known_names.h" | ||
| #include "common/http/header_map_impl.h" | ||
| #include "common/router/upstream_request.h" | ||
|
|
||
| #include "extensions/upstreams/http/http/upstream_request.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Upstreams { | ||
| namespace Http { | ||
| namespace ClusterSensitive { | ||
|
|
||
| class HttpConnPool : public Router::GenericConnPool, public Envoy::Http::ConnectionPool::Callbacks { | ||
| public: | ||
| // GenericConnPool | ||
| HttpConnPool(Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, | ||
| absl::optional<Envoy::Http::Protocol> downstream_protocol, | ||
| Upstream::LoadBalancerContext* ctx) { | ||
| ASSERT(!is_connect); | ||
| conn_pool_ = cm.httpConnPoolForCluster(route_entry.clusterName(), route_entry.priority(), | ||
| downstream_protocol, ctx); | ||
| } | ||
| void newStream(Router::GenericConnectionPoolCallbacks* callbacks) override; | ||
| bool cancelAnyPendingStream() override; | ||
| absl::optional<Envoy::Http::Protocol> protocol() const override; | ||
|
|
||
| // Http::ConnectionPool::Callbacks | ||
| void onPoolFailure(ConnectionPool::PoolFailureReason reason, | ||
| absl::string_view transport_failure_reason, | ||
| Upstream::HostDescriptionConstSharedPtr host) override; | ||
| void onPoolReady(Envoy::Http::RequestEncoder& callbacks_encoder, | ||
| Upstream::HostDescriptionConstSharedPtr host, | ||
| const StreamInfo::StreamInfo& info) override; | ||
| Upstream::HostDescriptionConstSharedPtr host() const override { return conn_pool_->host(); } | ||
|
|
||
| bool valid() { return conn_pool_ != nullptr; } | ||
|
|
||
| private: | ||
| // Points to the actual connection pool to create streams from. | ||
| Envoy::Http::ConnectionPool::Instance* conn_pool_{}; | ||
| Envoy::Http::ConnectionPool::Cancellable* conn_pool_stream_handle_{}; | ||
| Router::GenericConnectionPoolCallbacks* callbacks_{}; | ||
| }; | ||
|
|
||
| class HttpUpstream : public Router::GenericUpstream { | ||
| public: | ||
| HttpUpstream(Router::UpstreamToDownstream& upstream_request, Envoy::Http::RequestEncoder* encoder, | ||
| Upstream::HostDescriptionConstSharedPtr host) | ||
| : sub_upstream_(upstream_request, encoder), host_(host) {} | ||
|
|
||
| // GenericUpstream | ||
| void encodeData(Buffer::Instance& data, bool end_stream) override { | ||
| sub_upstream_.encodeData(data, end_stream); | ||
| } | ||
|
|
||
| void encodeMetadata(const Envoy::Http::MetadataMapVector& metadata_map_vector) override { | ||
| sub_upstream_.encodeMetadata(metadata_map_vector); | ||
| } | ||
|
|
||
| void encodeHeaders(const Envoy::Http::RequestHeaderMap& headers, bool end_stream) override { | ||
| auto dup = Envoy::Http::RequestHeaderMapImpl::create(); | ||
| Envoy::Http::HeaderMapImpl::copyFrom(*dup, headers); | ||
| dup->setCopy(Envoy::Http::LowerCaseString("X-istio-test"), "lambdai"); | ||
| // Sanitize original port header. | ||
| dup->remove(Envoy::Http::LowerCaseString("X-istio-original-port")); | ||
| if (auto filter_metadata = host_->cluster().metadata().filter_metadata().find("istio"); | ||
| filter_metadata != host_->cluster().metadata().filter_metadata().end()) { | ||
| ENVOY_LOG_MISC(warn, "lambdai: find filter_metadata from {}", | ||
| host_->cluster().metadata().DebugString()); | ||
| const ProtobufWkt::Struct& data_struct = filter_metadata->second; | ||
| const auto& fields = data_struct.fields(); | ||
| if (auto iter = fields.find("original_port"); iter != fields.end()) { | ||
| if (iter->second.kind_case() == ProtobufWkt::Value::kStringValue) { | ||
| dup->setCopy(Envoy::Http::LowerCaseString("X-istio-original-port"), | ||
| iter->second.string_value()); | ||
| } | ||
| } | ||
| } | ||
| sub_upstream_.encodeHeaders(*dup, end_stream); | ||
| } | ||
|
|
||
| void encodeTrailers(const Envoy::Http::RequestTrailerMap& trailers) override { | ||
| sub_upstream_.encodeTrailers(trailers); | ||
| } | ||
|
|
||
| void readDisable(bool disable) override { sub_upstream_.readDisable(disable); } | ||
|
|
||
| void resetStream() override { sub_upstream_.resetStream(); } | ||
|
|
||
| private: | ||
| Upstreams::Http::Http::HttpUpstream sub_upstream_; | ||
| Upstream::HostDescriptionConstSharedPtr host_{}; | ||
| }; | ||
|
|
||
| } // namespace ClusterSensitive | ||
| } // namespace Http | ||
| } // namespace Upstreams | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark