diff --git a/fdbclient/ActorLineageProfiler.cpp b/fdbclient/ActorLineageProfiler.cpp index 3b300f1653..3c656010b6 100644 --- a/fdbclient/ActorLineageProfiler.cpp +++ b/fdbclient/ActorLineageProfiler.cpp @@ -360,3 +360,11 @@ void ProfilerConfigT::reset(std::map const& config) { useTCP ? FluentDIngestor::Protocol::TCP : FluentDIngestor::Protocol::TCP, address)); } } + +std::map ProfilerConfigT::getConfig() const { + std::map res; + if (ingestor) { + ingestor->getConfig(res); + } + return res; +} diff --git a/fdbclient/ActorLineageProfiler.h b/fdbclient/ActorLineageProfiler.h index d09aba7d2c..9f9fdc3300 100644 --- a/fdbclient/ActorLineageProfiler.h +++ b/fdbclient/ActorLineageProfiler.h @@ -55,11 +55,13 @@ class SampleIngestor : std::enable_shared_from_this { public: virtual ~SampleIngestor(); virtual void ingest(std::shared_ptr const& sample) = 0; + virtual void getConfig(std::map&) const = 0; }; class NoneIngestor : public SampleIngestor { public: void ingest(std::shared_ptr const& sample) override {} + void getConfig(std::map& res) const override { res["ingestor"] = "none"; } }; // The FluentD ingestor uses the pimp idiom. This is to make compilation less heavy weight as this implementation has @@ -76,6 +78,7 @@ private: // members public: // interface void ingest(std::shared_ptr const& sample) override; FluentDIngestor(Protocol protocol, NetworkAddress& endpoint); + void getConfig(std::map& res) const override; ~FluentDIngestor(); }; @@ -99,6 +102,7 @@ private: // construction public: void reset(std::map const& config); + std::map getConfig() const; }; using ProfilerConfig = crossbow::singleton; diff --git a/fdbclient/FluentDSampleIngestor.cpp b/fdbclient/FluentDSampleIngestor.cpp index f1609ae5b3..e912643dbf 100644 --- a/fdbclient/FluentDSampleIngestor.cpp +++ b/fdbclient/FluentDSampleIngestor.cpp @@ -170,3 +170,9 @@ void FluentDIngestor::ingest(const std::shared_ptr& sample) { impl->socket->send(sample); } } + +void FluentDIngestor::getConfig(std::map& res) const { + res["ingestor"] = "fluentd"; + res["collector_endpoint"] = impl->endpoint.toString(); + res["collector_protocol"] = impl->protocol == Protocol::TCP ? "tcp" : "udp"; +} diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index cd7638221b..443571c097 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -1060,6 +1060,10 @@ DatabaseContext::DatabaseContext(Reference(SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ACTORLINEAGE))); + registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF, + SpecialKeySpace::IMPLTYPE::READWRITE, + std::make_unique( + SpecialKeySpace::getModuleRange(SpecialKeySpace::MODULE::ACTORLINEAGE))); } if (apiVersionAtLeast(630)) { registerSpecialKeySpaceModule(SpecialKeySpace::MODULE::TRANSACTION, diff --git a/fdbclient/SpecialKeySpace.actor.cpp b/fdbclient/SpecialKeySpace.actor.cpp index 603887fcf6..b692a5dea3 100644 --- a/fdbclient/SpecialKeySpace.actor.cpp +++ b/fdbclient/SpecialKeySpace.actor.cpp @@ -21,6 +21,7 @@ #include "boost/lexical_cast.hpp" #include "boost/algorithm/string.hpp" +#include "fdbclient/ActorLineageProfiler.h" #include "fdbclient/Knobs.h" #include "fdbclient/ProcessInterface.h" #include "fdbclient/GlobalConfig.actor.h" @@ -71,7 +72,10 @@ std::unordered_map SpecialKeySpace::moduleToB { SpecialKeySpace::MODULE::TRACING, KeyRangeRef(LiteralStringRef("\xff\xff/tracing/"), LiteralStringRef("\xff\xff/tracing0")) }, { SpecialKeySpace::MODULE::ACTORLINEAGE, - KeyRangeRef(LiteralStringRef("\xff\xff/actor_lineage/"), LiteralStringRef("\xff\xff/actor_lineage0")) } + KeyRangeRef(LiteralStringRef("\xff\xff/actor_lineage/"), LiteralStringRef("\xff\xff/actor_lineage0")) }, + { SpecialKeySpace::MODULE::ACTOR_PROFILER_CONF, + KeyRangeRef(LiteralStringRef("\xff\xff/actor_profiler_conf/"), + LiteralStringRef("\xff\xff/actor_profiler_conf0")) } }; std::unordered_map SpecialKeySpace::managementApiCommandToRange = { @@ -1953,3 +1957,64 @@ ACTOR static Future> actorLineageGetRangeActor(ReadYo Future> ActorLineageImpl::getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const { return actorLineageGetRangeActor(ryw, getKeyRange().begin, kr); } + +namespace { +std::string_view to_string_view(StringRef sr) { + return std::string_view(reinterpret_cast(sr.begin()), sr.size()); +} +} // namespace + +ActorProfilerConf::ActorProfilerConf(KeyRangeRef kr) + : SpecialKeyRangeRWImpl(kr), config(ProfilerConfig::instance().getConfig()) {} + +Future> ActorProfilerConf::getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const { + Standalone res; + std::string_view begin(to_string_view(kr.begin.removePrefix(range.begin))), + end(to_string_view(kr.end.removePrefix(range.begin))); + for (auto& p : config) { + if (p.first > end) { + break; + } else if (p.first > begin) { + KeyValueRef kv; + kv.key = StringRef(res.arena(), p.first); + kv.value = StringRef(res.arena(), p.second); + res.push_back(res.arena(), kv); + } + } + return res; +} + +void ActorProfilerConf::set(ReadYourWritesTransaction* ryw, const KeyRef& key, const ValueRef& value) { + config[key.removePrefix(range.begin).toString()] = value.toString(); +} + +void ActorProfilerConf::clear(ReadYourWritesTransaction* ryw, const KeyRangeRef& kr) { + std::string begin(kr.begin.removePrefix(range.begin).toString()), end(kr.end.removePrefix(range.begin).toString()); + auto first = config.lower_bound(begin); + if (first == config.end()) { + // nothing to clear + return; + } + auto last = config.upper_bound(end); + config.erase(first, last); +} + +void ActorProfilerConf::clear(ReadYourWritesTransaction* ryw, const KeyRef& key) { + std::string k = key.removePrefix(range.begin).toString(); + auto iter = config.find(k); + if (iter != config.end()) { + config.erase(iter); + } +} + +Future> ActorProfilerConf::commit(ReadYourWritesTransaction* ryw) { + Optional res{}; + try { + if (didWrite) { + ProfilerConfig::instance().reset(config); + } + return res; + } catch (ConfigError& err) { + return Optional{ err.description }; + } +} diff --git a/fdbclient/SpecialKeySpace.actor.h b/fdbclient/SpecialKeySpace.actor.h index 08a3c6cfc5..f17a4b38ca 100644 --- a/fdbclient/SpecialKeySpace.actor.h +++ b/fdbclient/SpecialKeySpace.actor.h @@ -143,6 +143,7 @@ class SpecialKeySpace { public: enum class MODULE { ACTORLINEAGE, // Sampling data + ACTOR_PROFILER_CONF, // profiler configuration CLUSTERFILEPATH, CONFIGURATION, // Configuration of the cluster CONNECTIONSTRING, @@ -395,5 +396,18 @@ public: Future> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const override; }; +class ActorProfilerConf : public SpecialKeyRangeRWImpl { + bool didWrite = false; + std::map config; + +public: + explicit ActorProfilerConf(KeyRangeRef kr); + Future> getRange(ReadYourWritesTransaction* ryw, KeyRangeRef kr) const override; + void set(ReadYourWritesTransaction* ryw, const KeyRef& key, const ValueRef& value) override; + void clear(ReadYourWritesTransaction* ryw, const KeyRangeRef& range) override; + void clear(ReadYourWritesTransaction* ryw, const KeyRef& key) override; + Future> commit(ReadYourWritesTransaction* ryw) override; +}; + #include "flow/unactorcompiler.h" #endif