From ec739073899a3364514ed0eaeec0fba5fde2b250 Mon Sep 17 00:00:00 2001 From: Igor Zolotarev <63460867+yngvar-antonsson@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:11:38 +0300 Subject: [PATCH] Add output description to latency functions (#297) --- metrics/collectors/shared.lua | 14 +++++++++----- metrics/http_middleware.lua | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/metrics/collectors/shared.lua b/metrics/collectors/shared.lua index f6588cb9..d0b2578a 100644 --- a/metrics/collectors/shared.lua +++ b/metrics/collectors/shared.lua @@ -87,11 +87,14 @@ local function observe_latency_tail(collector, label_pairs, start_time, ok, resu if type(label_pairs) == 'function' then label_pairs = label_pairs(ok, result, ...) end - xpcall(function() - collector:observe(latency, label_pairs) end, - function(err) - log.error(debug.traceback('Saving metrics failed: ' .. tostring(err))) - end) + xpcall( + function() + collector:observe(latency, label_pairs) + end, + function(err) + log.error(debug.traceback('Saving metrics failed: ' .. tostring(err))) + end + ) if not ok then error(result) end @@ -104,6 +107,7 @@ end -- If function is given its called with the results of pcall. -- @param fn function for pcall to instrument -- ... - args for function fn +-- @return value from fn function Shared:observe_latency(label_pairs, fn, ...) return observe_latency_tail(self, label_pairs, clock.monotonic(), pcall(fn, ...)) end diff --git a/metrics/http_middleware.lua b/metrics/http_middleware.lua index f379a036..15732ef8 100644 --- a/metrics/http_middleware.lua +++ b/metrics/http_middleware.lua @@ -69,6 +69,7 @@ end -- @string route.path -- @string route.method -- ... arguments for pcall to instrument +-- @return value from observable function function export.observe(collector, route, ...) return collector:observe_latency(function(ok, result) return {