1
#pragma once
2

            
3
#include "envoy/common/pure.h"
4
#include "envoy/config/typed_config.h"
5
#include "envoy/server/factory_context.h"
6

            
7
#include "absl/strings/string_view.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace Bootstrap {
12
namespace ReverseConnection {
13

            
14
/**
15
 * Interface for emitting reverse-tunnel lifecycle events.
16
 */
17
class ReverseTunnelReporter {
18
public:
19
5
  virtual ~ReverseTunnelReporter() = default;
20

            
21
  /**
22
   * Called after the Envoy server finishes initialization.
23
   */
24
  virtual void onServerInitialized() PURE;
25

            
26
  /**
27
   * Record that a reverse tunnel has been established.
28
   * @param node_id ID reported by the connecting node.
29
   * @param cluster_id cluster which the node belongs to.
30
   * @param tenant_id tenant identifier associated with the node.
31
   */
32
  virtual void reportConnectionEvent(absl::string_view node_id, absl::string_view cluster_id,
33
                                     absl::string_view tenant_id) PURE;
34

            
35
  /**
36
   * Record that a reverse tunnel has been torn down.
37
   * @param node_id ID of the disconnecting node.
38
   * @param cluster_id cluster which the node belongs to.
39
   */
40
  virtual void reportDisconnectionEvent(absl::string_view node_id,
41
                                        absl::string_view cluster_id) PURE;
42
};
43

            
44
using ReverseTunnelReporterPtr = std::unique_ptr<ReverseTunnelReporter>;
45

            
46
/**
47
 * Factory for creating reverse-tunnel reporters.
48
 */
49
class ReverseTunnelReporterFactory : public Config::TypedFactory {
50
public:
51
  /**
52
   * Build a reporter instance from the supplied configuration.
53
   * @param context owning server factory context.
54
   * @param message typed reporter configuration; ownership is transferred to the callee.
55
   * @return unique ptr to the reporter instance.
56
   */
57
  virtual ReverseTunnelReporterPtr
58
  createReporter(Server::Configuration::ServerFactoryContext& context,
59
                 ProtobufTypes::MessagePtr message) PURE;
60

            
61
5
  std::string category() const override {
62
5
    return "envoy.extensions.reverse_tunnel.reporting_service";
63
5
  }
64
};
65

            
66
} // namespace ReverseConnection
67
} // namespace Bootstrap
68
} // namespace Extensions
69
} // namespace Envoy