]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: add optional UUID field to showServers() and clarify doc about chashed distr...
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 13 Nov 2018 15:09:45 +0000 (16:09 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Tue, 13 Nov 2018 15:09:45 +0000 (16:09 +0100)
pdns/dnsdist-lua.cc
pdns/dnsdistdist/docs/guides/serverselection.rst
pdns/dnsdistdist/docs/reference/config.rst

index 1f468ebd2173a7f3751367e0faac38632eafbc1d..3356b75346cb84ccc8e44864907cf3355deb6033 100644 (file)
@@ -555,41 +555,68 @@ void setupLuaConfig(bool client)
       _exit(0);
   } );
 
-  g_lua.writeFunction("showServers", []() {
+  typedef std::unordered_map<std::string, boost::variant<bool, std::string> > showserversopts_t;
+
+  g_lua.writeFunction("showServers", [](boost::optional<showserversopts_t> vars) {
       setLuaNoSideEffect();
+      bool showUUIDs = false;
+      if (vars) {
+        if (vars->count("showUUIDs")) {
+          showUUIDs = boost::get<bool>((*vars)["showUUIDs"]);
+        }
+      }
       try {
-      ostringstream ret;
-      boost::format fmt("%1$-3d %2$-20.20s %|25t|%3% %|55t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$3d %|78t|%8$2d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5.1f %|115t|%13$11d %14%" );
-      //             1        2          3       4        5       6       7       8           9        10        11       12     13              14
-      ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools") << endl;
-
-      uint64_t totQPS{0}, totQueries{0}, totDrops{0};
-      int counter=0;
-      auto states = g_dstates.getLocal();
-      for(const auto& s : *states) {
-       string status = s->getStatus();
-       string pools;
-       for(auto& p : s->pools) {
-         if(!pools.empty())
-           pools+=" ";
-         pools+=p;
-       }
-
-       ret << (fmt % counter % s->name % s->remote.toStringWithPort() %
-               status %
-               s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % s->outstanding.load() % pools) << endl;
-
-       totQPS += s->queryLoad;
-       totQueries += s->queries.load();
-       totDrops += s->reuseds.load();
-       ++counter;
-      }
-      ret<< (fmt % "All" % "" % "" % ""
-               %
-            (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" ) << endl;
+        ostringstream ret;
+        boost::format fmt;
+        if (showUUIDs) {
+          fmt = boost::format("%1$-3d %15$-36s %2$-20.20s %|62t|%3% %|92t|%4$5s %|88t|%5$7.1f %|103t|%6$7d %|106t|%7$3d %|115t|%8$2d %|117t|%9$10d %|123t|%10$7d %|128t|%11$5.1f %|146t|%12$5.1f %|152t|%13$11d %14%" );
+          //             1        2          3       4        5       6       7       8           9        10        11       12     13              14        15
+          ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools" % "UUID") << endl;
+        } else {
+          fmt = boost::format("%1$-3d %2$-20.20s %|25t|%3% %|55t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$3d %|78t|%8$2d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5.1f %|115t|%13$11d %14%" );
+          ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools") << endl;
+        }
 
-      g_outputBuffer=ret.str();
-      }catch(std::exception& e) { g_outputBuffer=e.what(); throw; }
+        uint64_t totQPS{0}, totQueries{0}, totDrops{0};
+        int counter=0;
+        auto states = g_dstates.getLocal();
+        for(const auto& s : *states) {
+          string status = s->getStatus();
+          string pools;
+          for(auto& p : s->pools) {
+            if(!pools.empty())
+              pools+=" ";
+            pools+=p;
+          }
+          if (showUUIDs) {
+            ret << (fmt % counter % s->name % s->remote.toStringWithPort() %
+                    status %
+                    s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % s->outstanding.load() % pools % s->id) << endl;
+          } else {
+            ret << (fmt % counter % s->name % s->remote.toStringWithPort() %
+                    status %
+                    s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % s->outstanding.load() % pools) << endl;
+          }
+          totQPS += s->queryLoad;
+          totQueries += s->queries.load();
+          totDrops += s->reuseds.load();
+          ++counter;
+        }
+        if (showUUIDs) {
+          ret<< (fmt % "All" % "" % "" % ""
+                 %
+                 (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" % "" ) << endl;
+        } else {
+          ret<< (fmt % "All" % "" % "" % ""
+                 %
+                 (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" ) << endl;
+        }
+
+        g_outputBuffer=ret.str();
+      } catch(std::exception& e) {
+        g_outputBuffer=e.what();
+        throw;
+      }
     });
 
   g_lua.writeFunction("getServers", []() {
index b457b5e34d35ac646d7cbde90be5ebcc6503a77c..c8cde68b575b170207d1c6c5ca08865136dadadf 100644 (file)
@@ -48,7 +48,7 @@ The current hash algorithm is based on the qname of the query.
 
 ``chashed`` is a consistent hashing distribution policy. Identical questions with identical hashes will be distributed to the same servers. But unlike the ``whashed`` policy, this distribution will keep consistent over time. Adding or removing servers will only remap a small part of the queries.
 
-You can also set the hash perturbation value, see :func:`setWHashedPertubation`.
+You can also set the hash perturbation value, see :func:`setWHashedPertubation`. To achieve consistent distribution over :program:`dnsdist` restarts, you will also need to explicitly set the backend's UUIDs with the ``id`` option of :func:`newServer`. You can get the current UUIDs of your backends by calling :func:`showServers`.
 
 ``roundrobin``
 ~~~~~~~~~~~~~~
index f4391859e02183e41161bdb34ca9cafa9bd6244b..103d45e182519074ea454e5b48ea99d31c923e8d 100644 (file)
@@ -321,6 +321,7 @@ Servers
 
     newServer({
       address="IP:PORT",     -- IP and PORT of the backend server (mandatory)
+      id=STRING              -- Use a pre-defined UUID instead of a random one
       qps=NUM,               -- Limit the number of queries per second to NUM, when using the `firstAvailable` policy
       order=NUM,             -- The order of this server, used by the `leastOustanding` and `firstAvailable` policies
       weight=NUM,            -- The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1
@@ -686,12 +687,16 @@ Status, Statistics and More
 
   Show a plot of the response time latency distribution
 
-.. function:: showServers()
+.. function:: showServers([options])
+
+  .. versionchanged:: 1.3.4
+    ``options`` optional parameter added
 
   This function shows all backend servers currently configured and some statistics.
   These statics have the following fields:
 
   * ``#`` - The number of the server, can be used as the argument for :func:`getServer`
+  * ``UUID`` - The UUID of the backend. Can be set with the ``id`` option of :func:`newServer`
   * ``Address`` - The IP address and port of the server
   * ``State`` - The current state of the server
   * ``Qps`` - Current number of queries per second
@@ -704,6 +709,12 @@ Status, Statistics and More
   * ``Lat`` - The latency of this server in milliseconds
   * ``Pools`` - The pools this server belongs to
 
+  :param table options: A table with key: value pairs with display options.
+
+  Options:
+
+  * ``showUUIDs=false``: bool - Whether to display the UUIDs, defaults to false.
+
 .. function:: showTCPStats()
 
   Show some statistics regarding TCP