1
#pragma once
2

            
3
#include <memory>
4
#include <vector>
5

            
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/instance.h"
12

            
13
namespace Envoy {
14
namespace Server {
15
namespace Configuration {
16

            
17
class FatalAction {
18
public:
19
6
  virtual ~FatalAction() = default;
20
  /**
21
   * Callback function to run when Envoy is crashing.
22
   * @param tracked_objects a span of objects Envoy was working on when Envoy started crashing.
23
   */
24
  virtual void run(absl::Span<const ScopeTrackedObject* const> tracked_objects) PURE;
25

            
26
  /**
27
   * @return whether the action is async-signal-safe.
28
   * See man 7 signal-safety for the definition of async-signal-safe.
29
   */
30
  virtual bool isAsyncSignalSafe() const PURE;
31
};
32

            
33
using FatalActionPtr = std::unique_ptr<FatalAction>;
34

            
35
/**
36
 * Implemented by each custom FatalAction and registered via Registry::registerFactory()
37
 * or the convenience class RegisterFactory.
38
 */
39
class FatalActionFactory : public Config::TypedFactory {
40
public:
41
2
  ~FatalActionFactory() override = default;
42

            
43
  /**
44
   * Creates a particular FatalAction implementation.
45
   *
46
   * @param config supplies the configuration for the action.
47
   * @param context supplies the GuardDog Action's context.
48
   * @return FatalActionsPtr the FatalActions object.
49
   */
50
  virtual FatalActionPtr
51
  createFatalActionFromProto(const envoy::config::bootstrap::v3::FatalAction& config,
52
                             Instance* server) PURE;
53

            
54
2
  std::string category() const override { return "envoy.fatal_action"; }
55
};
56

            
57
} // namespace Configuration
58
} // namespace Server
59
} // namespace Envoy