mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-19 19:08:17 +00:00
42bf5c5e61
We've been hoping that mkdocs-material will ship the much anticipated search enhancements for some time, but it's time to recognize that we need to do something to improve the search results with how things work right now. This is a big commit that changes the titles of the various pages from the code-annotated synopsis to just the name of the function. This makes it much easier now to match things like `kumo.reject` directly, but `reject` remains awkward to find. I think this is the best that we can do at this time. A few functions have been annotated with the `status: deprecated` to show as deprecated in the toc/nav (shows with a little trash can next to the name).
2.2 KiB
2.2 KiB
kumo.time.start_timer
kumo.time.start_timer(LABEL)
{{since('2025.01.23-7273d2bc')}}
Starts a timer with a specific label and returns a timer object.
The timer object can be used to update a latency histogram that is reported in the prometheus metrics for the server to track how long it takes for a certain operation to complete.
The most basic usage looks like this:
local timer = kumo.time.start_timer 'my-operation'
-- do something here
kumo.time.sleep(1.5)
-- And record the latency
timer:done()
After this runs, you will see the following metrics:
$ curl -s 'http://127.0.0.1:8000/metrics' | grep user_lua
# HELP user_lua_latency how long something user-defined took to run in your lua policy
# TYPE user_lua_latency histogram
user_lua_latency_bucket{label="my-operation",le="0.005"} 1
user_lua_latency_bucket{label="my-operation",le="0.01"} 1
user_lua_latency_bucket{label="my-operation",le="0.025"} 1
user_lua_latency_bucket{label="my-operation",le="0.05"} 1
user_lua_latency_bucket{label="my-operation",le="0.1"} 1
user_lua_latency_bucket{label="my-operation",le="0.25"} 1
user_lua_latency_bucket{label="my-operation",le="0.5"} 1
user_lua_latency_bucket{label="my-operation",le="1"} 1
user_lua_latency_bucket{label="my-operation",le="2.5"} 1
user_lua_latency_bucket{label="my-operation",le="5"} 1
user_lua_latency_bucket{label="my-operation",le="10"} 1
user_lua_latency_bucket{label="my-operation",le="+Inf"} 1
user_lua_latency_sum{label="my-operation"} 1.5
user_lua_latency_count{label="my-operation"} 1
You can use the <close> feature of lua to automatically trigger the :done() call
when the timer object falls out of scope. This is useful for example to track how
long it takes to run a function:
local function mything()
-- This `timer` will automatically report the duration of the `mything`
-- function when it returns, so you don't need to litter the function
-- with timer:done() calls for each return case below
local timer <close> = kumo.time.start_timer("mything")
if something then
return
end
if something_else then
return
end
end
The timer:done() method returns the number of seconds that have elapsed
since the timer was started.