-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: create SocketSelectionFilter (#1797)
Description: Removes network-specific clusters and replaces with a filter that sets unique socket options based on current preferred network (via Reachability) status. Envoy internally creates a different socket pool for a unique set of socket options, so the effect of this is that we still use different sets of connections per interface, but no longer rely on a large set of clusters to do so. This PR also lays the groundwork for us to experiment with interface-bound sockets. Risk Level: High Testing: Existing unit and integration coverage Signed-off-by: Mike Schore <[email protected]> Signed-off-by: JP Simard <[email protected]>
- Loading branch information
Showing
22 changed files
with
283 additions
and
264 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
48 changes: 48 additions & 0 deletions
48
mobile/library/common/extensions/filters/http/socket_selection/BUILD
This file contains 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,48 @@ | ||
load( | ||
"@envoy//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_extension_package", | ||
"envoy_proto_library", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_proto_library( | ||
name = "filter", | ||
srcs = ["filter.proto"], | ||
) | ||
|
||
envoy_cc_extension( | ||
name = "socket_selection_filter_lib", | ||
srcs = ["filter.cc"], | ||
hdrs = ["filter.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
":filter_cc_proto", | ||
"//library/common/http:internal_headers_lib", | ||
"//library/common/network:mobile_utility_lib", | ||
"//library/common/types:c_types_lib", | ||
"@envoy//envoy/http:codes_interface", | ||
"@envoy//envoy/http:filter_interface", | ||
"@envoy//source/common/grpc:common_lib", | ||
"@envoy//source/common/grpc:status_lib", | ||
"@envoy//source/common/http:codes_lib", | ||
"@envoy//source/common/http:header_map_lib", | ||
"@envoy//source/common/http:headers_lib", | ||
"@envoy//source/common/http:utility_lib", | ||
"@envoy//source/extensions/filters/http/common:pass_through_filter_lib", | ||
], | ||
) | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
":socket_selection_filter_lib", | ||
"@envoy//source/extensions/filters/http/common:factory_base_lib", | ||
], | ||
) |
27 changes: 27 additions & 0 deletions
27
mobile/library/common/extensions/filters/http/socket_selection/config.cc
This file contains 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,27 @@ | ||
#include "library/common/extensions/filters/http/socket_selection/config.h" | ||
|
||
#include "library/common/extensions/filters/http/socket_selection/filter.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace SocketSelection { | ||
|
||
Http::FilterFactoryCb SocketSelectionFilterFactory::createFilterFactoryFromProtoTyped( | ||
const envoymobile::extensions::filters::http::socket_selection::SocketSelection&, | ||
const std::string&, Server::Configuration::FactoryContext&) { | ||
|
||
return [](Http::FilterChainFactoryCallbacks& callbacks) -> void { | ||
callbacks.addStreamFilter(std::make_shared<SocketSelectionFilter>()); | ||
}; | ||
} | ||
|
||
/** | ||
* Static registration for the SocketSelection filter. @see NamedHttpFilterConfigFactory. | ||
*/ | ||
REGISTER_FACTORY(SocketSelectionFilterFactory, Server::Configuration::NamedHttpFilterConfigFactory); | ||
|
||
} // namespace SocketSelection | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
33 changes: 33 additions & 0 deletions
33
mobile/library/common/extensions/filters/http/socket_selection/config.h
This file contains 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,33 @@ | ||
#include <string> | ||
|
||
#include "source/extensions/filters/http/common/factory_base.h" | ||
|
||
#include "library/common/extensions/filters/http/socket_selection/filter.pb.h" | ||
#include "library/common/extensions/filters/http/socket_selection/filter.pb.validate.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace SocketSelection { | ||
|
||
/** | ||
* Config registration for the socket_selection filter. @see NamedHttpFilterConfigFactory. | ||
*/ | ||
class SocketSelectionFilterFactory | ||
: public Common::FactoryBase< | ||
envoymobile::extensions::filters::http::socket_selection::SocketSelection> { | ||
public: | ||
SocketSelectionFilterFactory() : FactoryBase("socket_selection") {} | ||
|
||
private: | ||
::Envoy::Http::FilterFactoryCb createFilterFactoryFromProtoTyped( | ||
const envoymobile::extensions::filters::http::socket_selection::SocketSelection& config, | ||
const std::string& stats_prefix, Server::Configuration::FactoryContext& context) override; | ||
}; | ||
|
||
DECLARE_FACTORY(SocketSelectionFilterFactory); | ||
|
||
} // namespace SocketSelection | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
27 changes: 27 additions & 0 deletions
27
mobile/library/common/extensions/filters/http/socket_selection/filter.cc
This file contains 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,27 @@ | ||
#include "library/common/extensions/filters/http/socket_selection/filter.h" | ||
|
||
#include "envoy/server/filter_config.h" | ||
|
||
#include "library/common/network/mobile_utility.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace SocketSelection { | ||
|
||
Http::FilterHeadersStatus SocketSelectionFilter::decodeHeaders(Http::RequestHeaderMap&, bool) { | ||
ENVOY_LOG(debug, "SocketSelectionFilter::decodeHeaders"); | ||
|
||
envoy_network_t network = Network::MobileUtility::getPreferredNetwork(); | ||
ENVOY_LOG(debug, "current preferred network: {}", network); | ||
|
||
auto connection_options = Network::MobileUtility::getUpstreamSocketOptions(network); | ||
decoder_callbacks_->addUpstreamSocketOptions(connection_options); | ||
|
||
return Http::FilterHeadersStatus::Continue; | ||
} | ||
|
||
} // namespace SocketSelection | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
30 changes: 30 additions & 0 deletions
30
mobile/library/common/extensions/filters/http/socket_selection/filter.h
This file contains 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,30 @@ | ||
#pragma once | ||
|
||
#include "envoy/http/filter.h" | ||
|
||
#include "source/common/common/logger.h" | ||
#include "source/extensions/filters/http/common/pass_through_filter.h" | ||
|
||
#include "library/common/extensions/filters/http/socket_selection/filter.pb.h" | ||
#include "library/common/types/c_types.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace SocketSelection { | ||
|
||
/** | ||
* Filter to set upstream socket options based on network conditions. | ||
*/ | ||
class SocketSelectionFilter final : public Http::PassThroughFilter, | ||
public Logger::Loggable<Logger::Id::filter> { | ||
public: | ||
// Http::StreamDecoderFilter | ||
Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap& headers, | ||
bool end_stream) override; | ||
}; | ||
|
||
} // namespace SocketSelection | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
6 changes: 6 additions & 0 deletions
6
mobile/library/common/extensions/filters/http/socket_selection/filter.proto
This file contains 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,6 @@ | ||
syntax = "proto3"; | ||
|
||
package envoymobile.extensions.filters.http.socket_selection; | ||
|
||
message SocketSelection { | ||
} |
This file contains 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
Oops, something went wrong.