./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_type(),
6 mongoose_instrument:labels(),
7 mongoose_instrument:config()) -> mongoose_instrument:measurements().
8
9 -ignore_xref([call/4]).
10
11 -define(DEFAULT_PROBE_INTERVAL, 15).
12
13 -spec start_probe_timer(mongoose_instrument:event_type(),
14 mongoose_instrument:labels(),
15 mongoose_instrument:config()) -> timer:tref().
16 start_probe_timer(EventName, Labels, #{probe := ProbeMod} = Config) ->
17 76 Interval = timer:seconds(get_probe_interval(Config)),
18 %% TODO: when dropping support for OTP25, consider changing this to apply_repeatedly
19 76 {ok, TRef} = timer:apply_interval(Interval, ?MODULE, call,
20 [ProbeMod, EventName, Labels, Config]),
21 76 TRef.
22
23 call(ProbeMod, EventName, Labels, Config) ->
24 14 case safely:apply_and_log(ProbeMod, probe, [EventName, Labels, Config],
25 #{what => probe_failed, probe_mod => ProbeMod,
26 event_name => EventName, labels => Labels, config => Config}) of
27 {exception, _} ->
28
:-(
ok; % Already logged
29 Measurements = #{} ->
30 14 mongoose_instrument:execute(EventName, Labels, Measurements)
31 end.
32
33 -spec get_probe_interval(mongoose_instrument:config()) -> pos_integer().
34 get_probe_interval(#{probe_interval := Interval}) when is_integer(Interval), Interval > 0 ->
35
:-(
Interval;
36 get_probe_interval(#{}) ->
37 76 ?DEFAULT_PROBE_INTERVAL.
Line Hits Source