/proc/self/cwd/source/extensions/filters/network/ratelimit/config.cc
Line | Count | Source |
1 | | #include "source/extensions/filters/network/ratelimit/config.h" |
2 | | |
3 | | #include <chrono> |
4 | | #include <string> |
5 | | |
6 | | #include "envoy/extensions/filters/network/ratelimit/v3/rate_limit.pb.h" |
7 | | #include "envoy/extensions/filters/network/ratelimit/v3/rate_limit.pb.validate.h" |
8 | | #include "envoy/registry/registry.h" |
9 | | |
10 | | #include "source/common/config/utility.h" |
11 | | #include "source/common/protobuf/utility.h" |
12 | | #include "source/extensions/filters/common/ratelimit/ratelimit_impl.h" |
13 | | #include "source/extensions/filters/network/ratelimit/ratelimit.h" |
14 | | |
15 | | namespace Envoy { |
16 | | namespace Extensions { |
17 | | namespace NetworkFilters { |
18 | | namespace RateLimitFilter { |
19 | | |
20 | | Network::FilterFactoryCb RateLimitConfigFactory::createFilterFactoryFromProtoTyped( |
21 | | const envoy::extensions::filters::network::ratelimit::v3::RateLimit& proto_config, |
22 | 12 | Server::Configuration::FactoryContext& context) { |
23 | | |
24 | 12 | ASSERT(!proto_config.stat_prefix().empty()); |
25 | 12 | ASSERT(!proto_config.domain().empty()); |
26 | 12 | ASSERT(proto_config.descriptors_size() > 0); |
27 | | |
28 | 12 | ConfigSharedPtr filter_config(new Config(proto_config, context.scope(), context.runtime())); |
29 | 12 | const std::chrono::milliseconds timeout = |
30 | 12 | std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(proto_config, timeout, 20)); |
31 | | |
32 | 12 | THROW_IF_NOT_OK(Envoy::Config::Utility::checkTransportVersion(proto_config.rate_limit_service())); |
33 | 8 | Grpc::GrpcServiceConfigWithHashKey config_with_hash_key = |
34 | 8 | Grpc::GrpcServiceConfigWithHashKey(proto_config.rate_limit_service().grpc_service()); |
35 | 8 | return [config_with_hash_key, &context, timeout, |
36 | 8 | filter_config](Network::FilterManager& filter_manager) -> void { |
37 | 6 | filter_manager.addReadFilter(std::make_shared<Filter>( |
38 | 6 | filter_config, |
39 | 6 | Filters::Common::RateLimit::rateLimitClient(context, config_with_hash_key, timeout))); |
40 | 6 | }; |
41 | 12 | } |
42 | | |
43 | | /** |
44 | | * Static registration for the rate limit filter. @see RegisterFactory. |
45 | | */ |
46 | | LEGACY_REGISTER_FACTORY(RateLimitConfigFactory, |
47 | | Server::Configuration::NamedNetworkFilterConfigFactory, "envoy.ratelimit"); |
48 | | |
49 | | } // namespace RateLimitFilter |
50 | | } // namespace NetworkFilters |
51 | | } // namespace Extensions |
52 | | } // namespace Envoy |