1
#pragma once
2

            
3
#include "envoy/api/api.h"
4
#include "envoy/extensions/resource_monitors/injected_resource/v3/injected_resource.pb.h"
5
#include "envoy/filesystem/filesystem.h"
6
#include "envoy/server/resource_monitor.h"
7
#include "envoy/server/resource_monitor_config.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace ResourceMonitors {
12
namespace InjectedResourceMonitor {
13

            
14
/**
15
 * A monitor for an injected resource. The resource pressure is read from a text file
16
 * specified in the config, which must contain a floating-point number in the range
17
 * [0..1] and be updated atomically by a symbolic link swap.
18
 * This is intended primarily for integration tests to force Envoy into an overloaded state.
19
 */
20
class InjectedResourceMonitor : public Server::ResourceMonitor {
21
public:
22
  InjectedResourceMonitor(
23
      const envoy::extensions::resource_monitors::injected_resource::v3::InjectedResourceConfig&
24
          config,
25
      Server::Configuration::ResourceMonitorFactoryContext& context);
26

            
27
  // Server::ResourceMonitor
28
  void updateResourceUsage(Server::ResourceUpdateCallbacks& callbacks) override;
29

            
30
protected:
31
  virtual void onFileChanged();
32

            
33
private:
34
  const std::string filename_;
35
  bool file_changed_{true};
36
  Filesystem::WatcherPtr watcher_;
37
  absl::optional<double> pressure_;
38
  absl::optional<EnvoyException> error_;
39
  Api::Api& api_;
40
};
41

            
42
} // namespace InjectedResourceMonitor
43
} // namespace ResourceMonitors
44
} // namespace Extensions
45
} // namespace Envoy