From: Fred Morcos Date: Tue, 12 Dec 2023 14:16:13 +0000 (+0100) Subject: Remove global StatBag from ws-auth X-Git-Tag: auth-4.9.0-alpha1~23^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a690b08ca1376276568cfd0404f53b8586984d05;p=thirdparty%2Fpdns.git Remove global StatBag from ws-auth --- diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 59a3e2111f..ea0f4c91ed 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -844,8 +844,9 @@ static void mainthread() // NOW SAFE TO CREATE THREADS! s_dynListener->go(); - if (::arg().mustDo("webserver") || ::arg().mustDo("api")) - webserver.go(); + if (::arg().mustDo("webserver") || ::arg().mustDo("api")) { + webserver.go(S); + } if (::arg().mustDo("primary") || ::arg().mustDo("secondary") || !::arg()["forward-notify"].empty()) Communicator.go(); diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index ec429a30e1..11e7db3112 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -50,8 +50,6 @@ using json11::Json; -extern StatBag S; - Ewma::Ewma() { dt.set(); } void Ewma::submit(int val) @@ -122,25 +120,25 @@ AuthWebServer::AuthWebServer() : } } -void AuthWebServer::go() +void AuthWebServer::go(StatBag& stats) { S.doRings(); std::thread webT([this]() { webThread(); }); webT.detach(); - std::thread statT([this]() { statThread(); }); + std::thread statT([this, &stats]() { statThread(stats); }); statT.detach(); } -void AuthWebServer::statThread() +void AuthWebServer::statThread(StatBag& stats) { try { setThreadName("pdns/statHelper"); for (;;) { - d_queries.submit(S.read("udp-queries")); - d_cachehits.submit(S.read("packetcache-hit")); - d_cachemisses.submit(S.read("packetcache-miss")); - d_qcachehits.submit(S.read("query-cache-hit")); - d_qcachemisses.submit(S.read("query-cache-miss")); + d_queries.submit(static_cast(stats.read("udp-queries"))); + d_cachehits.submit(static_cast(stats.read("packetcache-hit"))); + d_cachemisses.submit(static_cast(stats.read("packetcache-miss"))); + d_qcachehits.submit(static_cast(stats.read("query-cache-hit"))); + d_qcachemisses.submit(static_cast(stats.read("query-cache-miss"))); Utility::sleep(1); } } diff --git a/pdns/ws-auth.hh b/pdns/ws-auth.hh index c306a1fa2a..1900a4ed72 100644 --- a/pdns/ws-auth.hh +++ b/pdns/ws-auth.hh @@ -27,6 +27,7 @@ #include "misc.hh" #include "namespaces.hh" #include "webserver.hh" +#include "statbag.hh" class Ewma { @@ -49,7 +50,7 @@ class AuthWebServer { public: AuthWebServer(); - void go(); + void go(StatBag& stats); static string makePercentage(const double& val); private: @@ -60,7 +61,7 @@ private: void printvars(ostringstream& ret); void printargs(ostringstream& ret); void webThread(); - void statThread(); + void statThread(StatBag& stats); time_t d_start; double d_min10, d_min5, d_min1;