1
#pragma once
2

            
3
#include <chrono>
4
#include <cstdint>
5
#include <memory>
6
#include <string>
7

            
8
#include "envoy/access_log/access_log.h"
9
#include "envoy/api/api.h"
10
#include "envoy/common/mutex_tracer.h"
11
#include "envoy/common/random_generator.h"
12
#include "envoy/config/trace/v3/http_tracer.pb.h"
13
#include "envoy/config/xds_manager.h"
14
#include "envoy/event/timer.h"
15
#include "envoy/grpc/context.h"
16
#include "envoy/http/context.h"
17
#include "envoy/http/http_server_properties_cache.h"
18
#include "envoy/init/manager.h"
19
#include "envoy/local_info/local_info.h"
20
#include "envoy/network/listen_socket.h"
21
#include "envoy/runtime/runtime.h"
22
#include "envoy/secret/secret_manager.h"
23
#include "envoy/server/admin.h"
24
#include "envoy/server/configuration.h"
25
#include "envoy/server/drain_manager.h"
26
#include "envoy/server/hot_restart.h"
27
#include "envoy/server/lifecycle_notifier.h"
28
#include "envoy/server/listener_manager.h"
29
#include "envoy/server/options.h"
30
#include "envoy/server/overload/overload_manager.h"
31
#include "envoy/ssl/context_manager.h"
32
#include "envoy/thread_local/thread_local.h"
33
#include "envoy/tracing/tracer.h"
34
#include "envoy/upstream/cluster_manager.h"
35

            
36
namespace Envoy {
37

            
38
namespace Stats {
39
class SinkPredicates;
40
}
41

            
42
namespace Server {
43

            
44
/**
45
 * An instance of the running server.
46
 */
47
class Instance {
48
public:
49
11670
  virtual ~Instance() = default;
50

            
51
  /**
52
   * Runs the server.
53
   */
54
  virtual void run() PURE;
55

            
56
  /**
57
   * @return OptRef<Admin> the global HTTP admin endpoint for the server.
58
   */
59
  virtual OptRef<Admin> admin() PURE;
60

            
61
  /**
62
   * @return Api::Api& the API used by the server.
63
   */
64
  virtual Api::Api& api() PURE;
65

            
66
  /**
67
   * @return Upstream::ClusterManager& singleton for use by the entire server.
68
   */
69
  virtual Upstream::ClusterManager& clusterManager() PURE;
70

            
71
  /**
72
   * @return const Upstream::ClusterManager& singleton for use by the entire server.
73
   */
74
  virtual const Upstream::ClusterManager& clusterManager() const PURE;
75

            
76
  /**
77
   * @return const Http::HttpServerPropertiesCacheManager& instance for use by the entire server.
78
   */
79
  virtual Http::HttpServerPropertiesCacheManager& httpServerPropertiesCacheManager() PURE;
80

            
81
  /**
82
   * @return Ssl::ContextManager& singleton for use by the entire server.
83
   */
84
  virtual Ssl::ContextManager& sslContextManager() PURE;
85

            
86
  /**
87
   * @return Event::Dispatcher& the main thread's dispatcher. This dispatcher should be used
88
   *         for all singleton processing.
89
   */
90
  virtual Event::Dispatcher& dispatcher() PURE;
91

            
92
  /**
93
   * @return Network::DnsResolverSharedPtr the singleton DNS resolver for the server.
94
   */
95
  virtual Network::DnsResolverSharedPtr dnsResolver() PURE;
96

            
97
  /**
98
   * Close the server's listening sockets and begin draining the listeners.
99
   * @param options - if provided, options are passed through to shutdownListener.
100
   */
101
  virtual void
102
  drainListeners(OptRef<const Network::ExtraShutdownListenerOptions> options = absl::nullopt) PURE;
103

            
104
  /**
105
   * @return DrainManager& singleton for use by the entire server.
106
   */
107
  virtual DrainManager& drainManager() PURE;
108

            
109
  /**
110
   * @return AccessLogManager for use by the entire server.
111
   */
112
  virtual AccessLog::AccessLogManager& accessLogManager() PURE;
113

            
114
  /**
115
   * Toggle whether the server fails or passes external healthchecks.
116
   */
117
  virtual void failHealthcheck(bool fail) PURE;
118

            
119
  /**
120
   * @return whether external healthchecks are currently failed or not.
121
   */
122
  virtual bool healthCheckFailed() PURE;
123

            
124
  /**
125
   * @return the server's hot restarter.
126
   */
127
  virtual HotRestart& hotRestart() PURE;
128

            
129
  /**
130
   * @return the server's init manager. This can be used for extensions that need to initialize
131
   *         after cluster manager init but before the server starts listening. All extensions
132
   *         should register themselves during configuration load. initialize() will be called on
133
   *         each registered target after cluster manager init but before the server starts
134
   *         listening. Once all targets have initialized and invoked their callbacks, the server
135
   *         will start listening.
136
   */
137
  virtual Init::Manager& initManager() PURE;
138

            
139
  /**
140
   * @return the server's listener manager.
141
   */
142
  virtual ListenerManager& listenerManager() PURE;
143

            
144
  /**
145
   * @return the server's global mutex tracer, if it was instantiated. Nullptr otherwise.
146
   */
147
  virtual Envoy::MutexTracer* mutexTracer() PURE;
148

            
149
  /**
150
   * @return the server's overload manager.
151
   */
152
  virtual OverloadManager& overloadManager() PURE;
153

            
154
  /**
155
   * @return the server's null overload manager in case we want to skip overloading the server.
156
   */
157
  virtual OverloadManager& nullOverloadManager() PURE;
158

            
159
  /**
160
   * @return the server's secret manager
161
   */
162
  virtual Secret::SecretManager& secretManager() PURE;
163

            
164
  /**
165
   * @return the server's CLI options.
166
   */
167
  virtual const Options& options() PURE;
168

            
169
  /**
170
   * @return Runtime::Loader& the singleton runtime loader for the server.
171
   */
172
  virtual Runtime::Loader& runtime() PURE;
173

            
174
  /**
175
   * @return ServerLifecycleNotifier& the singleton lifecycle notifier for the server.
176
   */
177
  virtual ServerLifecycleNotifier& lifecycleNotifier() PURE;
178

            
179
  /**
180
   * Shutdown the server gracefully.
181
   */
182
  virtual void shutdown() PURE;
183

            
184
  /**
185
   * @return whether the shutdown method has been called.
186
   */
187
  virtual bool isShutdown() PURE;
188

            
189
  /**
190
   * Shutdown the server's admin processing. This includes the admin API, stat flushing, etc.
191
   */
192
  virtual void shutdownAdmin() PURE;
193

            
194
  /**
195
   * @return Singleton::Manager& the server-wide singleton manager.
196
   */
197
  virtual Singleton::Manager& singletonManager() PURE;
198

            
199
  /**
200
   * @return the time that the server started during the current hot restart epoch.
201
   */
202
  virtual time_t startTimeCurrentEpoch() PURE;
203

            
204
  /**
205
   * @return the time that the server started the first hot restart epoch.
206
   */
207
  virtual time_t startTimeFirstEpoch() PURE;
208

            
209
  /**
210
   * @return the server-wide stats store.
211
   */
212
  virtual Stats::Store& stats() PURE;
213

            
214
  /**
215
   * @return the server-wide grpc context.
216
   */
217
  virtual Grpc::Context& grpcContext() PURE;
218

            
219
  /**
220
   * @return the server-wide http context.
221
   */
222
  virtual Http::Context& httpContext() PURE;
223

            
224
  /**
225
   * @return the server-wide router context.
226
   */
227
  virtual Router::Context& routerContext() PURE;
228

            
229
  /**
230
   * @return the server-wide process context.
231
   */
232
  virtual ProcessContextOptRef processContext() PURE;
233

            
234
  /**
235
   * @return ThreadLocal::Instance& the thread local storage engine for the server. This is used to
236
   *         allow runtime lockless updates to configuration, etc. across multiple threads.
237
   */
238
  virtual ThreadLocal::Instance& threadLocal() PURE;
239

            
240
  /**
241
   * @return information about the local environment the server is running in.
242
   */
243
  virtual LocalInfo::LocalInfo& localInfo() const PURE;
244

            
245
  /**
246
   * @return the time source used for the server.
247
   */
248
  virtual TimeSource& timeSource() PURE;
249

            
250
  /**
251
   * Flush the stats sinks outside of a flushing interval.
252
   * Note: stats flushing may not be synchronous.
253
   * Therefore, this function may return prior to flushing taking place.
254
   */
255
  virtual void flushStats() PURE;
256

            
257
  /**
258
   * @return ProtobufMessage::ValidationContext& validation context for configuration
259
   *         messages.
260
   */
261
  virtual ProtobufMessage::ValidationContext& messageValidationContext() PURE;
262

            
263
  /**
264
   * @return ProtobufMessage::ValidationVistior& validation visitor for configuration
265
   *         messages.
266
   */
267
  virtual ProtobufMessage::ValidationVisitor& messageValidationVisitor() PURE;
268

            
269
  /**
270
   * @return const StatsConfig& the configuration of server stats.
271
   */
272
  virtual Configuration::StatsConfig& statsConfig() PURE;
273

            
274
  /**
275
   * @return the server regex engine.
276
   */
277
  virtual Regex::Engine& regexEngine() PURE;
278

            
279
  /**
280
   * @return envoy::config::bootstrap::v3::Bootstrap& the servers bootstrap configuration.
281
   */
282
  virtual envoy::config::bootstrap::v3::Bootstrap& bootstrap() PURE;
283

            
284
  /**
285
   * @return Configuration::ServerFactoryContext& factory context for filters.
286
   */
287
  virtual Configuration::ServerFactoryContext& serverFactoryContext() PURE;
288

            
289
  /**
290
   * @return Configuration::TransportSocketFactoryContext& factory context for transport sockets.
291
   */
292
  virtual Configuration::TransportSocketFactoryContext& transportSocketFactoryContext() PURE;
293

            
294
  /**
295
   * Set the default server-wide tracer provider configuration that will be used as a fallback
296
   * if an "envoy.filters.network.http_connection_manager" filter that has tracing enabled doesn't
297
   * define a tracer provider in-place.
298
   *
299
   * Once deprecation window for the tracer provider configuration in the bootstrap config is over,
300
   * this method will no longer be necessary.
301
   */
302
  virtual void
303
  setDefaultTracingConfig(const envoy::config::trace::v3::Tracing& tracing_config) PURE;
304

            
305
  /**
306
   * Return the default for whether reuse_port is enabled or not. This was added as part of
307
   * fixing https://github.com/envoyproxy/envoy/issues/15794. It is required to know what the
308
   * default was of parent processes during hot restart was, because otherwise switching the
309
   * default on the fly will break existing deployments.
310
   * TODO(mattklein123): This can be removed when version 1.20.0 is no longer supported.
311
   */
312
  virtual bool enableReusePortDefault() PURE;
313

            
314
  /**
315
   * Set predicates for filtering stats to be flushed to sinks.
316
   */
317
  virtual void
318
  setSinkPredicates(std::unique_ptr<Envoy::Stats::SinkPredicates>&& sink_predicates) PURE;
319

            
320
  /**
321
   * @return Envoy's xDS manager.
322
   */
323
  virtual Config::XdsManager& xdsManager() PURE;
324
};
325

            
326
// Pick a class HdsDelegate inherits from
327
class HdsDelegateApi : public Logger::Loggable<Logger::Id::upstream> {
328
public:
329
63
  virtual ~HdsDelegateApi() = default;
330
};
331

            
332
} // namespace Server
333
} // namespace Envoy