Skip to content

Commit

Permalink
Replaced hut by logger
Browse files Browse the repository at this point in the history
Minimum OTP version for parse_trans is 21. The logger was added into OTP 21.
  • Loading branch information
vkatsuba committed Sep 24, 2021
1 parent 0e625a1 commit 10d76e8
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 75 deletions.
46 changes: 14 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,22 @@ on:
workflow_dispatch:

jobs:
test_till_otp_22:
name: Run tests on OTP ${{matrix.otp}}
strategy:
matrix:
otp: [21.3]
fail-fast: false
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
rebar3-version: '3.15.2'
- run: rebar3 compile
- run: rebar3 xref
- run: rebar3 dialyzer
- run: rebar3 eunit
- run: rebar3 ct

test_till_otp_24:
name: Run tests on OTP ${{matrix.otp}}
strategy:
matrix:
otp: [22.3, 23.3, 24.1]
fail-fast: false
runs-on: ubuntu-latest
otp: [21.3, 22.3, 23.3, 24.1]
container:
image: erlang:${{ matrix.otp }}-alpine
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
rebar3-version: '3.17'
- run: rebar3 compile
- run: rebar3 xref
- run: rebar3 dialyzer
- run: rebar3 eunit
- run: rebar3 ct
- name: Checkout
uses: actions/checkout@v2
- name: Compile
run: rebar3 compile
- name: Tests
run: |
rebar3 xref
rebar3 dialyzer
rebar3 eunit
rebar3 ct
1 change: 0 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[
{parse_trans, "3.4.1"},
{folsom, "1.0.0"},
{hut, "1.3.0"},
{setup, "2.1.0"}
]}.

Expand Down
3 changes: 0 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
{"1.2.0",
[{<<"bear">>,{pkg,<<"bear">>,<<"1.0.0">>},1},
{<<"folsom">>,{pkg,<<"folsom">>,<<"1.0.0">>},0},
{<<"hut">>,{pkg,<<"hut">>,<<"1.3.0">>},0},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.4.1">>},0},
{<<"setup">>,{pkg,<<"setup">>,<<"2.1.0">>},0}]}.
[
{pkg_hash,[
{<<"bear">>, <<"430419C1126B477686CDE843E88BA0F2C7DC5CDF0881C677500074F704339A99">>},
{<<"folsom">>, <<"50ECC998D2149939F1D5E0AA3E32788F8ED16A58E390D81B5C0BE4CC4EF25589">>},
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>},
{<<"parse_trans">>, <<"6E6AA8167CB44CC8F39441D05193BE6E6F4E7C2946CB2759F015F8C56B76E5FF">>},
{<<"setup">>, <<"05F69185A5EB71474C9BC6BA892565651EC7507791F85632B7B914DBFE130510">>}]},
{pkg_hash_ext,[
{<<"bear">>, <<"157B67901ADF84FF0DA6EAE035CA1292A0AC18AA55148154D8C582B2C68959DB">>},
{<<"folsom">>, <<"DD6AB97278E94F9E4CFC43E188224A7B8C7EAEC0DD2E935007005177F3EEBB0E">>},
{<<"hut">>, <<"7E15D28555D8A1F2B5A3A931EC120AF0753E4853A4C66053DB354F35BF9AB563">>},
{<<"parse_trans">>, <<"620A406CE75DADA827B82E453C19CF06776BE266F5A67CFF34E1EF2CBB60E49A">>},
{<<"setup">>, <<"EFD072578F0CF85BEA96CAAFFC7ADB0992398272522660A136E10567377071C5">>}]}
].
Binary file added rebar3
Binary file not shown.
25 changes: 12 additions & 13 deletions src/exometer_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
-export([monitor/2, monitor/3, demonitor/1]).

-compile({no_auto_import, [monitor/3]}).
-include_lib("hut/include/hut.hrl").
-include_lib("kernel/include/logger.hrl").
-include("exometer.hrl").

-record(st, {}).
Expand Down Expand Up @@ -127,7 +127,7 @@ do_load_defaults(Src, L) when is_list(L) ->
try set_default(NamePattern, Type, Spec)
catch
error:E ->
?log(error, "Defaults(~p): ERROR: ~p~n", [Src, E])
?LOG_ERROR("Defaults(~p): ERROR: ~p~n", [Src, E])
end
end, L).

Expand All @@ -145,7 +145,7 @@ do_load_predef(Src, L) when is_list(L) ->
fun({K,_,_}) ->
predef_delete_entry(K, Src);
(Other) ->
?log(error, "Predef(~p): ~p~n",
?LOG_ERROR("Predef(~p): ~p~n",
[Src, {bad_pattern,Other}])
end, Found);
({aliases, Aliases}) ->
Expand All @@ -159,7 +159,7 @@ predef_delete_entry(Key, Src) ->
case delete_entry(Key) of
ok -> ok;
Error ->
?log(error, "Predef(~p): ~p~n", [Src, Error])
?LOG_ERROR("Predef(~p): ~p~n", [Src, Error])
end.

ok({ok, Res}, _) -> Res;
Expand Down Expand Up @@ -279,7 +279,7 @@ handle_call({new_entry, Name, Type, Opts, AllowExisting} = _Req, _From, S) ->
remove_old_instance(LookupRes, Name)
catch
?EXCEPTION(Cat, Exception, Stacktrace1) ->
?log(debug, "CAUGHT(~p) ~p:~p / ~p",
?LOG_DEBUG("CAUGHT(~p) ~p:~p / ~p",
[Name, Cat, Exception, ?GET_STACK(Stacktrace1)]),
ok
end,
Expand All @@ -288,16 +288,15 @@ handle_call({new_entry, Name, Type, Opts, AllowExisting} = _Req, _From, S) ->
exometer_report:new_entry(E1)
catch
?EXCEPTION(error, Error1, Stacktrace2) ->
?log(debug,
"ERROR create_entry(~p) :- ~p~n~p",
[E1, Error1, ?GET_STACK(Stacktrace2)]),
?LOG_DEBUG("ERROR create_entry(~p) :- ~p~n~p",
[E1, Error1, ?GET_STACK(Stacktrace2)]),
erlang:error(Error1)
end,
{reply, Res, S}
end
catch
?EXCEPTION(error, Error, Stacktrace) ->
?log(error, "~p -*-> error:~p~n~p~n",
?LOG_ERROR("~p -*-> error:~p~n~p~n",
[_Req, Error, ?GET_STACK(Stacktrace)]),
{reply, {error, Error}, S}
end;
Expand Down Expand Up @@ -456,14 +455,14 @@ on_error(Name, delete) ->
try_delete_entry_(Name);
on_error(_Proc, _OnError) ->
%% Not good, but will do for now.
?log(debug, "Unrecognized OnError: ~p (~p)~n", [_OnError, _Proc]),
?LOG_DEBUG("Unrecognized OnError: ~p (~p)~n", [_OnError, _Proc]),
ok.

call_restart(M, F, A) ->
apply(M, F, A).

restart_failed(Name, Error) ->
?log(debug, "Restart failed ~p: ~p~n", [Name, Error]),
?LOG_DEBUG("Restart failed ~p: ~p~n", [Name, Error]),
if is_list(Name) ->
try_delete_entry_(Name);
true ->
Expand Down Expand Up @@ -682,7 +681,7 @@ try_disable_entry_(Name) when is_list(Name) ->
try exometer:setopts(Name, [{status, disabled}])
catch
error:Err ->
?log(debug, "Couldn't disable ~p: ~p~n", [Name, Err]),
?LOG_DEBUG("Couldn't disable ~p: ~p~n", [Name, Err]),
try_delete_entry_(Name)
end;
try_disable_entry_(_Name) ->
Expand All @@ -692,7 +691,7 @@ try_delete_entry_(Name) ->
try delete_entry_(Name)
catch
error:R ->
?log(debug, "Couldn't delete ~p: ~p~n", [Name, R]),
?LOG_DEBUG("Couldn't delete ~p: ~p~n", [Name, R]),
ok
end.

Expand Down
2 changes: 1 addition & 1 deletion src/exometer_core.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[{description,"Code instrumentation and metrics collection package."},
{vsn,git},
{registered,[]},
{applications,[kernel,stdlib,hut,setup,folsom,parse_trans]},
{applications,[kernel,stdlib,setup,folsom,parse_trans]},
{included_applications,[]},
{mod,{exometer_core_app,[]}},
{start_phases,[{start_reporters,[]},{preset_defaults,[]}]},
Expand Down
10 changes: 5 additions & 5 deletions src/exometer_folsom_monitor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
-record(st, {mon = orddict:new()}).

-include_lib("parse_trans/include/codegen.hrl").
-include_lib("hut/include/hut.hrl").
-include_lib("kernel/include/logger.hrl").
-include("exometer.hrl").

-type type() :: exometer:type().
Expand Down Expand Up @@ -126,10 +126,10 @@ init_monitor([_|_]) ->
do_init_monitor() ->
case is_transformed() of
true ->
?log(debug, "already transformed...~n", []),
?LOG_DEBUG("already transformed...~n", []),
ok;
false ->
?log(debug, "transforming folsom_metrics...~n", []),
?LOG_DEBUG("transforming folsom_metrics...~n", []),
parse_trans_mod:transform_module(folsom_metrics, fun pt/2, [])
end.

Expand Down Expand Up @@ -211,7 +211,7 @@ maybe_create(CB, [FolsomType, Name | Args]) ->
ignore
catch
Cat:Msg ->
?log(error, "~p:copy_folsom(~p,~p,~p): ~p:~p~n",
[CB, Name, FolsomType, Args, Cat, Msg]),
?LOG_ERROR("~p:copy_folsom(~p,~p,~p): ~p:~p~n",
[CB, Name, FolsomType, Args, Cat, Msg]),
ignore
end.
28 changes: 14 additions & 14 deletions src/exometer_report.erl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

-export_type([metric/0, datapoint/0, interval/0, extra/0]).

-include_lib("hut/include/hut.hrl").
-include_lib("kernel/include/logger.hrl").
-include("exometer.hrl").

-define(SERVER, ?MODULE).
Expand Down Expand Up @@ -688,7 +688,7 @@ start_reporters() ->

do_start_reporters(S) ->
Opts = get_report_env(),
?log(info, "Starting reporters with ~p~n", [ Opts ]),
?LOG_INFO("Starting reporters with ~p~n", [ Opts ]),
%% Dig out the mod opts.
%% { reporters, [ {reporter1, [{opt1, val}, ...]}, {reporter2, [...]}]}
%% Traverse list of reporter and launch reporter gen servers as dynamic
Expand Down Expand Up @@ -1145,7 +1145,7 @@ handle_info({'DOWN', Ref, process, _Pid, Reason}, #st{} = S) ->
{noreply, S};

handle_info(_Info, State) ->
?log(warning, "exometer_report:info(??): ~p~n", [ _Info ]),
?LOG_WARNING("exometer_report:info(??): ~p~n", [ _Info ]),
{noreply, State}.

restart_reporter(#reporter{name = Name, opts = Opts, restart = Restart}) ->
Expand Down Expand Up @@ -1214,7 +1214,7 @@ handle_report(#key{reporter = Reporter} = Key, Interval, TS, #st{} = St) ->
end;
false ->
%% Possibly an unsubscribe removed the subscriber
?log(error, "No such subscriber (Key=~p)~n", [Key])
?LOG_ERROR("No such subscriber (Key=~p)~n", [Key])
end,
St.

Expand All @@ -1229,14 +1229,14 @@ do_report(#key{metric = Metric,
true;
%% We did not find a value, but we should try again.
{true, _ } ->
?log(debug, "Metric(~p) Datapoint(~p) not found."
?LOG_DEBUG("Metric(~p) Datapoint(~p) not found."
" Will try again in ~p msec~n",
[Metric, DataPoint, Interval]),
true;
%% We did not find a value, and we should not retry.
_ ->
%% Entry removed while timer in progress.
?log(warning, "Metric(~p) Datapoint(~p) not found. Will not try again~n",
?LOG_WARNING("Metric(~p) Datapoint(~p) not found. Will not try again~n",
[Metric, DataPoint]),
false
end.
Expand Down Expand Up @@ -1516,7 +1516,7 @@ subscribe_(Reporter, Metric, DataPoint, Interval, RetryFailedMetrics,
},
case ets:lookup(?EXOMETER_SUBS, Key) of
[] ->
?log(debug, "subscribe_(~p, ~p, ~p, ~p, ~p, ~p, ~p)~n",
?LOG_DEBUG("subscribe_(~p, ~p, ~p, ~p, ~p, ~p, ~p)~n",
[Reporter, Metric, DataPoint, Interval, RetryFailedMetrics, Extra, Status]),
ets:insert(?EXOMETER_SUBS,
#subscriber{key = Key,
Expand All @@ -1539,7 +1539,7 @@ unsubscribe_(Reporter, Metric, DataPoint, Extra) ->
datapoint = DataPoint,
extra = Extra}) of
[#subscriber{} = Sub] ->
?log(info, "unsubscribe_(~p, ~p, ~p, ~p)~n",
?LOG_INFO("unsubscribe_(~p, ~p, ~p, ~p)~n",
[ Reporter, Metric, DataPoint, Extra]),
unsubscribe_(Sub);
[] ->
Expand All @@ -1559,7 +1559,7 @@ report_values(Found, #key{reporter = Reporter, extra = Extra} = Key) ->
try Reporter ! {exometer_report, Found, Extra}
catch
?EXCEPTION(error, Reason, Stacktrace) ->
?log(error, "~p~nKey = ~p~nTrace: ~p",
?LOG_ERROR("~p~nKey = ~p~nTrace: ~p",
[Reason, Key, ?GET_STACK(Stacktrace)])
end.

Expand Down Expand Up @@ -1590,7 +1590,7 @@ get_subscribers(Metric, Type, Status,
metric = Metric,
datapoint = SDataPoint
}} | T ]) ->
?log(debug,"get_subscribers(~p, ~p, ~p): match~n", [ Metric, SDataPoint, SReporter]),
?LOG_DEBUG("get_subscribers(~p, ~p, ~p): match~n", [ Metric, SDataPoint, SReporter]),
[ { SReporter, SDataPoint } | get_subscribers(Metric, Type, Status, T) ];

%% get_subscribers(Metric, Type, Status,
Expand All @@ -1616,7 +1616,7 @@ get_subscribers(Metric, Type, Status,
metric = SMetric,
datapoint = SDataPoint
}} | T]) ->
?log(debug, "get_subscribers(~p, ~p, ~p) nomatch(~p) ~n",
?LOG_DEBUG("get_subscribers(~p, ~p, ~p) nomatch(~p) ~n",
[ SMetric, SDataPoint, SReporter, Metric]),
get_subscribers(Metric, Type, Status, T).

Expand Down Expand Up @@ -1646,7 +1646,7 @@ reporter_init(Reporter, Opts) ->
{ok, St} ->
{ok, Module, #rst{st = St, bulk = Bulk}};
{error, Reason} ->
?log(error, "Failed to start reporter ~p: ~p~n", [Module, Reason]),
?LOG_ERROR("Failed to start reporter ~p: ~p~n", [Module, Reason]),
exit(Reason)
end.

Expand Down Expand Up @@ -1697,7 +1697,7 @@ reporter_loop(Module, #rst{st = St, bulk = Bulk} = RSt) ->
end;
%% Allow reporters to generate their own callbacks.
Other ->
?log(debug, "Custom invocation: ~p(~p)~n", [ Module, Other]),
?LOG_DEBUG("Custom invocation: ~p(~p)~n", [ Module, Other]),
case Module:exometer_info(Other, St) of
{ok, St1} -> {ok, St1};
_ -> {ok, St}
Expand Down Expand Up @@ -1776,7 +1776,7 @@ init_subscriber({select, Expr}) when tuple_size(Expr)==3;
end, Entries);

init_subscriber(Other) ->
?log(warning, "Incorrect static subscriber spec ~p. "
?LOG_WARNING("Incorrect static subscriber spec ~p. "
"Use { Reporter, Metric, DataPoint, Interval [, Extra ]}~n",
[ Other ]).

Expand Down
12 changes: 6 additions & 6 deletions src/exometer_report_tty.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
exometer_terminate/2
]).

-include_lib("hut/include/hut.hrl").
-include_lib("kernel/include/logger.hrl").
-include("exometer.hrl").

-define(SERVER, ?MODULE).
Expand All @@ -54,7 +54,7 @@
%%%===================================================================

exometer_init(Opts) ->
?log(info, "~p(~p): Starting~n", [?MODULE, Opts]),
?LOG_INFO("~p(~p): Starting~n", [?MODULE, Opts]),
TypeMap = proplists:get_value(type_map, Opts, []),
{ok, #st{type_map = TypeMap}}.

Expand All @@ -67,7 +67,7 @@ exometer_unsubscribe(_Metric, _DataPoint, _Extra, St) ->
%% Invoked through the remote_exometer() function to
%% send out an update.
exometer_report(Metric, DataPoint, Extra, Value, St) ->
?log(debug, "Report metric ~p_~p = ~p~n", [Metric, DataPoint, Value]),
?LOG_DEBUG("Report metric ~p_~p = ~p~n", [Metric, DataPoint, Value]),
%% Report the value and setup a new refresh timer.
Key = Metric ++ [DataPoint],
Type = case exometer_util:report_type(Key, Extra, St#st.type_map) of
Expand All @@ -80,15 +80,15 @@ exometer_report(Metric, DataPoint, Extra, Value, St) ->
{ok, St}.

exometer_call(Unknown, From, St) ->
?log(info, "Unknown call ~p from ~p", [Unknown, From]),
?LOG_INFO("Unknown call ~p from ~p", [Unknown, From]),
{ok, St}.

exometer_cast(Unknown, St) ->
?log(info, "Unknown cast: ~p", [Unknown]),
?LOG_INFO("Unknown cast: ~p", [Unknown]),
{ok, St}.

exometer_info(Unknown, St) ->
?log(info, "Unknown info: ~p", [Unknown]),
?LOG_INFO("Unknown info: ~p", [Unknown]),
{ok, St}.

exometer_newentry(_Entry, St) ->
Expand Down

0 comments on commit 10d76e8

Please sign in to comment.