]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Elapsed lua binding 14850/head
authorphonedph1 <ph1@slurpee3>
Wed, 20 Nov 2024 23:08:22 +0000 (16:08 -0700)
committerphonedph1 <ph1@slurpee3>
Wed, 20 Nov 2024 23:08:22 +0000 (16:08 -0700)
pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc
pdns/dnsdistdist/docs/reference/dq.rst

index bf6c47361c9eb52ad2690cf3b9abd89bf04f254d..3527ce7ba2800966fbd05b4b7473ab04693d0d53 100644 (file)
@@ -168,6 +168,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx)
     return dnsQuestion.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& dnsQuestion, boost::optional<std::string> reason) {
 #ifdef HAVE_NET_SNMP
     if (g_snmpAgent != nullptr && dnsdist::configuration::getCurrentRuntimeConfiguration().d_snmpTrapsEnabled) {
@@ -495,6 +499,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx)
     return dnsResponse.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& dnsResponse, boost::optional<std::string> reason) {
 #ifdef HAVE_NET_SNMP
     if (g_snmpAgent != nullptr && dnsdist::configuration::getCurrentRuntimeConfiguration().d_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