/proc/self/cwd/source/extensions/filters/network/zookeeper_proxy/config.cc
Line | Count | Source |
1 | | #include "source/extensions/filters/network/zookeeper_proxy/config.h" |
2 | | |
3 | | #include <string> |
4 | | |
5 | | #include "envoy/extensions/filters/network/zookeeper_proxy/v3/zookeeper_proxy.pb.h" |
6 | | #include "envoy/extensions/filters/network/zookeeper_proxy/v3/zookeeper_proxy.pb.validate.h" |
7 | | #include "envoy/registry/registry.h" |
8 | | #include "envoy/server/filter_config.h" |
9 | | |
10 | | #include "source/common/common/logger.h" |
11 | | #include "source/extensions/filters/network/zookeeper_proxy/filter.h" |
12 | | |
13 | | namespace Envoy { |
14 | | namespace Extensions { |
15 | | namespace NetworkFilters { |
16 | | namespace ZooKeeperProxy { |
17 | | |
18 | | /** |
19 | | * Config registration for the ZooKeeper proxy filter. @see NamedNetworkFilterConfigFactory. |
20 | | */ |
21 | | Network::FilterFactoryCb ZooKeeperConfigFactory::createFilterFactoryFromProtoTyped( |
22 | | const envoy::extensions::filters::network::zookeeper_proxy::v3::ZooKeeperProxy& proto_config, |
23 | 634 | Server::Configuration::FactoryContext& context) { |
24 | | |
25 | 634 | ASSERT(!proto_config.stat_prefix().empty()); |
26 | | |
27 | 634 | const std::string stat_prefix = fmt::format("{}.zookeeper", proto_config.stat_prefix()); |
28 | 634 | const uint32_t max_packet_bytes = |
29 | 634 | PROTOBUF_GET_WRAPPED_OR_DEFAULT(proto_config, max_packet_bytes, 1024 * 1024); |
30 | 634 | const bool enable_per_opcode_request_bytes_metrics = |
31 | 634 | proto_config.enable_per_opcode_request_bytes_metrics(); |
32 | 634 | const bool enable_per_opcode_response_bytes_metrics = |
33 | 634 | proto_config.enable_per_opcode_response_bytes_metrics(); |
34 | 634 | const bool enable_latency_threshold_metrics = proto_config.enable_latency_threshold_metrics(); |
35 | 634 | const std::chrono::milliseconds default_latency_threshold( |
36 | 634 | PROTOBUF_GET_MS_OR_DEFAULT(proto_config, default_latency_threshold, 100)); |
37 | 634 | const LatencyThresholdOverrideList& latency_threshold_overrides = |
38 | 634 | proto_config.latency_threshold_overrides(); |
39 | | |
40 | | // Check duplicated opcodes in config. |
41 | 634 | absl::flat_hash_set<LatencyThresholdOverride_Opcode> opcodes; |
42 | 634 | for (const auto& threshold_override : latency_threshold_overrides) { |
43 | 468 | auto insertion = opcodes.insert(threshold_override.opcode()); |
44 | 468 | if (!insertion.second) { |
45 | 7 | throw EnvoyException(fmt::format("Duplicated opcode find in config: {}", |
46 | 7 | static_cast<uint32_t>(threshold_override.opcode()))); |
47 | 7 | } |
48 | 468 | } |
49 | | |
50 | 627 | ZooKeeperFilterConfigSharedPtr filter_config(std::make_shared<ZooKeeperFilterConfig>( |
51 | 627 | stat_prefix, max_packet_bytes, enable_per_opcode_request_bytes_metrics, |
52 | 627 | enable_per_opcode_response_bytes_metrics, enable_latency_threshold_metrics, |
53 | 627 | default_latency_threshold, latency_threshold_overrides, context.scope())); |
54 | 627 | auto& time_source = context.mainThreadDispatcher().timeSource(); |
55 | | |
56 | 627 | return [filter_config, &time_source](Network::FilterManager& filter_manager) -> void { |
57 | 624 | filter_manager.addFilter(std::make_shared<ZooKeeperFilter>(filter_config, time_source)); |
58 | 624 | }; |
59 | 634 | } |
60 | | |
61 | | /** |
62 | | * Static registration for the ZooKeeper proxy filter. @see RegisterFactory. |
63 | | */ |
64 | | REGISTER_FACTORY(ZooKeeperConfigFactory, Server::Configuration::NamedNetworkFilterConfigFactory); |
65 | | |
66 | | } // namespace ZooKeeperProxy |
67 | | } // namespace NetworkFilters |
68 | | } // namespace Extensions |
69 | | } // namespace Envoy |