Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : 5 : #include "envoy/common/exception.h" 6 : #include "envoy/common/pure.h" 7 : 8 : #include "source/common/common/assert.h" 9 : 10 : namespace Envoy { 11 : namespace Server { 12 : 13 : // Struct for reporting usage for a particular resource. 14 : struct ResourceUsage { 15 0 : bool operator==(const ResourceUsage& rhs) const { 16 0 : return resource_pressure_ == rhs.resource_pressure_; 17 0 : } 18 : 19 : // Fraction of (resource usage)/(resource limit). 20 : double resource_pressure_; 21 : }; 22 : 23 : /** 24 : * Notifies caller of updated resource usage. 25 : */ 26 : class ResourceUpdateCallbacks { 27 : public: 28 0 : virtual ~ResourceUpdateCallbacks() = default; 29 : 30 : /** 31 : * Called when the request for updated resource usage succeeds. 32 : * @param usage the updated resource usage 33 : */ 34 : virtual void onSuccess(const ResourceUsage& usage) PURE; 35 : 36 : /** 37 : * Called when the request for updated resource usage fails. 38 : * @param error the exception caught when trying to get updated resource usage 39 : */ 40 : virtual void onFailure(const EnvoyException& error) PURE; 41 : }; 42 : 43 : class ResourceMonitor { 44 : public: 45 0 : virtual ~ResourceMonitor() = default; 46 : 47 : /** 48 : * Recalculate resource usage. 49 : * This must be non-blocking so if RPCs need to be made they should be 50 : * done asynchronously and invoke the callback when finished. 51 : */ 52 : virtual void updateResourceUsage(ResourceUpdateCallbacks& callbacks) PURE; 53 : }; 54 : 55 : using ResourceMonitorPtr = std::unique_ptr<ResourceMonitor>; 56 : 57 : } // namespace Server 58 : } // namespace Envoy