-
Notifications
You must be signed in to change notification settings - Fork 5.3k
ZooKeeper proxy filter #5991
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
Merged
Merged
ZooKeeper proxy filter #5991
Changes from all commits
Commits
Show all changes
121 commits
Select commit
Hold shift + click to select a range
df3db4b
ZooKeeper proxy filter
d2f50eb
Fix format issues
5a3bfe1
Fix docs
e16f507
Add missing words to dictionary.
ea2c5d6
Move var declaration closer to usage.
71f7686
Tentatively adding @snowp as sponsor/co-maintainer :-)
ad8f315
Make DecoderImpl's constructor explicit
cfa9f3f
Use peekInt<>() to extract bool
2698f55
Use copyOut() instead of linearize
a17402a
Simplify test helpers
f5a2877
Drop my copy of enumToInt()
8482d4c
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
6746876
Fix order of version history items
7911d6c
Consistently name stats that are requests
dce2ca7
Fix doc
315e656
Use enum class for XID codes
0e2c698
Expand enumToInt() to support signed ints.
d839235
Add enumToIntSigned()
98e6896
Move Buffer::OwnedImpl instead of returning pointers
c371cfb
Emit decoderError() calls when len checks fail
73962e4
Parse delete & exists requests
e19d918
Parse getacl & setacl requests
30546ce
Parse sync requests
b454671
Parse check requests
e2fa765
Parse multi requests
a21102f
Parse reconfig requests
4635b35
Parse setWatches requests
bae0ca2
Parse Close requests
24b781c
Fix format
4d3ca2b
Set the corresponding metadata for each request
6ba1f21
Skip obvious comments
e39825d
Few stylistic items
ac3b3d1
Describe regular vs readonly connect requests
1d66596
Merge branch 'master' into add-zookeeper-filter
83ff78c
Add comment noting that ZK uses network ordering
2192a9d
Centralize error handling when parsing
2db08fe
Improve coverage
e315233
onWrite() should be used for responses
edf37a8
Fix mem leak
5cac7fa
Fix decoding error with Pings
020d46a
Address nit
c241f25
Don't use exceptions to check if a bool is avail
6cc7279
Make check length a helper and not a macro
701cce0
Avoid potential infinite loops
354bd32
Split empty string vs not big enough buffer
4eb510f
Use return values instead of out param references
4c8204d
Track request bytes
44a179f
Naming & link for ZooKeeper
c9cadb7
Mention supported ZK version & opcodes handling
70827ce
Handle unknown opcodes
028d7e9
Add support for {check, remove}watches
fcf42bb
Kick CI
5d3f2f9
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
90c58da
Document the different between XIDs <=0 and > 0.
3dc1f72
Fix spelling
2b67b7a
Use const for skipping offsets
1854c33
Skip reading credential, since we don't use it.
70e4852
More spelling
bdad785
Add xid to the dictionary
fcc62ef
Kick CI
3180d02
Make local vars const when possible
0575502
Use consts to explain how the min length is derived
93caa9b
Fix bool that shouldn't be const
d55144b
Rename checkLength to ensureMinLength
dfd64fe
Use consts to express what the min lengths mean
0d11026
Fix format
6ce5752
Avoid const for values in declarations
b9490e3
Simplify peekBool()
9389ef1
More context when throwing exception
9a744d7
Update tests
cbc618a
Enforce max bytes check
980207e
Fix signature
df93faa
Cast len to uint
0ba7695
Fix test
64fe5c4
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
ceecefb
Use google.protobuf.UInt32Value
804b83c
Enumerate unsupported opcodes.
55293f2
Add missing import for UInt32Value
6c71415
Use PROTOBUF_GET_WRAPPED_OR_DEFAULT
c121cee
Use constexpr
6c8c977
Use helper to skip individual strings
e3ee7f2
Remove const from values in decls
d845a5a
Clarify that helpers aren't for IO
a115c66
Fix spelling
df66703
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
f001664
Support all of create()'s flags
36d1c39
Fix build
7ef7405
Move createFlagsToString out of header
be08bfa
Fix name
4695977
Fix more typos
e301b74
Handle unknown flags.
eb2cebd
Handle container & TTL znode creation
2a0374d
Fix
2f1b994
Fix signature
8b705e6
Fix type
3043ab2
Fix parseCreateRequest call
b9d4883
Reduce calls to enumToInt()
ff5284e
Handle enum value that wasn't being handled
f91a5db
Improve comment on handling XIDs.
823ccc5
Guard against longer than length messages
a2ae4ec
Properly namespace method
aceaca4
Move missing header to the right place
f21580f
Relax erstwhile const methods
9284fc1
Fix syntax
514e92a
Fix test
a1a28bc
Support getEphemerals & getAllChildrenNumber
4cd3f6e
Simplify int to enum conversion
e43cd1e
Encapsulate skip within the BufferHelper
fe401f4
Explain how offset and cursor_ are different.
6e0f226
Test all possible create flags
a80279d
Improve coverage fo ZooKeeperFilter::onCreateRequest
67227d7
Add test for empty string as path
2533893
Fix comment
f18cbfe
DRY things up a bit
58ce244
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
0a1e14f
Tidy up ZooKeeperFilter::doDecode
d689794
Add missing coverage for BufferHelper::peekString
bda8df1
Fix
cb117f3
Merge remote-tracking branch 'upstream/master' into add-zookeeper-filter
3f3f466
More constness
3ec7cb4
Rename enumToIntSigned -> enumToSignedInt
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
8 changes: 8 additions & 0 deletions
8
api/envoy/config/filter/network/zookeeper_proxy/v1alpha1/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,8 @@ | ||
| load("//bazel:api_build_system.bzl", "api_proto_library_internal") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_library_internal( | ||
| name = "zookeeper_proxy", | ||
| srcs = ["zookeeper_proxy.proto"], | ||
| ) |
33 changes: 33 additions & 0 deletions
33
api/envoy/config/filter/network/zookeeper_proxy/v1alpha1/zookeeper_proxy.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,33 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.network.zookeeper_proxy.v1alpha1; | ||
|
|
||
| option java_outer_classname = "ZookeeperProxyProto"; | ||
| option java_multiple_files = true; | ||
| option java_package = "io.envoyproxy.envoy.config.filter.network.zookeeper_proxy.v1alpha1"; | ||
| option go_package = "v1alpha1"; | ||
|
|
||
| import "validate/validate.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| // [#protodoc-title: ZooKeeper proxy] | ||
| // ZooKeeper Proxy :ref:`configuration overview <config_network_filters_zookeeper_proxy>`. | ||
| message ZooKeeperProxy { | ||
| // The human readable prefix to use when emitting :ref:`statistics | ||
| // <config_network_filters_zookeeper_proxy_stats>`. | ||
| string stat_prefix = 1 [(validate.rules).string.min_bytes = 1]; | ||
|
|
||
| // [#not-implemented-hide:] The optional path to use for writing ZooKeeper access logs. | ||
| // If the access log field is empty, access logs will not be written. | ||
| string access_log = 2; | ||
|
|
||
| // Messages — requests, responses and events — that are bigger than this value will | ||
| // be ignored. If it is not set, the default value is 1Mb. | ||
| // | ||
| // The value here should match the jute.maxbuffer property in your cluster configuration: | ||
| // | ||
| // https://zookeeper.apache.org/doc/r3.4.10/zookeeperAdmin.html#Unsafe+Options | ||
| // | ||
| // if that is set. If it isn't, ZooKeeper's default is also 1Mb. | ||
| google.protobuf.UInt32Value max_packet_bytes = 3; | ||
| } |
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 |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ filters. | |
| tcp_proxy_filter | ||
| thrift_proxy_filter | ||
| sni_cluster_filter | ||
| zookeeper_proxy_filter | ||
92 changes: 92 additions & 0 deletions
92
docs/root/configuration/network_filters/zookeeper_proxy_filter.rst
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,92 @@ | ||
| .. _config_network_filters_zookeeper_proxy: | ||
|
|
||
| ZooKeeper proxy | ||
| =============== | ||
|
|
||
| The ZooKeeper proxy filter decodes the client protocol for | ||
| `Apache ZooKeeper <https://zookeeper.apache.org/>`_. It decodes the requests, | ||
| responses and events in the payload. Most opcodes known in | ||
| `ZooKeeper 3.5 <https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/ZooDefs.java>`_ | ||
| are supported. The unsupported ones are related to SASL authentication. | ||
|
|
||
| .. attention:: | ||
|
|
||
| The zookeeper_proxy filter is experimental and is currently under active | ||
| development. Capabilities will be expanded over time and the | ||
| configuration structures are likely to change. | ||
|
|
||
| .. _config_network_filters_zookeeper_proxy_config: | ||
|
|
||
| Configuration | ||
| ------------- | ||
|
|
||
| The ZooKeeper proxy filter should be chained with the TCP proxy filter as shown | ||
| in the configuration snippet below: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| filter_chains: | ||
| - filters: | ||
| - name: envoy.filters.network.zookeeper_proxy | ||
| config: | ||
| stat_prefix: zookeeper | ||
| - name: envoy.tcp_proxy | ||
| config: | ||
| stat_prefix: tcp | ||
| cluster: ... | ||
|
|
||
|
|
||
| .. _config_network_filters_zookeeper_proxy_stats: | ||
|
|
||
| Statistics | ||
| ---------- | ||
|
|
||
| Every configured ZooKeeper proxy filter has statistics rooted at *zookeeper.<stat_prefix>.* with the | ||
| following statistics: | ||
|
|
||
| .. csv-table:: | ||
| :header: Name, Type, Description | ||
| :widths: 1, 1, 2 | ||
|
|
||
| decoder_error, Counter, Number of times a message wasn't decoded | ||
| request_bytes, Counter, Number of bytes in decoded request messages | ||
| connect_rq, Counter, Number of regular connect (non-readonly) requests | ||
| connect_readonly_rq, Counter, Number of connect requests with the readonly flag set | ||
rgs1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ping_rq, Counter, Number of ping requests | ||
| auth.<type>_rq, Counter, Number of auth requests for a given type | ||
| getdata_rq, Counter, Number of getdata requests | ||
| create_rq, Counter, Number of create requests | ||
| create2_rq, Counter, Number of create2 requests | ||
| setdata_rq, Counter, Number of setdata requests | ||
| getchildren_rq, Counter, Number of getchildren requests | ||
| getchildren2_rq, Counter, Number of getchildren2 requests | ||
| remove_rq, Counter, Number of delete requests | ||
| exists_rq, Counter, Number of stat requests | ||
| getacl_rq, Counter, Number of getacl requests | ||
| setacl_rq, Counter, Number of setacl requests | ||
| sync_rq, Counter, Number of sync requests | ||
| multi_rq, Counter, Number of multi transaction requests | ||
| reconfig_rq, Counter, Number of reconfig requests | ||
| close_rq, Counter, Number of close requests | ||
| setwatches_rq, Counter, Number of setwatches requests | ||
| checkwatches_rq, Counter, Number of checkwatches requests | ||
| removewatches_rq, Counter, Number of removewatches requests | ||
| check_rq, Counter, Number of check requests | ||
|
|
||
| .. _config_network_filters_zookeeper_proxy_dynamic_metadata: | ||
|
|
||
| Dynamic Metadata | ||
| ---------------- | ||
|
|
||
| The ZooKeeper filter emits the following dynamic metadata for each message parsed: | ||
|
|
||
| .. csv-table:: | ||
| :header: Name, Type, Description | ||
| :widths: 1, 1, 2 | ||
|
|
||
| <path>, string, "The path associated with the request, response or event" | ||
rgs1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <opname>, string, "The opname for the request, response or event" | ||
| <create_type>, string, "The string representation of the flags applied to the znode" | ||
| <bytes>, string, "The size of the request message in bytes" | ||
| <watch>, string, "True if a watch is being set, false otherwise" | ||
| <version>, string, "The version parameter, if any, given with the request" | ||
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
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,47 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| # ZooKeeper proxy L7 network filter. | ||
| # Public docs: docs/root/configuration/network_filters/zookeeper_proxy_filter.rst | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "proxy_lib", | ||
| srcs = [ | ||
| "zookeeper_decoder.cc", | ||
| "zookeeper_filter.cc", | ||
| "zookeeper_utils.cc", | ||
| ], | ||
| hdrs = [ | ||
| "zookeeper_decoder.h", | ||
| "zookeeper_filter.h", | ||
| "zookeeper_utils.h", | ||
| ], | ||
| deps = [ | ||
| "//include/envoy/network:filter_interface", | ||
| "//include/envoy/server:filter_config_interface", | ||
| "//include/envoy/stats:stats_interface", | ||
| "//include/envoy/stats:stats_macros", | ||
| "//source/common/config:filter_json_lib", | ||
| "//source/common/network:filter_lib", | ||
| "//source/extensions/filters/network:well_known_names", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "config", | ||
| srcs = ["zookeeper_config.cc"], | ||
| hdrs = ["zookeeper_config.h"], | ||
| deps = [ | ||
| ":proxy_lib", | ||
| "//source/extensions/filters/network:well_known_names", | ||
| "//source/extensions/filters/network/common:factory_base_lib", | ||
| "@envoy_api//envoy/config/filter/network/zookeeper_proxy/v1alpha1:zookeeper_proxy_cc", | ||
| ], | ||
| ) |
47 changes: 47 additions & 0 deletions
47
source/extensions/filters/network/zookeeper_proxy/zookeeper_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,47 @@ | ||
| #include "extensions/filters/network/zookeeper_proxy/zookeeper_config.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/config/filter/network/zookeeper_proxy/v1alpha1/zookeeper_proxy.pb.validate.h" | ||
| #include "envoy/registry/registry.h" | ||
| #include "envoy/server/filter_config.h" | ||
|
|
||
| #include "common/common/logger.h" | ||
|
|
||
| #include "extensions/filters/network/zookeeper_proxy/zookeeper_filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace ZooKeeperProxy { | ||
|
|
||
| /** | ||
| * Config registration for the ZooKeeper proxy filter. @see NamedNetworkFilterConfigFactory. | ||
| */ | ||
| Network::FilterFactoryCb | ||
| NetworkFilters::ZooKeeperProxy::ZooKeeperConfigFactory::createFilterFactoryFromProtoTyped( | ||
| const envoy::config::filter::network::zookeeper_proxy::v1alpha1::ZooKeeperProxy& proto_config, | ||
| Server::Configuration::FactoryContext& context) { | ||
|
|
||
| ASSERT(!proto_config.stat_prefix().empty()); | ||
rgs1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const std::string stat_prefix = fmt::format("{}.zookeeper.", proto_config.stat_prefix()); | ||
| const uint32_t max_packet_bytes = | ||
| PROTOBUF_GET_WRAPPED_OR_DEFAULT(proto_config, max_packet_bytes, 1024 * 1024); | ||
|
|
||
| ZooKeeperFilterConfigSharedPtr filter_config( | ||
| std::make_shared<ZooKeeperFilterConfig>(stat_prefix, max_packet_bytes, context.scope())); | ||
| return [filter_config](Network::FilterManager& filter_manager) -> void { | ||
| filter_manager.addFilter(std::make_shared<ZooKeeperFilter>(filter_config)); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Static registration for the ZooKeeper proxy filter. @see RegisterFactory. | ||
| */ | ||
| REGISTER_FACTORY(ZooKeeperConfigFactory, Server::Configuration::NamedNetworkFilterConfigFactory); | ||
|
|
||
| } // namespace ZooKeeperProxy | ||
| } // namespace NetworkFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
33 changes: 33 additions & 0 deletions
33
source/extensions/filters/network/zookeeper_proxy/zookeeper_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,33 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/config/filter/network/zookeeper_proxy/v1alpha1/zookeeper_proxy.pb.h" | ||
| #include "envoy/config/filter/network/zookeeper_proxy/v1alpha1/zookeeper_proxy.pb.validate.h" | ||
|
|
||
| #include "extensions/filters/network/common/factory_base.h" | ||
| #include "extensions/filters/network/well_known_names.h" | ||
| #include "extensions/filters/network/zookeeper_proxy/zookeeper_filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace ZooKeeperProxy { | ||
|
|
||
| /** | ||
| * Config registration for the ZooKeeper proxy filter. | ||
| */ | ||
| class ZooKeeperConfigFactory | ||
| : public Common::FactoryBase< | ||
| envoy::config::filter::network::zookeeper_proxy::v1alpha1::ZooKeeperProxy> { | ||
| public: | ||
| ZooKeeperConfigFactory() : FactoryBase(NetworkFilterNames::get().ZooKeeperProxy) {} | ||
|
|
||
| private: | ||
| Network::FilterFactoryCb createFilterFactoryFromProtoTyped( | ||
| const envoy::config::filter::network::zookeeper_proxy::v1alpha1::ZooKeeperProxy& proto_config, | ||
| Server::Configuration::FactoryContext& context) override; | ||
| }; | ||
|
|
||
| } // namespace ZooKeeperProxy | ||
| } // namespace NetworkFilters | ||
| } // 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.
Uh oh!
There was an error while loading. Please reload this page.