diff --git a/pdns/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdist-lua-bindings-dnsquestion.cc index 4512fc5ef4f8..bd75754b3cb9 100644 --- a/pdns/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdist-lua-bindings-dnsquestion.cc @@ -146,6 +146,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx) return dq.ids.queryRealTime.getStartTime(); }); + luaCtx.registerFunction("getElapsedUs", [](const DNSQuestion& dnsQuestion) { + return dnsQuestion.ids.queryRealTime.udiff(); + }); + luaCtx.registerFunction("sendTrap", [](const DNSQuestion& dq, boost::optional reason) { #ifdef HAVE_NET_SNMP if (g_snmpAgent && g_snmpTrapsEnabled) { @@ -450,6 +454,10 @@ class AsynchronousObject return dr.ids.queryRealTime.getStartTime(); }); + luaCtx.registerFunction("getElapsedUs", [](const DNSResponse& dnsResponse) { + return dnsResponse.ids.queryRealTime.udiff(); + }); + luaCtx.registerFunction("sendTrap", [](const DNSResponse& dr, boost::optional reason) { #ifdef HAVE_NET_SNMP if (g_snmpAgent && g_snmpTrapsEnabled) { diff --git a/pdns/dnsdistdist/docs/reference/dq.rst b/pdns/dnsdistdist/docs/reference/dq.rst index 69bd0a2bb92c..c66f1257ad19 100644 --- a/pdns/dnsdistdist/docs/reference/dq.rst +++ b/pdns/dnsdistdist/docs/reference/dq.rst @@ -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