forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_common.h
117 lines (96 loc) · 4.1 KB
/
main_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
#include "envoy/event/timer.h"
#include "envoy/runtime/runtime.h"
#include "common/common/thread.h"
#include "common/event/real_time_system.h"
#include "common/stats/thread_local_store.h"
#include "common/thread_local/thread_local_impl.h"
#include "server/options_impl.h"
#include "server/server.h"
#include "server/test_hooks.h"
#ifdef ENVOY_HANDLE_SIGNALS
#include "exe/signal_action.h"
#include "exe/terminate_handler.h"
#endif
namespace Envoy {
class ProdComponentFactory : public Server::ComponentFactory {
public:
// Server::DrainManagerFactory
Server::DrainManagerPtr createDrainManager(Server::Instance& server) override;
Runtime::LoaderPtr createRuntime(Server::Instance& server,
Server::Configuration::Initial& config) override;
};
class MainCommonBase {
public:
// Consumer must guarantee that all passed references are alive until this object is
// destructed.
MainCommonBase(OptionsImpl& options, Event::TimeSystem& time_system, TestHooks& test_hooks,
Server::ComponentFactory& component_factory,
std::unique_ptr<Runtime::RandomGenerator>&& random_generator,
Thread::ThreadFactory& thread_factory);
~MainCommonBase();
bool run();
// Will be null if options.mode() == Server::Mode::Validate
Server::Instance* server() { return server_.get(); }
using AdminRequestFn =
std::function<void(const Http::HeaderMap& response_headers, absl::string_view body)>;
// Makes an admin-console request by path, calling handler() when complete.
// The caller can initiate this from any thread, but it posts the request
// onto the main thread, so the handler is called asynchronously.
//
// This is designed to be called from downstream consoles, so they can access
// the admin console information stream without opening up a network port.
//
// This should only be called while run() is active; ensuring this is the
// responsibility of the caller.
//
// TODO(jmarantz): consider std::future for encapsulating this delayed request
// semantics, rather than a handler callback.
void adminRequest(absl::string_view path_and_query, absl::string_view method,
const AdminRequestFn& handler);
protected:
Envoy::OptionsImpl& options_;
Server::ComponentFactory& component_factory_;
Thread::ThreadFactory& thread_factory_;
std::unique_ptr<ThreadLocal::InstanceImpl> tls_;
std::unique_ptr<Server::HotRestart> restarter_;
std::unique_ptr<Stats::ThreadLocalStoreImpl> stats_store_;
std::unique_ptr<Logger::Context> logging_context_;
std::unique_ptr<Server::InstanceImpl> server_;
private:
void configureComponentLogLevels();
};
// TODO(jmarantz): consider removing this class; I think it'd be more useful to
// go through MainCommonBase directly.
class MainCommon {
public:
MainCommon(int argc, const char* const* argv);
bool run() { return base_.run(); }
// Makes an admin-console request by path, calling handler() when complete.
// The caller can initiate this from any thread, but it posts the request
// onto the main thread, so the handler is called asynchronously.
//
// This is designed to be called from downstream consoles, so they can access
// the admin console information stream without opening up a network port.
//
// This should only be called while run() is active; ensuring this is the
// responsibility of the caller.
void adminRequest(absl::string_view path_and_query, absl::string_view method,
const MainCommonBase::AdminRequestFn& handler) {
base_.adminRequest(path_and_query, method, handler);
}
static std::string hotRestartVersion(uint64_t max_num_stats, uint64_t max_stat_name_len,
bool hot_restart_enabled);
private:
#ifdef ENVOY_HANDLE_SIGNALS
Envoy::SignalAction handle_sigs;
Envoy::TerminateHandler log_on_terminate;
#endif
Envoy::OptionsImpl options_;
Event::RealTimeSystem real_time_system_;
DefaultTestHooks default_test_hooks_;
ProdComponentFactory prod_component_factory_;
Thread::ThreadFactoryImpl thread_factory_;
MainCommonBase base_;
};
} // namespace Envoy