forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_impl.h
140 lines (128 loc) · 5.99 KB
/
options_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
#pragma once
#include <chrono>
#include <cstdint>
#include <string>
#include "envoy/common/exception.h"
#include "envoy/server/options.h"
#include "envoy/stats/stats_options.h"
#include "common/stats/stats_options_impl.h"
#include "spdlog/spdlog.h"
namespace Envoy {
/**
* Implementation of Server::Options.
*/
class OptionsImpl : public Server::Options {
public:
/**
* Parameters are max_num_stats, max_stat_name_len, hot_restart_enabled
*/
typedef std::function<std::string(uint64_t, uint64_t, bool)> HotRestartVersionCb;
/**
* @throw NoServingException if Envoy has already done everything specified by the argv (e.g.
* print the hot restart version) and it's time to exit without serving HTTP traffic. The
* caller should exit(0) after any necessary cleanup.
* @throw MalformedArgvException if something is wrong with the arguments (invalid flag or flag
* value). The caller should call exit(1) after any necessary cleanup.
*/
OptionsImpl(int argc, const char* const* argv, const HotRestartVersionCb& hot_restart_version_cb,
spdlog::level::level_enum default_log_level);
// Setters for option fields. These are not part of the Options interface.
void setBaseId(uint64_t base_id) { base_id_ = base_id; };
void setConcurrency(uint32_t concurrency) { concurrency_ = concurrency; }
void setConfigPath(const std::string& config_path) { config_path_ = config_path; }
void setConfigYaml(const std::string& config_yaml) { config_yaml_ = config_yaml; }
void setV2ConfigOnly(bool v2_config_only) { v2_config_only_ = v2_config_only; }
void setAdminAddressPath(const std::string& admin_address_path) {
admin_address_path_ = admin_address_path;
}
void setLocalAddressIpVersion(Network::Address::IpVersion local_address_ip_version) {
local_address_ip_version_ = local_address_ip_version;
}
void setDrainTime(std::chrono::seconds drain_time) { drain_time_ = drain_time; }
void setLogLevel(spdlog::level::level_enum log_level) { log_level_ = log_level; }
void setLogFormat(const std::string& log_format) { log_format_ = log_format; }
void setLogPath(const std::string& log_path) { log_path_ = log_path; }
void setParentShutdownTime(std::chrono::seconds parent_shutdown_time) {
parent_shutdown_time_ = parent_shutdown_time;
}
void setRestartEpoch(uint64_t restart_epoch) { restart_epoch_ = restart_epoch; }
void setMode(Server::Mode mode) { mode_ = mode; }
void setFileFlushIntervalMsec(std::chrono::milliseconds file_flush_interval_msec) {
file_flush_interval_msec_ = file_flush_interval_msec;
}
void setServiceClusterName(const std::string& service_cluster) {
service_cluster_ = service_cluster;
}
void setServiceNodeName(const std::string& service_node) { service_node_ = service_node; }
void setServiceZone(const std::string& service_zone) { service_zone_ = service_zone; }
void setMaxStats(uint64_t max_stats) { max_stats_ = max_stats; }
void setStatsOptions(Stats::StatsOptionsImpl stats_options) { stats_options_ = stats_options; }
void setHotRestartDisabled(bool hot_restart_disabled) {
hot_restart_disabled_ = hot_restart_disabled;
}
// Server::Options
uint64_t baseId() const override { return base_id_; }
uint32_t concurrency() const override { return concurrency_; }
const std::string& configPath() const override { return config_path_; }
const std::string& configYaml() const override { return config_yaml_; }
bool v2ConfigOnly() const override { return v2_config_only_; }
const std::string& adminAddressPath() const override { return admin_address_path_; }
Network::Address::IpVersion localAddressIpVersion() const override {
return local_address_ip_version_;
}
std::chrono::seconds drainTime() const override { return drain_time_; }
spdlog::level::level_enum logLevel() const override { return log_level_; }
const std::string& logFormat() const override { return log_format_; }
const std::string& logPath() const override { return log_path_; }
std::chrono::seconds parentShutdownTime() const override { return parent_shutdown_time_; }
uint64_t restartEpoch() const override { return restart_epoch_; }
Server::Mode mode() const override { return mode_; }
std::chrono::milliseconds fileFlushIntervalMsec() const override {
return file_flush_interval_msec_;
}
const std::string& serviceClusterName() const override { return service_cluster_; }
const std::string& serviceNodeName() const override { return service_node_; }
const std::string& serviceZone() const override { return service_zone_; }
uint64_t maxStats() const override { return max_stats_; }
const Stats::StatsOptions& statsOptions() const override { return stats_options_; }
bool hotRestartDisabled() const override { return hot_restart_disabled_; }
private:
uint64_t base_id_;
uint32_t concurrency_;
std::string config_path_;
std::string config_yaml_;
bool v2_config_only_;
std::string admin_address_path_;
Network::Address::IpVersion local_address_ip_version_;
spdlog::level::level_enum log_level_;
std::string log_format_;
std::string log_path_;
uint64_t restart_epoch_;
std::string service_cluster_;
std::string service_node_;
std::string service_zone_;
std::chrono::milliseconds file_flush_interval_msec_;
std::chrono::seconds drain_time_;
std::chrono::seconds parent_shutdown_time_;
Server::Mode mode_;
uint64_t max_stats_;
Stats::StatsOptionsImpl stats_options_;
bool hot_restart_disabled_;
};
/**
* Thrown when an OptionsImpl was not constructed because all of Envoy's work is done (for example,
* it was started with --help and it's already printed a help message) so all that's left to do is
* exit successfully.
*/
class NoServingException : public EnvoyException {
public:
NoServingException() : EnvoyException("NoServingException") {}
};
/**
* Thrown when an OptionsImpl was not constructed because the argv was invalid.
*/
class MalformedArgvException : public EnvoyException {
public:
MalformedArgvException(const std::string& what) : EnvoyException(what) {}
};
} // namespace Envoy