Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/envoy/upstream/resource_manager.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <cstddef>
4
#include <cstdint>
5
#include <memory>
6
7
#include "envoy/common/pure.h"
8
#include "envoy/common/resource.h"
9
10
namespace Envoy {
11
namespace Upstream {
12
13
/**
14
 * Resource priority classes. The parallel NumResourcePriorities constant allows defining fixed
15
 * arrays for each priority, but does not pollute the enum.
16
 */
17
enum class ResourcePriority : uint8_t { Default, High };
18
const size_t NumResourcePriorities = 2;
19
20
/**
21
 * RAII wrapper that increments a resource on construction and decrements it on destruction.
22
 */
23
class ResourceAutoIncDec {
24
public:
25
0
  ResourceAutoIncDec(ResourceLimit& resource) : resource_(resource) { resource_.inc(); }
26
0
  ~ResourceAutoIncDec() { resource_.dec(); }
27
28
private:
29
  ResourceLimit& resource_;
30
};
31
32
using ResourceAutoIncDecPtr = std::unique_ptr<ResourceAutoIncDec>;
33
34
/**
35
 * Global resource manager that loosely synchronizes maximum connections, pending requests, etc.
36
 * NOTE: Currently this is used on a per cluster basis. In the future we may consider also chaining
37
 *       this with a global resource manager.
38
 */
39
class ResourceManager {
40
public:
41
410k
  virtual ~ResourceManager() = default;
42
43
  /**
44
   * @return ResourceLimit& active TCP connections and UDP sessions.
45
   */
46
  virtual ResourceLimit& connections() PURE;
47
48
  /**
49
   * @return ResourceLimit& active pending requests (requests that have not yet been attached to a
50
   *         connection pool connection).
51
   */
52
  virtual ResourceLimit& pendingRequests() PURE;
53
54
  /**
55
   * @return ResourceLimit& active requests (requests that are currently bound to a connection pool
56
   *         connection and are awaiting response).
57
   */
58
  virtual ResourceLimit& requests() PURE;
59
60
  /**
61
   * @return ResourceLimit& active retries.
62
   */
63
  virtual ResourceLimit& retries() PURE;
64
65
  /**
66
   * @return ResourceLimit& active connection pools.
67
   */
68
  virtual ResourceLimit& connectionPools() PURE;
69
70
  /**
71
   * @return uint64_t the max number of connections per host.
72
   */
73
  virtual uint64_t maxConnectionsPerHost() PURE;
74
};
75
76
} // namespace Upstream
77
} // namespace Envoy