in fb303/ServiceData.cpp [596:648]
ServiceData::SetOptionResult ServiceData::setOptionWithResult(
string_view key,
string_view value) {
// Check to see if a dynamic option is registered for this key
{
auto dynamicOptionsRLock = dynamicOptions_.rlock();
if (auto ptr = folly::get_ptr(*dynamicOptionsRLock, key)) {
if (ptr->setter) {
as_mutable(ptr->setter)(string{value});
}
return SetOptionResult::Dynamic;
}
}
// This is not a dynamic option.
// Set it in the static option map.
(*options_.wlock())[key] = string{value};
// Next check to see if we should update command line flags based
// on this static option name.
// By default allow modifying glog verbosity (options 'v' or 'vmodule')
auto useOptionsAsFlags = useOptionsAsFlags_.load(std::memory_order_relaxed);
static constexpr StringPiece blacklistedOptions[] = {
StringPiece{"logmailer"}, StringPiece{"whitelist_flags"}};
if (std::count(
std::begin(blacklistedOptions), std::end(blacklistedOptions), key) >
0) {
return SetOptionResult::CmdlineBlacklisted;
}
if (!(useOptionsAsFlags || key == "v" || key == "vmodule")) {
return SetOptionResult::CmdlineDisabled;
}
string res =
gflags::SetCommandLineOption(string{key}.c_str(), string{value}.c_str());
if (res.empty()) {
LOG(ERROR) << "Couldn't set flag 'FLAGS_" << key << "' to val '" << value
<< "'";
return SetOptionResult::CmdlineNoUpdate;
}
// special handling for vmodule changes as SetCommandLineOption()
// is not sufficient. Need to call SetVLOGLevel() as well.
if (key == "vmodule") {
setVModuleOption(key, value);
} else if (key == "v") {
gflags::SetCommandLineOption("minloglevel", "0");
}
LOG(WARNING) << "FLAG CHANGE: overrode 'FLAGS_" << key << "' to val '"
<< value << "', res '" << res << "'";
return SetOptionResult::CmdlineUpdated;
}