./ct_report/coverage/mongoose_instrument_probe.COVER.html

1 -module(mongoose_instrument_probe).
2
3 -export([start_probe_timer/3, call/4]).
4
5 -callback probe(mongoose_instrument:event_name(),
6 mongoose_instrument:labels(),
7 mongoose_instrument:config()) -> mongoose_instrument:measurements().
8
9 -ignore_xref([call/4]).
10
11 -spec start_probe_timer(mongoose_instrument:event_name(),
12 mongoose_instrument:labels(),
13 mongoose_instrument:config()) -> timer:tref().
14 start_probe_timer(EventName, Labels, #{probe := #{module := Module} = ProbeConfig} = Config) ->
15
:-(
Interval = timer:seconds(get_probe_interval(ProbeConfig)),
16 %% TODO: when dropping support for OTP25, consider changing this to apply_repeatedly
17
:-(
{ok, TRef} = timer:apply_interval(Interval, ?MODULE, call,
18 [Module, EventName, Labels, Config]),
19
:-(
TRef.
20
21 call(ProbeMod, EventName, Labels, Config) ->
22
:-(
case safely:apply_and_log(ProbeMod, probe, [EventName, Labels, Config],
23 #{what => probe_failed, probe_mod => ProbeMod,
24 event_name => EventName, labels => Labels, config => Config}) of
25 {exception, _} ->
26
:-(
ok; % Already logged
27 Measurements = #{} ->
28
:-(
mongoose_instrument:execute(EventName, Labels, Measurements)
29 end.
30
31 -spec get_probe_interval(mongoose_instrument:probe_config()) -> pos_integer().
32 get_probe_interval(#{interval := Interval}) when is_integer(Interval), Interval > 0 ->
33
:-(
Interval;
34 get_probe_interval(#{}) ->
35
:-(
mongoose_config:get_opt([instrumentation, probe_interval]).
Line Hits Source