Skip to content

Commit

Permalink
Elapsed lua binding
Browse files Browse the repository at this point in the history
(cherry picked from commit d31fa78)
  • Loading branch information
phonedph1 authored and rgacogne committed Nov 26, 2024
1 parent 905654a commit 9fd070b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pdns/dnsdist-lua-bindings-dnsquestion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -450,6 +454,10 @@ class AsynchronousObject
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) {
Expand Down
8 changes: 8 additions & 0 deletions pdns/dnsdistdist/docs/reference/dq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9fd070b

Please sign in to comment.