1
#pragma once
2

            
3
#include <memory>
4

            
5
#include "envoy/api/api.h"
6
#include "envoy/common/pure.h"
7
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
8
#include "envoy/config/typed_config.h"
9
#include "envoy/event/dispatcher.h"
10
#include "envoy/protobuf/message_validator.h"
11
#include "envoy/server/guarddog.h"
12
#include "envoy/stats/scope.h"
13

            
14
#include "source/common/protobuf/protobuf.h"
15

            
16
namespace Envoy {
17
namespace Server {
18
namespace Configuration {
19

            
20
struct GuardDogActionFactoryContext {
21
  Api::Api& api_;
22
  Event::Dispatcher& dispatcher_; // not owned (this is the guard dog's dispatcher)
23
  Stats::Scope& stats_;           // not owned (this is the server's stats scope)
24
  absl::string_view guarddog_name_;
25
};
26

            
27
class GuardDogAction {
28
public:
29
76
  virtual ~GuardDogAction() = default;
30
  /**
31
   * Callback function for when the GuardDog observes an event.
32
   * @param event the event the GuardDog observes.
33
   * @param thread_last_checkin_pairs pair of the relevant thread to the event, and the
34
   *  last check in time of those threads with their watchdog.
35
   * @param now the current time.
36
   */
37
  virtual void
38
  run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::WatchdogEvent event,
39
      const std::vector<std::pair<Thread::ThreadId, MonotonicTime>>& thread_last_checkin_pairs,
40
      MonotonicTime now) PURE;
41
};
42

            
43
using GuardDogActionPtr = std::unique_ptr<GuardDogAction>;
44

            
45
/**
46
 * Implemented by each custom GuardDogAction and registered via Registry::registerFactory()
47
 * or the convenience class RegisterFactory.
48
 */
49
class GuardDogActionFactory : public Config::TypedFactory {
50
public:
51
28
  ~GuardDogActionFactory() override = default;
52

            
53
  /**
54
   * Creates a particular GuardDog Action factory implementation.
55
   *
56
   * @param config supplies the configuration for the action.
57
   * @param context supplies the GuardDog Action's context.
58
   * @return GuardDogActionPtr the GuardDogAction object.
59
   */
60
  virtual GuardDogActionPtr createGuardDogActionFromProto(
61
      const envoy::config::bootstrap::v3::Watchdog::WatchdogAction& config,
62
      GuardDogActionFactoryContext& context) PURE;
63

            
64
1013
  std::string category() const override { return "envoy.guarddog_actions"; }
65
};
66

            
67
} // namespace Configuration
68
} // namespace Server
69
} // namespace Envoy