Skip to content

Commit

Permalink
Transform cluster log statements into telemetry events
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 1, 2023
1 parent 99772de commit 2e0ad0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 10 additions & 0 deletions guides/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ event_name: [amoc, config, get | verify | env]
measurements: #{}
metadata: #{log_class => syslog_level(), _ => _}
```

## Cluster

### Internal events
There are related to clustering events
```erlang
event_name: [amoc, cluster, connect_nodes | nodedown | master_node_down]
measurements: #{count => non_neg_integer()},
metadata: #{node => node(), nodes => nodes(), state => map()}
```
12 changes: 7 additions & 5 deletions src/amoc_distribution/amoc_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-behaviour(gen_server).
-define(SERVER, ?MODULE).

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

%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------
Expand Down Expand Up @@ -133,7 +131,8 @@ handle_call(_Request, _From, State) ->

-spec handle_cast(any(), state()) -> {noreply, state()}.
handle_cast({connect_nodes, Nodes}, State) ->
?LOG_INFO("{connect_nodes, ~p}, state: ~p", [Nodes, state_to_map(State)]),
telemetry:execute([amoc, cluster, connect_nodes], #{count => length(Nodes)},
#{nodes => Nodes, state => state_to_map(State)}),
NewState = handle_connect_nodes(Nodes, State),
schedule_timer(NewState),
{noreply, NewState};
Expand All @@ -148,11 +147,14 @@ handle_info(timeout, State) ->
schedule_timer(NewState),
{noreply, NewState};
handle_info({nodedown, Node}, #state{master = Node} = State) ->
?LOG_ERROR("Master node ~p is down. Halting.", [Node]),
telemetry:execute([amoc, cluster, master_node_down],
#{count => 1},
#{node => Node, state => state_to_map(State)}),
erlang:halt(),
{noreply, State};
handle_info({nodedown, Node}, State) ->
?LOG_ERROR("node ~p is down.", [Node]),
telemetry:execute([amoc, cluster, nodedown], #{count => 1},
#{node => Node, state => state_to_map(State)}),
{noreply, merge(connection_lost, [Node], State)};
handle_info(_Info, State) ->
{noreply, State}.
Expand Down

0 comments on commit 2e0ad0a

Please sign in to comment.