Skip to content

Commit

Permalink
Avoid double notifying on node termiation.
Browse files Browse the repository at this point in the history
When a node was terminated aten would sometimes send two notifications
to registered listeners. One when it detected the node as not responding
and one next interval when it detected it as gone.

This adds a check for gone case to see if the node has already been
detected as down and only sends a down notification in this scenario
if the prior state is not down.

Also return `ignore` if trying to monitor the current node.
  • Loading branch information
kjnilsson committed Dec 19, 2023
1 parent d89ad9c commit 70911ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 7 additions & 11 deletions src/aten.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@
start/0,
register/1,
unregister/1
]).

-export_type([
]).

]).

start() ->
application:ensure_all_started(aten).

-spec register(node()) -> ok.
-spec register(node()) -> ok | ignore.
register(Node) when Node == node() ->
ignore;
register(Node) ->
aten_detector:register(Node).

-spec unregister(node()) -> ok.
-spec unregister(node()) -> ok | ignore.
unregister(Node) when Node == node() ->
ignore;
unregister(Node) ->
aten_detector:unregister(Node).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
12 changes: 10 additions & 2 deletions src/aten_detector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,18 @@ analyse_one(_Curr, _Prev, _Thresh) ->
no_change.

analyse(Curr, Prev, Thresh) ->
Down0 = maps:fold(fun (N, _S, Acc) ->
Down0 = maps:fold(fun (N, Sample, Acc) ->
case maps:get(N, Curr, undefined) of
undefined ->
[N | Acc];
case Sample >= Thresh of
true ->
%% already down
%% this should already have been
%% been notified
Acc;
_ ->
[N | Acc]
end;
_ ->
Acc
end
Expand Down
2 changes: 0 additions & 2 deletions src/aten_sink.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

-behaviour(gen_server).

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

%% API functions
-export([start_link/0,
get_failure_probabilities/0,
Expand Down

0 comments on commit 70911ba

Please sign in to comment.