1
#pragma once
2

            
3
#include <memory>
4

            
5
#include "envoy/common/pure.h"
6

            
7
#include "absl/strings/string_view.h"
8

            
9
namespace Envoy {
10
namespace Server {
11

            
12
class LoadShedPointNameValues {
13
public:
14
  // Envoy will reject (close) new TCP connections.
15
  // This occurs before the Listener Filter Chain is created.
16
  const std::string TcpListenerAccept = "envoy.load_shed_points.tcp_listener_accept";
17

            
18
  // Envoy will reject new HTTP streams by sending a local reply.
19
  const std::string HcmDecodeHeaders =
20
      "envoy.load_shed_points.http_connection_manager_decode_headers";
21

            
22
  // Envoy will reject processing HTTP1 at the codec level.
23
  const std::string H1ServerAbortDispatch = "envoy.load_shed_points.http1_server_abort_dispatch";
24

            
25
  // Envoy will send a GOAWAY while processing HTTP2 requests at the codec level
26
  // which will eventually drain the HTTP/2 connection.
27
  const std::string H2ServerGoAwayOnDispatch =
28
      "envoy.load_shed_points.http2_server_go_away_on_dispatch";
29

            
30
  // Envoy will send a GOAWAY and immediately close the connection while processing HTTP2 requests
31
  // at the codec level.
32
  const std::string H2ServerGoAwayAndCloseOnDispatch =
33
      "envoy.load_shed_points.http2_server_go_away_and_close_on_dispatch";
34

            
35
  // Envoy will close the connections before creating codec if Envoy is under pressure,
36
  // typically memory. This happens once geting data from the connection.
37
  const std::string HcmCodecCreation = "envoy.load_shed_points.hcm_ondata_creating_codec";
38

            
39
  const std::string HttpDownstreamFilterCheck =
40
      "envoy.load_shed_points.http_downstream_filter_check";
41

            
42
  // Envoy will stop creating new connections in the connection pool when
43
  // it is under pressure (typically memory pressure). If a new connection is
44
  // rejected by this load shed point and there is no available capacity
45
  // to serve the downstream request, the downstream request will fail.
46
  const std::string ConnectionPoolNewConnection =
47
      "envoy.load_shed_points.connection_pool_new_connection";
48

            
49
  // Envoy will send GOAWAY and immediately close the connection while
50
  // processing HTTP3 requests at the codec level.
51
  const std::string H3ServerGoAwayAndCloseOnDispatch =
52
      "envoy.load_shed_points.http3_server_go_away_and_close_on_dispatch";
53

            
54
  // Envoy will send a GOAWAY while processing HTTP3 requests at the codec level
55
  // which will eventually drain the HPPT/3 connection.
56
  const std::string H3ServerGoAwayOnDispatch =
57
      "envoy.load_shed_points.http3_server_go_away_on_dispatch";
58
};
59

            
60
using LoadShedPointName = ConstSingleton<LoadShedPointNameValues>;
61

            
62
/**
63
 * A point within the connection or request lifecycle that provides context on
64
 * whether to shed load at that given stage for the current entity at the point.
65
 */
66
class LoadShedPoint {
67
public:
68
2059
  virtual ~LoadShedPoint() = default;
69

            
70
  // Whether to shed the load.
71
  virtual bool shouldShedLoad() PURE;
72
};
73

            
74
using LoadShedPointPtr = std::unique_ptr<LoadShedPoint>;
75

            
76
/**
77
 * Provides configured LoadShedPoints.
78
 */
79
class LoadShedPointProvider {
80
public:
81
144101
  virtual ~LoadShedPointProvider() = default;
82

            
83
  /**
84
   * Get the load shed point identified by the following string. Returns nullptr
85
   * for non-configured points.
86
   */
87
  virtual LoadShedPoint* getLoadShedPoint(absl::string_view point_name) PURE;
88
};
89

            
90
} // namespace Server
91
} // namespace Envoy