/proc/self/cwd/source/extensions/filters/network/mongo_proxy/config.cc
Line | Count | Source |
1 | | #include "source/extensions/filters/network/mongo_proxy/config.h" |
2 | | |
3 | | #include <memory> |
4 | | |
5 | | #include "envoy/extensions/filters/network/mongo_proxy/v3/mongo_proxy.pb.h" |
6 | | #include "envoy/extensions/filters/network/mongo_proxy/v3/mongo_proxy.pb.validate.h" |
7 | | #include "envoy/network/connection.h" |
8 | | #include "envoy/registry/registry.h" |
9 | | |
10 | | #include "source/common/common/fmt.h" |
11 | | #include "source/extensions/filters/network/mongo_proxy/proxy.h" |
12 | | |
13 | | namespace Envoy { |
14 | | namespace Extensions { |
15 | | namespace NetworkFilters { |
16 | | namespace MongoProxy { |
17 | | |
18 | | Network::FilterFactoryCb MongoProxyFilterConfigFactory::createFilterFactoryFromProtoTyped( |
19 | | const envoy::extensions::filters::network::mongo_proxy::v3::MongoProxy& proto_config, |
20 | 2.63k | Server::Configuration::FactoryContext& context) { |
21 | | |
22 | 2.63k | ASSERT(!proto_config.stat_prefix().empty()); |
23 | | |
24 | 2.63k | const std::string stat_prefix = fmt::format("mongo.{}", proto_config.stat_prefix()); |
25 | 2.63k | AccessLogSharedPtr access_log; |
26 | 2.63k | if (!proto_config.access_log().empty()) { |
27 | 801 | access_log = std::make_shared<AccessLog>(proto_config.access_log(), context.accessLogManager(), |
28 | 801 | context.mainThreadDispatcher().timeSource()); |
29 | 801 | } |
30 | | |
31 | 2.63k | Filters::Common::Fault::FaultDelayConfigSharedPtr fault_config; |
32 | 2.63k | if (proto_config.has_delay()) { |
33 | 122 | fault_config = std::make_shared<Filters::Common::Fault::FaultDelayConfig>(proto_config.delay()); |
34 | 122 | } |
35 | | |
36 | 2.63k | auto commands = std::vector<std::string>{"delete", "insert", "update"}; |
37 | 2.63k | if (proto_config.commands_size() > 0) { |
38 | 383 | commands = |
39 | 383 | std::vector<std::string>(proto_config.commands().begin(), proto_config.commands().end()); |
40 | 383 | } |
41 | | |
42 | 2.63k | auto stats = std::make_shared<MongoStats>(context.scope(), stat_prefix, commands); |
43 | 2.63k | const bool emit_dynamic_metadata = proto_config.emit_dynamic_metadata(); |
44 | 2.63k | return [stat_prefix, &context, access_log, fault_config, emit_dynamic_metadata, |
45 | 2.63k | stats](Network::FilterManager& filter_manager) -> void { |
46 | 2.62k | filter_manager.addFilter(std::make_shared<ProdProxyFilter>( |
47 | 2.62k | stat_prefix, context.scope(), context.runtime(), access_log, fault_config, |
48 | 2.62k | context.drainDecision(), context.mainThreadDispatcher().timeSource(), emit_dynamic_metadata, |
49 | 2.62k | stats)); |
50 | 2.62k | }; |
51 | 2.63k | } |
52 | | |
53 | | /** |
54 | | * Static registration for the mongo filter. @see RegisterFactory. |
55 | | */ |
56 | | LEGACY_REGISTER_FACTORY(MongoProxyFilterConfigFactory, |
57 | | Server::Configuration::NamedNetworkFilterConfigFactory, |
58 | | "envoy.mongo_proxy"); |
59 | | |
60 | | } // namespace MongoProxy |
61 | | } // namespace NetworkFilters |
62 | | } // namespace Extensions |
63 | | } // namespace Envoy |