-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
network: add socket interface factory and config option #11630
Changes from 3 commits
388d1f9
c241e44
cc4d075
d77b0a9
fdd0e2f
1ca8153
6c34d86
0f300c8
3612cfa
af294af
43805c8
a02aa41
b622854
bd1a63d
f9cc098
97368af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
package envoy.config.core.v3; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.core.v3"; | ||
option java_outer_classname = "DefaultSocketInterfaceProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Default Socket Interface configuration] | ||
// Configuration for default socket interface that relies on OS dependent syscall to create | ||
// sockets. | ||
// [#extension: envoy.config.core] | ||
|
||
message DefaultSocketInterface { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.core.v3; | ||
|
||
import "envoy/config/core/v3/extension.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.core.v3"; | ||
option java_outer_classname = "SocketInterfacesProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Socket Interfaces Configuration ] | ||
|
||
// Used to select the socket interface implementation to use | ||
message SocketInterfacesConfig { | ||
// Addition socket interfaces to initialize | ||
repeated TypedExtensionConfig custom_types = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document how the name or type URL of these extensions is significant and used during resolution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Let me know if it's not clear. |
||
|
||
// Override default socket interface | ||
TypedExtensionConfig custom_default_type = 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this just be a string? I.e. the extension config is above, this is just specifying some entry in it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/typed_config.h" | ||
#include "envoy/network/socket.h" | ||
#include "envoy/registry/registry.h" | ||
|
||
#include "common/singleton/threadsafe_singleton.h" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
||
class SocketInterfaceFactory : public virtual Config::TypedFactory { | ||
public: | ||
virtual SocketInterfacePtr createSocketInterface(const Protobuf::Message& config) PURE; | ||
std::string category() const override { return "envoy.config.core.socket_interface"; } | ||
}; | ||
|
||
class DefaultSocketInterfaceFactory : public SocketInterfaceFactory { | ||
public: | ||
SocketInterfacePtr createSocketInterface(const Protobuf::Message& config) override; | ||
ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
std::string name() const override { return "envoy.config.core.default_socket_interface"; } | ||
}; | ||
|
||
DECLARE_FACTORY(DefaultSocketInterfaceFactory); | ||
|
||
using SocketInterfacesMap = absl::flat_hash_map<std::string, SocketInterfacePtr>; | ||
using SocketInterfacesSingleton = InjectableSingleton<SocketInterfacesMap>; | ||
|
||
static inline const SocketInterface* socketInterface(std::string name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to be used to find the right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the registry basically provide this? (type_url -> factory) I'm probably missing why we need to redo this type of stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way I set this up, and maybe that's not what we want, is: typed_config is handed off to If there's a nicer way this could be done with type_url, point me to an example and I'll try to follow it (still have a lot of things to learn :-() . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will defer to @lizan and @kyessenov who have more experience with the factory, but I'm wondering if we could change it slightly so the registered factory just spits out sockets and then we would just look up the factory by type_url? |
||
auto it = SocketInterfacesSingleton::get().find(name); | ||
if (it == SocketInterfacesSingleton::get().end()) { | ||
return nullptr; | ||
} | ||
return it->second.get(); | ||
} | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#include "common/network/socket_interface_impl.h" | ||
|
||
#include "envoy/common/exception.h" | ||
#include "envoy/config/core/v3/default_socket_interface.pb.h" | ||
#include "envoy/network/socket.h" | ||
|
||
#include "common/api/os_sys_calls_impl.h" | ||
#include "common/network/address_impl.h" | ||
#include "common/network/io_socket_handle_impl.h" | ||
#include "common/network/socket_interface_factory.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
@@ -80,6 +82,16 @@ bool SocketInterfaceImpl::ipFamilySupported(int domain) { | |
return SOCKET_VALID(result.rc_); | ||
} | ||
|
||
SocketInterfacePtr DefaultSocketInterfaceFactory::createSocketInterface(const Protobuf::Message&) { | ||
return std::make_unique<SocketInterfaceImpl>(); | ||
} | ||
|
||
ProtobufTypes::MessagePtr DefaultSocketInterfaceFactory::createEmptyConfigProto() { | ||
return std::make_unique<envoy::config::core::v3::DefaultSocketInterface>(); | ||
} | ||
|
||
REGISTER_FACTORY(DefaultSocketInterfaceFactory, SocketInterfaceFactory); | ||
|
||
static SocketInterfaceLoader* socket_interface_ = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we do this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely a good point but if tests are run without the server being properly initialized, the Should we maybe statically initialize the singleton to the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out integration:hotrestart_test, integration:run_envoy_test and test:router_tool_test still fail :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah I think that's good way to do test. OTOH, if this causes a lot churn, we can do static registration here, then let's not do factory registration for default interface. Because even they're configured through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because we do some network related things early on, before initializing the server, (e.g., call
Do you mean to keep the global static registration in As for the factory registration, here's the weird use case I came up with: people may want to configure a different default but may still want to configure addresses to use what we now call Tying this to your first suggestion: we could maybe do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Either works for me. In long term we might want a. but to keep PR smaller and easier to review we can do a. as a follow up.
I meant we should drop it until we can support it in a meaningful way? i.e. when address can specify socket interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's fine with you, let's try to do a. as a follow up after we fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not to forget about it, I pushed the fix now, but that's independent of the changes we've been discussing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Let me know if anything else is needed (the update seems to have verified fine). |
||
new SocketInterfaceLoader(std::make_unique<SocketInterfaceImpl>()); | ||
|
||
|
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.
Is the thinking that these will one day be dynamically discovered by an xDS? If not, you don't need to put them in
static_resources
, they can just live top-level.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.
+1.
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.
Done! Actually this was just me not knowing what I was doing, so thanks for the comment!
Another thing that's confusing is the ci/circleci:docs error. Should I add the new *.proto files to some list or is there something wrong with them?