Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ra:key_metrics/2 #461

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/ra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
register_external_log_reader/1,
member_overview/1,
member_overview/2,
key_metrics/1
key_metrics/1,
key_metrics/2
]).

%% xref should pick these up
Expand Down Expand Up @@ -1212,7 +1213,20 @@ member_overview(ServerId, Timeout) ->
%%
%% @param ServerId the Ra server to obtain key metrics for
%% @end
key_metrics({Name, N} = ServerId) when N == node() ->
key_metrics(ServerId) ->
key_metrics(ServerId, ?DEFAULT_TIMEOUT).

%% @doc Returns a map of key metrics about a Ra member
%%
%% The keys and values may vary depending on what state
%% the member is in. This function will never call into the
%% Ra process itself so is likely to return swiftly even
%% when the Ra process is busy (such as when it is recovering)
%%
%% @param ServerId the Ra server to obtain key metrics for
%% @param Timeout The time to wait for the server to reply
%% @end
key_metrics({Name, N} = ServerId, _Timeout) when N == node() ->
Fields = [last_applied,
commit_index,
snapshot_index,
Expand All @@ -1239,8 +1253,8 @@ key_metrics({Name, N} = ServerId) when N == node() ->
membership => Membership}
end
end;
key_metrics({_, N} = ServerId) ->
erpc:call(N, ?MODULE, ?FUNCTION_NAME, [ServerId]).
key_metrics({_, N} = ServerId, Timeout) ->
erpc:call(N, ?MODULE, ?FUNCTION_NAME, [ServerId], Timeout).


%% internal
Expand Down
Loading