This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
configuration_impl.h
185 lines (161 loc) · 7.03 KB
/
configuration_impl.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#include <chrono>
#include <cstdint>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/trace/v3/http_tracer.pb.h"
#include "envoy/config/typed_config.h"
#include "envoy/http/filter.h"
#include "envoy/network/filter.h"
#include "envoy/server/configuration.h"
#include "envoy/server/filter_config.h"
#include "envoy/server/instance.h"
#include "common/common/logger.h"
#include "common/network/resolver_impl.h"
#include "common/network/utility.h"
namespace Envoy {
namespace Server {
namespace Configuration {
/**
* Implemented for each Stats::Sink and registered via Registry::registerFactory() or
* the convenience class RegisterFactory.
*/
class StatsSinkFactory : public Config::TypedFactory {
public:
~StatsSinkFactory() override = default;
/**
* Create a particular Stats::Sink implementation. If the implementation is unable to produce a
* Stats::Sink with the provided parameters, it should throw an EnvoyException. The returned
* pointer should always be valid.
* @param config supplies the custom proto configuration for the Stats::Sink
* @param server supplies the server instance
*/
virtual Stats::SinkPtr createStatsSink(const Protobuf::Message& config,
Server::Configuration::ServerFactoryContext& server) PURE;
std::string category() const override { return "envoy.stats_sinks"; }
};
/**
* Utilities for creating a filter chain for a network connection.
*/
class FilterChainUtility {
public:
/**
* Given a connection and a list of factories, create a new filter chain. Chain creation will
* exit early if any filters immediately close the connection.
*/
static bool buildFilterChain(Network::FilterManager& filter_manager,
const std::vector<Network::FilterFactoryCb>& factories);
/**
* Given a ListenerFilterManager and a list of factories, create a new filter chain. Chain
* creation will exit early if any filters immediately close the connection.
*
* TODO(sumukhs): Coalesce with the above as they are very similar
*/
static bool buildFilterChain(Network::ListenerFilterManager& filter_manager,
const std::vector<Network::ListenerFilterFactoryCb>& factories);
/**
* Given a UdpListenerFilterManager and a list of factories, create a new filter chain. Chain
* creation will exit early if any filters immediately close the connection.
*/
static void
buildUdpFilterChain(Network::UdpListenerFilterManager& filter_manager,
Network::UdpReadFilterCallbacks& callbacks,
const std::vector<Network::UdpListenerFilterFactoryCb>& factories);
};
/**
* Implementation of Server::Configuration::Main that reads a configuration from
* a JSON file.
*/
class MainImpl : Logger::Loggable<Logger::Id::config>, public Main {
public:
/**
* MainImpl is created in two phases. In the first phase it is
* default-constructed without a configuration as part of the server. The
* server won't be fully populated yet. initialize() applies the
* configuration in the second phase, as it requires a fully populated server.
*
* @param bootstrap v2 bootstrap proto.
* @param server supplies the owning server.
* @param cluster_manager_factory supplies the cluster manager creation factory.
*/
void initialize(const envoy::config::bootstrap::v3::Bootstrap& bootstrap, Instance& server,
Upstream::ClusterManagerFactory& cluster_manager_factory);
// Server::Configuration::Main
Upstream::ClusterManager* clusterManager() override { return cluster_manager_.get(); }
std::list<Stats::SinkPtr>& statsSinks() override { return stats_sinks_; }
std::chrono::milliseconds statsFlushInterval() const override { return stats_flush_interval_; }
const Watchdog& mainThreadWatchdogConfig() const override { return *main_thread_watchdog_; }
const Watchdog& workerWatchdogConfig() const override { return *worker_watchdog_; }
private:
/**
* Initialize tracers and corresponding sinks.
*/
void initializeTracers(const envoy::config::trace::v3::Tracing& configuration, Instance& server);
void initializeStatsSinks(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
Instance& server);
/**
* Initialize watchdog(s). Call before accessing any watchdog configuration.
*/
void initializeWatchdogs(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
Instance& server);
std::unique_ptr<Upstream::ClusterManager> cluster_manager_;
std::list<Stats::SinkPtr> stats_sinks_;
std::chrono::milliseconds stats_flush_interval_;
std::unique_ptr<Watchdog> main_thread_watchdog_;
std::unique_ptr<Watchdog> worker_watchdog_;
};
class WatchdogImpl : public Watchdog {
public:
WatchdogImpl(const envoy::config::bootstrap::v3::Watchdog& watchdog, Instance& server);
std::chrono::milliseconds missTimeout() const override { return miss_timeout_; }
std::chrono::milliseconds megaMissTimeout() const override { return megamiss_timeout_; }
std::chrono::milliseconds killTimeout() const override { return kill_timeout_; }
std::chrono::milliseconds multiKillTimeout() const override { return multikill_timeout_; }
double multiKillThreshold() const override { return multikill_threshold_; }
Protobuf::RepeatedPtrField<envoy::config::bootstrap::v3::Watchdog::WatchdogAction>
actions() const override {
return actions_;
}
private:
std::chrono::milliseconds miss_timeout_;
std::chrono::milliseconds megamiss_timeout_;
std::chrono::milliseconds kill_timeout_;
std::chrono::milliseconds multikill_timeout_;
double multikill_threshold_;
Protobuf::RepeatedPtrField<envoy::config::bootstrap::v3::Watchdog::WatchdogAction> actions_;
};
/**
* Initial configuration that reads from JSON.
*/
class InitialImpl : public Initial {
public:
InitialImpl(const envoy::config::bootstrap::v3::Bootstrap& bootstrap);
// Server::Configuration::Initial
Admin& admin() override { return admin_; }
absl::optional<std::string> flagsPath() const override { return flags_path_; }
const envoy::config::bootstrap::v3::LayeredRuntime& runtime() override {
return layered_runtime_;
}
private:
struct AdminImpl : public Admin {
// Server::Configuration::Initial::Admin
const std::string& accessLogPath() const override { return access_log_path_; }
const std::string& profilePath() const override { return profile_path_; }
Network::Address::InstanceConstSharedPtr address() override { return address_; }
Network::Socket::OptionsSharedPtr socketOptions() override { return socket_options_; }
std::string access_log_path_;
std::string profile_path_;
Network::Address::InstanceConstSharedPtr address_;
Network::Socket::OptionsSharedPtr socket_options_;
};
AdminImpl admin_;
absl::optional<std::string> flags_path_;
envoy::config::bootstrap::v3::LayeredRuntime layered_runtime_;
};
} // namespace Configuration
} // namespace Server
} // namespace Envoy