Skip to content

Commit

Permalink
Merge pull request #1 from esl/amoc_logging
Browse files Browse the repository at this point in the history
Use amoc telemetry events to do logging
  • Loading branch information
DenysGonchar authored Jan 19, 2024
2 parents f729b77 + 97efcd4 commit 1922067
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: OTP ${{matrix.otp}}
strategy:
matrix:
otp: ['26.0', '25.3', '24.3']
otp: ['26.2', '25.3', '24.3']
runs-on: 'ubuntu-22.04'
steps:
- uses: actions/checkout@v4
Expand All @@ -28,7 +28,7 @@ jobs:
name: docker container test with OTP ${{matrix.otp}}
strategy:
matrix:
otp: ['25.3', '24.3']
otp: ['26.2', '25.3', '24.3']
runs-on: 'ubuntu-22.04'
env:
OTP_RELEASE: ${{ matrix.otp }}
Expand All @@ -37,7 +37,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
rebar3-version: '3.21.0'
rebar3-version: '3.22.0'
- run: ./ci/build_docker_image.sh
- run: ./ci/start_demo_cluster.sh
- run: ./ci/test_amoc_cluster.sh
Expand Down
2 changes: 1 addition & 1 deletion ci/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enable_strict_mode
cd "$git_root"

version="$(git rev-parse --short HEAD)"
otp_vsn="${OTP_RELEASE:-25.3}"
otp_vsn="${OTP_RELEASE:-26.2}"
echo "ERLANG/OTP '${otp_vsn}'"

docker build \
Expand Down
20 changes: 18 additions & 2 deletions 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 All @@ -22,7 +23,7 @@
]}.

{dialyzer, [
{plt_extra_apps, [compiler, amoc, ranch, cowboy, jsx]}
{plt_extra_apps, [compiler, telemetry, amoc, ranch, cowboy, jsx]}
]}.

{ xref_checks, [
Expand All @@ -31,6 +32,21 @@
deprecated_function_calls, deprecated_functions
]}.

{overrides, [
%% https://github.com/for-GET/jesse/blob/cf075d213ae9e9c54a748c93cc64d5350e646f9a/rebar.config#L11
%% and OTP26.1 throws warnings for matching on 0.0, as in the future +0.0 and -0.0 will not be considered equal anymore.
{override, jesse, [{erl_opts, [ {platform_define, "^R[0-9]+", erlang_deprecated_types}
, warn_export_vars
, warn_obsolete_guard
, warn_shadow_vars
, warn_untyped_record
, warn_unused_function
, warn_unused_import
, warn_unused_record
, warn_unused_vars
]}]}
]}.

{relx, [
{release, {amoc_arsenal, {git, short}}, [amoc_arsenal, runtime_tools]},
{debug_info, keep},
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).
5 changes: 3 additions & 2 deletions src/amoc_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ maybe_add_reporter() ->
case lists:keyfind(Reporter, 1, exometer_report:list_reporters()) of
{Reporter, _} -> ok;
_->
case amoc_config_env:get(graphite_host) of
case amoc_config_env:get(graphite_host, undefined) of
undefined -> ok;
Host ->
Prefix = amoc_config_env:get(graphite_prefix, net_adm:localhost()),
Expand Down Expand Up @@ -114,5 +114,6 @@ maybe_subscribe(ExName, Datapoints) ->
end.

maybe_init_predefined_metrics() ->
Preconfigured = amoc_config_utils:find_all_vars(predefined_metrics),
App = application:get_application(?MODULE),
Preconfigured = application:get_env(App, predefined_metrics, []),
[init(Type, Name) || {Type, Name} <- lists:flatten(Preconfigured)].
3 changes: 2 additions & 1 deletion test/amoc_api_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ start_amoc() ->
-spec stop_amoc() -> any().
stop_amoc() ->
application:stop(amoc_arsenal),
application:stop(amoc).
application:stop(amoc),
application:stop(telemetry).

-spec remove_module(module()) -> any().
remove_module(M) ->
Expand Down

0 comments on commit 1922067

Please sign in to comment.