From 0ebe92de6815c34b66dafd9ce3abd3d4166ca10d Mon Sep 17 00:00:00 2001 From: CJ Cobb <46455409+cjcobb23@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:51:39 -0500 Subject: [PATCH] add work queue output to server_info (#322) --- src/rpc/Counters.cpp | 16 ++++++++++------ src/rpc/Counters.h | 8 ++++++-- src/rpc/WorkQueue.h | 3 +-- src/rpc/handlers/ServerInfo.cpp | 3 +-- src/webserver/Listener.h | 1 + 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/rpc/Counters.cpp b/src/rpc/Counters.cpp index 22755c20..4263813c 100644 --- a/src/rpc/Counters.cpp +++ b/src/rpc/Counters.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace RPC { @@ -66,20 +67,23 @@ Counters::report() { std::shared_lock lk(mutex_); boost::json::object obj = {}; + obj[JS(rpc)] = boost::json::object{}; + auto& rpc = obj[JS(rpc)].as_object(); for (auto const& [method, info] : methodInfo_) { boost::json::object counters = {}; - counters["started"] = std::to_string(info.started); - counters["finished"] = std::to_string(info.finished); - counters["errored"] = std::to_string(info.errored); + counters[JS(started)] = std::to_string(info.started); + counters[JS(finished)] = std::to_string(info.finished); + counters[JS(errored)] = std::to_string(info.errored); counters["forwarded"] = std::to_string(info.forwarded); - counters["duration_us"] = std::to_string(info.duration); + counters[JS(duration_us)] = std::to_string(info.duration); - obj[method] = std::move(counters); + rpc[method] = std::move(counters); } + obj["work_queue"] = workQueue_.get().report(); return obj; } -} // namespace RPC \ No newline at end of file +} // namespace RPC diff --git a/src/rpc/Counters.h b/src/rpc/Counters.h index 2b7084d8..66943acc 100644 --- a/src/rpc/Counters.h +++ b/src/rpc/Counters.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,8 +32,10 @@ private: std::shared_mutex mutex_; std::unordered_map methodInfo_; + std::reference_wrapper workQueue_; + public: - Counters() = default; + Counters(WorkQueue const& wq) : workQueue_(std::cref(wq)){}; void rpcErrored(std::string const& method); @@ -50,4 +54,4 @@ public: } // namespace RPC -#endif // RPC_COUNTERS_H \ No newline at end of file +#endif // RPC_COUNTERS_H diff --git a/src/rpc/WorkQueue.h b/src/rpc/WorkQueue.h index d3cf8582..3a666d27 100644 --- a/src/rpc/WorkQueue.h +++ b/src/rpc/WorkQueue.h @@ -60,9 +60,8 @@ public: return true; } - // TODO: this is not actually being called. Wait for application refactor boost::json::object - report() + report() const { boost::json::object obj; obj["queued"] = queued_; diff --git a/src/rpc/handlers/ServerInfo.cpp b/src/rpc/handlers/ServerInfo.cpp index 7f875b7d..acdc61ca 100644 --- a/src/rpc/handlers/ServerInfo.cpp +++ b/src/rpc/handlers/ServerInfo.cpp @@ -47,8 +47,7 @@ doServerInfo(Context const& context) if (admin) { - info[JS(counters)] = boost::json::object{}; - info[JS(counters)].as_object()[JS(rpc)] = context.counters.report(); + info[JS(counters)] = context.counters.report(); info[JS(counters)].as_object()["subscriptions"] = context.subscriptions->report(); } diff --git a/src/webserver/Listener.h b/src/webserver/Listener.h index 79dd22d8..d848a107 100644 --- a/src/webserver/Listener.h +++ b/src/webserver/Listener.h @@ -223,6 +223,7 @@ public: , etl_(etl) , dosGuard_(dosGuard) , queue_(numWorkerThreads, maxQueueSize) + , counters_(queue_) { boost::beast::error_code ec;