using std::ostringstream;
using std::string;
-int parse_log_client_options(CephContext *cct,
- map<string,string> &log_to_monitors,
- map<string,string> &log_to_syslog,
- map<string,string> &log_channels,
- map<string,string> &log_prios,
- map<string,string> &log_to_graylog,
- map<string,string> &log_to_graylog_host,
- map<string,string> &log_to_graylog_port,
- uuid_d &fsid,
- string &host)
-{
- ostringstream oss;
-
- int r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_monitors"), oss,
- &log_to_monitors, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_monitors'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_syslog"), oss,
- &log_to_syslog, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_syslog'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_syslog_facility"), oss,
- &log_channels, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_syslog_facility'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_syslog_level"), oss,
- &log_prios, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_syslog_level'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_graylog"), oss,
- &log_to_graylog, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_graylog'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_graylog_host"), oss,
- &log_to_graylog_host, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_graylog_host'" << dendl;
- return r;
- }
-
- r = get_conf_str_map_helper(
- cct->_conf.get_val<string>("clog_to_graylog_port"), oss,
- &log_to_graylog_port, CLOG_CONFIG_DEFAULT_KEY);
- if (r < 0) {
- lderr(cct) << __func__ << " error parsing 'clog_to_graylog_port'" << dendl;
- return r;
- }
-
- fsid = cct->_conf.get_val<uuid_d>("fsid");
- host = cct->_conf->host;
- return 0;
-}
-
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
static ostream& _prefix(std::ostream *_dout, LogClient *logc) {
}
}
-void LogChannel::update_config(map<string,string> &log_to_monitors,
- map<string,string> &log_to_syslog,
- map<string,string> &log_channels,
- map<string,string> &log_prios,
- map<string,string> &log_to_graylog,
- map<string,string> &log_to_graylog_host,
- map<string,string> &log_to_graylog_port,
- uuid_d &fsid,
- string &host)
+void LogChannel::update_config(const clog_targets_conf_t& conf_strings)
{
- ldout(cct, 20) << __func__ << " log_to_monitors " << log_to_monitors
- << " log_to_syslog " << log_to_syslog
- << " log_channels " << log_channels
- << " log_prios " << log_prios
+ ldout(cct, 20) << __func__ << " log_to_monitors " << conf_strings.log_to_monitors
+ << " log_to_syslog " << conf_strings.log_to_syslog
+ << " log_channels " << conf_strings.log_channels
+ << " log_prios " << conf_strings.log_prios
<< dendl;
- bool to_monitors = (get_str_map_key(log_to_monitors, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY) == "true");
- bool to_syslog = (get_str_map_key(log_to_syslog, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY) == "true");
- string syslog_facility = get_str_map_key(log_channels, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY);
- string prio = get_str_map_key(log_prios, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY);
- bool to_graylog = (get_str_map_key(log_to_graylog, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY) == "true");
- string graylog_host = get_str_map_key(log_to_graylog_host, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY);
- string graylog_port_str = get_str_map_key(log_to_graylog_port, log_channel,
- &CLOG_CONFIG_DEFAULT_KEY);
- int graylog_port = atoi(graylog_port_str.c_str());
+
+ bool to_monitors = (conf_strings.log_to_monitors == "true");
+ bool to_syslog = (conf_strings.log_to_syslog == "true");
+ bool to_graylog = (conf_strings.log_to_graylog == "true");
+ auto graylog_port = atoi(conf_strings.log_to_graylog_port.c_str());
set_log_to_monitors(to_monitors);
set_log_to_syslog(to_syslog);
- set_syslog_facility(syslog_facility);
- set_log_prio(prio);
+ set_syslog_facility(conf_strings.log_channels);
+ set_log_prio(conf_strings.log_prios);
if (to_graylog && !graylog) { /* should but isn't */
graylog = std::make_shared<ceph::logging::Graylog>("clog");
}
if (to_graylog && graylog) {
- graylog->set_fsid(fsid);
- graylog->set_hostname(host);
+ graylog->set_fsid(conf_strings.fsid);
+ graylog->set_hostname(conf_strings.host);
}
- if (graylog && (!graylog_host.empty()) && (graylog_port != 0)) {
- graylog->set_destination(graylog_host, graylog_port);
+ if (graylog && !conf_strings.log_to_graylog_host.empty() && (graylog_port != 0)) {
+ graylog->set_destination(conf_strings.log_to_graylog_host, graylog_port);
}
ldout(cct, 10) << __func__
<< " to_monitors: " << (to_monitors ? "true" : "false")
<< " to_syslog: " << (to_syslog ? "true" : "false")
- << " syslog_facility: " << syslog_facility
- << " prio: " << prio
+ << " syslog_facility: " << conf_strings.log_channels
+ << " prio: " << conf_strings.log_prios
<< " to_graylog: " << (to_graylog ? "true" : "false")
- << " graylog_host: " << graylog_host
+ << " graylog_host: " << conf_strings.log_to_graylog_host
<< " graylog_port: " << graylog_port
<< ")" << dendl;
}
+clog_targets_conf_t LogChannel::parse_client_options(CephContext* conf_cct)
+{
+ auto parsed_options = parse_log_client_options(conf_cct);
+ update_config(parsed_options);
+ return parsed_options;
+}
+
+clog_targets_conf_t LogChannel::parse_log_client_options(CephContext* cct)
+{
+ clog_targets_conf_t targets;
+
+ targets.log_to_monitors =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_monitors"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_to_syslog =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_channels =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog_facility"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_prios =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_syslog_level"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_to_graylog =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_to_graylog_host =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog_host"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+ targets.log_to_graylog_port =
+ get_value_via_strmap(cct->_conf.get_val<string>("clog_to_graylog_port"),
+ log_channel, CLOG_CONFIG_DEFAULT_KEY);
+
+ targets.fsid = cct->_conf.get_val<uuid_d>("fsid");
+ targets.host = cct->_conf->host;
+ return targets;
+}
+
void LogChannel::do_log(clog_type prio, std::stringstream& ss)
{
while (!ss.eof()) {
}
}
-int parse_log_client_options(CephContext *cct,
- std::map<std::string,std::string> &log_to_monitors,
- std::map<std::string,std::string> &log_to_syslog,
- std::map<std::string,std::string> &log_channels,
- std::map<std::string,std::string> &log_prios,
- std::map<std::string,std::string> &log_to_graylog,
- std::map<std::string,std::string> &log_to_graylog_host,
- std::map<std::string,std::string> &log_to_graylog_port,
- uuid_d &fsid,
- std::string &host);
+struct clog_targets_conf_t {
+ std::string log_to_monitors;
+ std::string log_to_syslog;
+ std::string log_channels;
+ std::string log_prios;
+ std::string log_to_graylog;
+ std::string log_to_graylog_host;
+ std::string log_to_graylog_port;
+ uuid_d fsid; // only 16B. Simpler as a copy.
+ std::string host;
+};
/** Manage where we output to and at which priority
*
typedef std::shared_ptr<LogChannel> Ref;
/**
- * update config values from parsed k/v std::map for each config option
+ * Query the configuration database in conf_cct for configuration
+ * parameters. Pick out the relevant values based on our channel name.
+ * Update the logger configuration based on these values.
*
- * Pick out the relevant value based on our channel.
+ * Return a collection of configuration strings.
*/
- void update_config(std::map<std::string,std::string> &log_to_monitors,
- std::map<std::string,std::string> &log_to_syslog,
- std::map<std::string,std::string> &log_channels,
- std::map<std::string,std::string> &log_prios,
- std::map<std::string,std::string> &log_to_graylog,
- std::map<std::string,std::string> &log_to_graylog_host,
- std::map<std::string,std::string> &log_to_graylog_port,
- uuid_d &fsid,
- std::string &host);
+ clog_targets_conf_t parse_client_options(CephContext* conf_cct);
void do_log(clog_type prio, std::stringstream& ss);
void do_log(clog_type prio, const std::string& s);
bool log_to_monitors;
std::shared_ptr<ceph::logging::Graylog> graylog;
+ /**
+ * update config values from parsed k/v std::map for each config option
+ */
+ void update_config(const clog_targets_conf_t& conf_strings);
+
+ clog_targets_conf_t parse_log_client_options(CephContext* conf_cct);
};
typedef LogChannel::Ref LogChannelRef;
vector<string> get_str_vec(const string& str, const char *delims)
{
vector<string> result;
- get_str_vec(str, delims, result);
+ for_each_substr(str, delims, [&result] (auto token) {
+ result.emplace_back(token.begin(), token.end());
+ });
return result;
}
int get_json_str_map(
const string &str,
ostream &ss,
- map<string,string> *str_map,
+ str_map_t *str_map,
bool fallback_to_plain)
{
json_spirit::mValue json;
int get_str_map(
const string &str,
- map<string,string> *str_map,
+ str_map_t* str_map,
const char *delims)
{
- list<string> pairs;
- get_str_list(str, delims, pairs);
- for (list<string>::iterator i = pairs.begin(); i != pairs.end(); ++i) {
- size_t equal = i->find('=');
+ auto pairs = get_str_list(str, delims);
+ for (const auto& pr : pairs) {
+ size_t equal = pr.find('=');
if (equal == string::npos)
- (*str_map)[*i] = string();
+ (*str_map)[pr] = string();
else {
- const string key = trim(i->substr(0, equal));
+ const string key = trim(pr.substr(0, equal));
equal++;
- const string value = trim(i->substr(equal));
+ const string value = trim(pr.substr(equal));
(*str_map)[key] = value;
}
}
return 0;
}
+str_map_t get_str_map(
+ const string& str,
+ const char* delim)
+{
+ auto pairs = get_str_list(str, delim);
+ str_map_t str_map;
+
+ for (const auto& pr : pairs) {
+ auto equal = pr.find('=');
+
+ // is the format 'K=V' or just 'K'?
+ if (equal == std::string::npos) {
+ str_map[pr] = std::string{};
+ } else {
+ const string key = trim(pr.substr(0, equal));
+ equal++;
+ const string value = trim(pr.substr(equal));
+ str_map[key] = value;
+ }
+ }
+
+ return str_map;
+}
+
string get_str_map_value(
- const map<string,string> &str_map,
+ const str_map_t &str_map,
const string &key,
const string *def_val)
{
- map<string,string>::const_iterator p = str_map.find(key);
+ auto p = str_map.find(key);
// key exists in str_map
if (p != str_map.end()) {
}
// key DNE in str_map and def_val was specified
- if (def_val != NULL)
+ if (def_val != nullptr)
return *def_val;
// key DNE in str_map, no def_val was specified
}
string get_str_map_key(
- const map<string,string> &str_map,
+ const str_map_t &str_map,
const string &key,
const string *fallback_key)
{
- map<string,string>::const_iterator p = str_map.find(key);
+ auto p = str_map.find(key);
if (p != str_map.end())
return p->second;
- if (fallback_key != NULL) {
+ if (fallback_key != nullptr) {
p = str_map.find(*fallback_key);
if (p != str_map.end())
return p->second;
int get_conf_str_map_helper(
const string &str,
ostringstream &oss,
- map<string,string> *m,
- const string &def_key)
+ str_map_t* str_map,
+ const string &default_key)
{
- int r = get_str_map(str, m);
+ get_str_map(str, str_map);
- if (r < 0) {
- return r;
- }
-
- if (r >= 0 && m->size() == 1) {
- map<string,string>::iterator p = m->begin();
+ if (str_map->size() == 1) {
+ auto p = str_map->begin();
if (p->second.empty()) {
string s = p->first;
- m->erase(s);
- (*m)[def_key] = s;
+ str_map->erase(s);
+ (*str_map)[default_key] = s;
}
}
- return r;
+ return 0;
+}
+
+std::string get_value_via_strmap(
+ const string& conf_string,
+ std::string_view default_key)
+{
+ auto mp = get_str_map(conf_string);
+ if (mp.size() != 1) {
+ return "";
+ }
+
+ // if the one-elem "map" is of the form { 'value' : '' }
+ // replace it with { 'default_key' : 'value' }
+ const auto& [k, v] = *(mp.begin());
+ if (v.empty()) {
+ return k;
+ }
+ return v;
+}
+
+std::string get_value_via_strmap(
+ const string& conf_string,
+ const string& key,
+ std::string_view default_key)
+{
+ auto mp = get_str_map(conf_string);
+ if (mp.size() != 1) {
+ return std::string{};
+ }
+
+ // if the one-elem "map" is of the form { 'value' : '' }
+ // replace it with { 'default_key' : 'value' }
+ const auto& [k, v] = *(mp.begin());
+ if (v.empty()) {
+ return k;
+ }
+ if (k == key) {
+ return k;
+ }
+ if (k == default_key) {
+ return v;
+ }
+
+ return string{};
}
#include <string>
#include <sstream>
+using str_map_t = std::map<std::string,std::string>;
+
/**
* Parse **str** and set **str_map** with the key/value pairs read
* from it. The format of **str** is either a well formed JSON object
* @param [in] fallback_to_plain attempt parsing as plain-text if json fails
* @return **0** on success or a -EINVAL on error.
*/
-extern int get_json_str_map(
+int get_json_str_map(
const std::string &str,
std::ostream &ss,
- std::map<std::string,std::string> *str_map,
+ str_map_t* str_map,
bool fallback_to_plain = true);
/**
* @param [out] str_map key/value pairs parsed from str
* @return **0**
*/
-extern int get_str_map(
+int get_str_map(
const std::string &str,
- std::map<std::string,std::string> *str_map,
+ str_map_t* str_map,
const char *delims = CONST_DELIMS);
+// an alternate form (as we never fail):
+str_map_t get_str_map(
+ const std::string& str,
+ const char* delim = CONST_DELIMS);
+
/**
* Returns the value of **key** in **str_map** if available.
*
* @param[in] key The key to search for in the map
* @param[in] def_val The value to return in case **key** is not present
*/
-extern std::string get_str_map_value(
- const std::map<std::string,std::string> &str_map,
+std::string get_str_map_value(
+ const str_map_t& str_map,
const std::string &key,
- const std::string *def_val = NULL);
+ const std::string *def_val = nullptr);
/**
* Returns the value of **key** in **str_map** if available.
* @param[in] def_key Key to fallback to if **key** is not present
* in **str_map**
*/
-extern std::string get_str_map_key(
- const std::map<std::string,std::string> &str_map,
+std::string get_str_map_key(
+ const str_map_t& str_map,
const std::string &key,
- const std::string *fallback_key = NULL);
-
+ const std::string *fallback_key = nullptr);
// This function's only purpose is to check whether a given map has only
// ONE key with an empty value (which would mean that 'get_str_map()' read
int get_conf_str_map_helper(
const std::string &str,
std::ostringstream &oss,
- std::map<std::string,std::string> *m,
- const std::string &def_key);
+ str_map_t* str_map,
+ const std::string &default_key);
+
+std::string get_value_via_strmap(
+ const std::string& conf_string,
+ std::string_view default_key);
+
+std::string get_value_via_strmap(
+ const std::string& conf_string,
+ const std::string& key,
+ std::string_view default_key);
#endif
void MDSRankDispatcher::update_log_config()
{
- map<string,string> log_to_monitors;
- map<string,string> log_to_syslog;
- map<string,string> log_channel;
- map<string,string> log_prio;
- map<string,string> log_to_graylog;
- map<string,string> log_to_graylog_host;
- map<string,string> log_to_graylog_port;
- uuid_d fsid;
- string host;
-
- if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host) == 0)
- clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
- dout(10) << __func__ << " log_to_monitors " << log_to_monitors << dendl;
+ auto parsed_options = clog->parse_client_options(g_ceph_context);
+ dout(10) << __func__ << " log_to_monitors " << parsed_options.log_to_monitors << dendl;
}
void MDSRank::create_logger()
std::lock_guard l(lock);
auto cl = monc.get_log_client()->create_channel(channel);
- map<string,string> log_to_monitors;
- map<string,string> log_to_syslog;
- map<string,string> log_channel;
- map<string,string> log_prio;
- map<string,string> log_to_graylog;
- map<string,string> log_to_graylog_host;
- map<string,string> log_to_graylog_port;
- uuid_d fsid;
- string host;
- if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host) == 0)
- cl->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
+ cl->parse_client_options(g_ceph_context);
cl->do_log(prio, message);
}
metadata = m;
auto p = m.find("device_ids");
if (p != m.end()) {
- std::map<std::string,std::string> devs, paths; // devname -> id or path
- get_str_map(p->second, &devs, ",; ");
+ std::map<std::string,std::string> paths; // devname -> id or path
+ auto devs = get_str_map(p->second, ",; ");
auto q = m.find("device_paths");
if (q != m.end()) {
get_str_map(q->second, &paths, ",; ");
void MgrStandby::_update_log_config()
{
- map<string,string> log_to_monitors;
- map<string,string> log_to_syslog;
- map<string,string> log_channel;
- map<string,string> log_prio;
- map<string,string> log_to_graylog;
- map<string,string> log_to_graylog_host;
- map<string,string> log_to_graylog_port;
- uuid_d fsid;
- string host;
-
- if (parse_log_client_options(cct, log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host) == 0) {
- clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
- audit_clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
- }
+ clog->parse_client_options(cct);
+ audit_clog->parse_client_options(cct);
}
void MgrStandby::handle_mgr_map(ref_t<MMgrMap> mmap)
void Monitor::update_log_clients()
{
- map<string,string> log_to_monitors;
- map<string,string> log_to_syslog;
- map<string,string> log_channel;
- map<string,string> log_prio;
- map<string,string> log_to_graylog;
- map<string,string> log_to_graylog_host;
- map<string,string> log_to_graylog_port;
- uuid_d fsid;
- string host;
-
- if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host))
- return;
-
- clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
-
- audit_clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
+ clog->parse_client_options(g_ceph_context);
+ audit_clog->parse_client_options(g_ceph_context);
}
int Monitor::sanitize_options()
dout(20) << "prior dead_mon_buckets: " << old_dead_buckets
<< "; down_mon_buckets: " << down_mon_buckets
<< "; up_mon_buckets: " << up_mon_buckets << dendl;
- for (auto di : down_mon_buckets) {
+ for (const auto& di : down_mon_buckets) {
if (!up_mon_buckets.count(di.first)) {
dead_mon_buckets[di.first] = di.second;
}
void OSD::update_log_config()
{
- map<string,string> log_to_monitors;
- map<string,string> log_to_syslog;
- map<string,string> log_channel;
- map<string,string> log_prio;
- map<string,string> log_to_graylog;
- map<string,string> log_to_graylog_host;
- map<string,string> log_to_graylog_port;
- uuid_d fsid;
- string host;
-
- if (parse_log_client_options(cct, log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host) == 0)
- clog->update_config(log_to_monitors, log_to_syslog,
- log_channel, log_prio, log_to_graylog,
- log_to_graylog_host, log_to_graylog_port,
- fsid, host);
- derr << "log_to_monitors " << log_to_monitors << dendl;
+ auto parsed_options = clog->parse_client_options(cct);
+ derr << "log_to_monitors " << parsed_options.log_to_monitors << dendl;
}
void OSD::check_config()
}
};
-
-static map<string,string> get_str_map(const string &str) {
- map<string,string> m;
- get_str_map(str, &m, ";, \t");
- return m;
-}
-
-
static int get_actual_key_from_conf(const DoutPrefixProvider* dpp,
CephContext *cct,
std::string_view key_id,
#ifndef CEPH_RGW_KMS_H
#define CEPH_RGW_KMS_H
+#include <string>
+
static const std::string RGW_SSE_KMS_BACKEND_TESTING = "testing";
static const std::string RGW_SSE_KMS_BACKEND_BARBICAN = "barbican";
static const std::string RGW_SSE_KMS_BACKEND_VAULT = "vault";