Skip to content

Commit

Permalink
Use amoc telemetry events to do logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 19, 2024
1 parent 3d80eba commit 928cbd2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{alias, [{test, [compile, ct, xref, dialyzer]}]}.

{deps, [
{amoc, {git, "https://github.com/esl/amoc", {tag, "3.0.0-rc3"}}},
{amoc, "3.0.0"},
{telemetry, "1.2.1"},
{exometer_core, {git, "https://github.com/esl/exometer_core.git", {branch, "master"}}},
{exometer_report_graphite,
{git, "https://github.com/esl/exometer_report_graphite.git", {branch, "master"}}},
Expand Down
9 changes: 4 additions & 5 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{"1.2.0",
[{<<"amoc">>,
{git,"https://github.com/esl/amoc",
{ref,"dc2a8250a7a3f5985f25d59a177a6200a7028528"}},
0},
[{<<"amoc">>,{pkg,<<"amoc">>,<<"3.0.0">>},0},
{<<"amoc_rest">>,
{git,"https://github.com/esl/amoc_rest.git",
{ref,"103c3123a8cf0464b9c3f9392af6a396673f67bd"}},
Expand All @@ -26,9 +23,10 @@
{<<"providers">>,{pkg,<<"providers">>,<<"1.8.1">>},1},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.8.0">>},2},
{<<"rfc3339">>,{pkg,<<"rfc3339">>,<<"0.9.0">>},1},
{<<"telemetry">>,{pkg,<<"telemetry">>,<<"1.2.1">>},1}]}.
{<<"telemetry">>,{pkg,<<"telemetry">>,<<"1.2.1">>},0}]}.
[
{pkg_hash,[
{<<"amoc">>, <<"DFBE52A36237EE7659D9E691F392E16DC5634346800CBB4A1F971143984C1DC1">>},
{<<"bear">>, <<"430419C1126B477686CDE843E88BA0F2C7DC5CDF0881C677500074F704339A99">>},
{<<"cowboy">>, <<"865DD8B6607E14CF03282E10E934023A1BD8BE6F6BACF921A7E2A96D800CD452">>},
{<<"cowlib">>, <<"0B9FF9C346629256C42EBE1EEB769A83C6CB771A6EE5960BD110AB0B9B872063">>},
Expand All @@ -42,6 +40,7 @@
{<<"rfc3339">>, <<"2075653DC9407541C84B1E15F8BDA2ABE95FB17C9694025E079583F2D19C1060">>},
{<<"telemetry">>, <<"68FDFE8D8F05A8428483A97D7AAB2F268AAFF24B49E0F599FAA091F1D4E7F61C">>}]},
{pkg_hash_ext,[
{<<"amoc">>, <<"66A377798F9F4F6361C223A586FEB32CA6B3401FA106850C9D9682FEB3BBD5B9">>},
{<<"bear">>, <<"157B67901ADF84FF0DA6EAE035CA1292A0AC18AA55148154D8C582B2C68959DB">>},
{<<"cowboy">>, <<"2C729F934B4E1AA149AFF882F57C6372C15399A20D54F65C8D67BEF583021BDE">>},
{<<"cowlib">>, <<"2B3E9DA0B21C4565751A6D4901C20D1B4CC25CBB7FD50D91D2AB6DD287BC86A9">>},
Expand Down
1 change: 1 addition & 0 deletions src/amoc_arsenal_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
start(_StartType, _StartArgs) ->
{ok, _} = amoc_api:start(),
amoc_metrics:start(),
amoc_logging:start(),
amoc_arsenal_sup:start_link().

stop(_State) ->
Expand Down
36 changes: 36 additions & 0 deletions src/amoc_logging.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-module(amoc_logging).

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

-export([start/0,
handle_cluster_event/4,
handle_log_event/4]).

start() ->
ok = telemetry:attach_many(
<<"amoc-arsenal-logging-cluster">>,
[
[amoc, cluster, connect_nodes],
[amoc, cluster, nodedown],
[amoc, cluster, master_node_down]
],
fun ?MODULE:handle_cluster_event/4, []),
ok = telemetry:attach_many(
<<"amoc-arsenal-logging-pure-log-events">>,
[
[amoc, config, get],
[amoc, config, verify],
[amoc, config, env],
[amoc, throttle, process]
],
fun ?MODULE:handle_log_event/4, []).

handle_cluster_event([amoc, cluster, connect_nodes], _, #{nodes := Nodes, state := State}, _) ->
?LOG(info, #{msg => <<"connecting to nodes">>, node => node(), nodes => Nodes, state => State});
handle_cluster_event([amoc, cluster, nodedown], _, #{nodes := [Node]}, _) ->
?LOG(error, #{msg => <<"node is down">>, node => Node});
handle_cluster_event([amoc, cluster, master_node_down], _, #{nodes := [Master]}, _) ->
?LOG(error, #{msg => <<"Master node is down. Halting.">>, node => Master}).

handle_log_event([amoc | _], _, #{log_level := Level} = Metadata, _) ->
?LOG(Level, Metadata).

0 comments on commit 928cbd2

Please sign in to comment.