From 7f7686970045670887c04a834eddbcdc38965209 Mon Sep 17 00:00:00 2001 From: Charles-Henri Bruyand Date: Tue, 13 Nov 2018 16:09:45 +0100 Subject: [PATCH] dnsdist: add optional UUID field to showServers() and clarify doc about chashed distribution mechanism --- pdns/dnsdist-lua.cc | 91 ++++++++++++------- .../docs/guides/serverselection.rst | 2 +- pdns/dnsdistdist/docs/reference/config.rst | 13 ++- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 1f468ebd2..3356b7534 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -555,41 +555,68 @@ void setupLuaConfig(bool client) _exit(0); } ); - g_lua.writeFunction("showServers", []() { + typedef std::unordered_map > showserversopts_t; + + g_lua.writeFunction("showServers", [](boost::optional vars) { setLuaNoSideEffect(); + bool showUUIDs = false; + if (vars) { + if (vars->count("showUUIDs")) { + showUUIDs = boost::get((*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", []() { diff --git a/pdns/dnsdistdist/docs/guides/serverselection.rst b/pdns/dnsdistdist/docs/guides/serverselection.rst index b457b5e34..c8cde68b5 100644 --- a/pdns/dnsdistdist/docs/guides/serverselection.rst +++ b/pdns/dnsdistdist/docs/guides/serverselection.rst @@ -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`` ~~~~~~~~~~~~~~ diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index f4391859e..103d45e18 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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 -- 2.40.0