]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Remove global StatBag from ws-auth
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 12 Dec 2023 14:16:13 +0000 (15:16 +0100)
committerFred Morcos <fred.morcos@open-xchange.com>
Thu, 21 Dec 2023 14:41:41 +0000 (15:41 +0100)
pdns/auth-main.cc
pdns/ws-auth.cc
pdns/ws-auth.hh

index 59a3e2111fd783240efc893498e50edf745d7ec2..ea0f4c91ed5549715faf5acba8b9d984642f4cfc 100644 (file)
@@ -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();
index ec429a30e198e5403409227f4c4dc3c05a52e491..11e7db31125751a7bbd954c8d2e9afdbbe43869d 100644 (file)
@@ -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<int>(stats.read("udp-queries")));
+      d_cachehits.submit(static_cast<int>(stats.read("packetcache-hit")));
+      d_cachemisses.submit(static_cast<int>(stats.read("packetcache-miss")));
+      d_qcachehits.submit(static_cast<int>(stats.read("query-cache-hit")));
+      d_qcachemisses.submit(static_cast<int>(stats.read("query-cache-miss")));
       Utility::sleep(1);
     }
   }
index c306a1fa2a448e9d3bef192dd8a00d7709d05295..1900a4ed728c5a8851b2563b47871993e12e1082 100644 (file)
@@ -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;