]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Elapsed lua binding 14887/head
authorphonedph1 <ph1@slurpee3>
Wed, 20 Nov 2024 23:08:22 +0000 (16:08 -0700)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 26 Nov 2024 09:12:16 +0000 (10:12 +0100)
(cherry picked from commit d31fa785c5a9e5ba6f9d2d482e79fbf72856aa4b)

pdns/dnsdist-lua-bindings-dnsquestion.cc
pdns/dnsdistdist/docs/reference/dq.rst

index 4512fc5ef4f81b4a6d8e06da64005a931f22b5c0..bd75754b3cb93b3d19a4c0d08a382f166f3da937 100644 (file)
@@ -146,6 +146,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx)
     return dq.ids.queryRealTime.getStartTime();
   });
 
+  luaCtx.registerFunction<double (DNSQuestion::*)() const>("getElapsedUs", [](const DNSQuestion& dnsQuestion) {
+    return dnsQuestion.ids.queryRealTime.udiff();
+  });
+
   luaCtx.registerFunction<void(DNSQuestion::*)(std::string)>("sendTrap", [](const DNSQuestion& dq, boost::optional<std::string> reason) {
 #ifdef HAVE_NET_SNMP
       if (g_snmpAgent && g_snmpTrapsEnabled) {
@@ -450,6 +454,10 @@ private:
     return dr.ids.queryRealTime.getStartTime();
   });
 
+  luaCtx.registerFunction<double (DNSResponse::*)() const>("getElapsedUs", [](const DNSResponse& dnsResponse) {
+    return dnsResponse.ids.queryRealTime.udiff();
+  });
+
   luaCtx.registerFunction<void(DNSResponse::*)(std::string)>("sendTrap", [](const DNSResponse& dr, boost::optional<std::string> reason) {
 #ifdef HAVE_NET_SNMP
       if (g_snmpAgent && g_snmpTrapsEnabled) {
index 69bd0a2bb92c6fa8a16e01143f9cd6f03dffe34c..c66f1257ad196e445439d74de63a9b2b27c2a02d 100644 (file)
@@ -131,6 +131,14 @@ This state can be modified from the various hooks.
 
     :returns: A table of EDNSOptionView objects, indexed on the ECS Option code
 
+  .. method:: DNSQuestion::getElapsedUs -> double
+
+     .. versionadded:: 2.0.0
+
+     Return the amount of time that has elapsed since the query was received.
+
+     :returns: A double indicating elapsed time in microseconds
+
   .. method:: DNSQuestion:getHTTPHeaders() -> table
 
     .. versionadded:: 1.4.0