/proc/self/cwd/source/extensions/filters/network/thrift_proxy/router/router_ratelimit.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <cstdint> |
4 | | #include <memory> |
5 | | #include <string> |
6 | | #include <vector> |
7 | | |
8 | | #include "envoy/http/header_map.h" |
9 | | #include "envoy/ratelimit/ratelimit.h" |
10 | | |
11 | | #include "source/extensions/filters/network/thrift_proxy/metadata.h" |
12 | | #include "source/extensions/filters/network/thrift_proxy/router/router.h" |
13 | | |
14 | | namespace Envoy { |
15 | | namespace Extensions { |
16 | | namespace NetworkFilters { |
17 | | namespace ThriftProxy { |
18 | | namespace Router { |
19 | | |
20 | | /** |
21 | | * Base interface for generic rate limit action. |
22 | | */ |
23 | | class RateLimitAction { |
24 | | public: |
25 | 0 | virtual ~RateLimitAction() = default; |
26 | | |
27 | | /** |
28 | | * Potentially append a descriptor entry to the end of descriptor. |
29 | | * @param route supplies the target route for the request. |
30 | | * @param descriptor supplies the descriptor to optionally fill. |
31 | | * @param local_service_cluster supplies the name of the local service cluster. |
32 | | * @param metadata supplies the message metadata for the request. |
33 | | * @param remote_address supplies the trusted downstream address for the connection. |
34 | | * @return true if the RateLimitAction populated the descriptor. |
35 | | */ |
36 | | virtual bool populateDescriptor(const RouteEntry& route, RateLimit::Descriptor& descriptor, |
37 | | const std::string& local_service_cluster, |
38 | | const MessageMetadata& metadata, |
39 | | const Network::Address::Instance& remote_address) const PURE; |
40 | | }; |
41 | | |
42 | | using RateLimitActionPtr = std::unique_ptr<RateLimitAction>; |
43 | | |
44 | | /** |
45 | | * Rate limit configuration. |
46 | | */ |
47 | | class RateLimitPolicyEntry { |
48 | | public: |
49 | 0 | virtual ~RateLimitPolicyEntry() = default; |
50 | | |
51 | | /** |
52 | | * @return the stage value that the configuration is applicable to. |
53 | | */ |
54 | | virtual uint32_t stage() const PURE; |
55 | | |
56 | | /** |
57 | | * @return runtime key to be set to disable the configuration. |
58 | | */ |
59 | | virtual const std::string& disableKey() const PURE; |
60 | | |
61 | | /** |
62 | | * Potentially populate the descriptor array with new descriptors to query. |
63 | | * @param route supplies the target route for the request. |
64 | | * @param descriptors supplies the descriptor array to optionally fill. |
65 | | * @param local_service_cluster supplies the name of the local service cluster. |
66 | | * @param metadata supplies the message metadata for the request. |
67 | | * @param remote_address supplies the trusted downstream address for the connection. |
68 | | */ |
69 | | virtual void populateDescriptors(const RouteEntry& route, |
70 | | std::vector<RateLimit::Descriptor>& descriptors, |
71 | | const std::string& local_service_cluster, |
72 | | const MessageMetadata& metadata, |
73 | | const Network::Address::Instance& remote_address) const PURE; |
74 | | }; |
75 | | |
76 | | /** |
77 | | * Rate limiting policy. |
78 | | */ |
79 | | class RateLimitPolicy { |
80 | | public: |
81 | 0 | virtual ~RateLimitPolicy() = default; |
82 | | |
83 | | /** |
84 | | * @return true if there is no rate limit policy for all stage settings. |
85 | | */ |
86 | | virtual bool empty() const PURE; |
87 | | |
88 | | /** |
89 | | * @param stage the value for finding applicable rate limit configurations. |
90 | | * @return set of RateLimitPolicyEntry that are applicable for a stage. |
91 | | */ |
92 | | virtual const std::vector<std::reference_wrapper<const RateLimitPolicyEntry>>& |
93 | | getApplicableRateLimit(uint32_t stage) const PURE; |
94 | | }; |
95 | | |
96 | | } // namespace Router |
97 | | } // namespace ThriftProxy |
98 | | } // namespace NetworkFilters |
99 | | } // namespace Extensions |
100 | | } // namespace Envoy |