Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
nodes/0,
locally_known_nodes/0,
get_ra_cluster_name/0,
get_server_id/1,
get_store_id/0,
transfer_leadership/1,

Expand Down Expand Up @@ -677,6 +678,14 @@ locally_known_nodes() ->
get_ra_cluster_name() ->
?RA_CLUSTER_NAME.

-spec get_server_id(Node) -> RaServerId when
Node :: node(),
RaServerId :: ra:server_id().
%% @doc Returns the Ra server id of the Khepri member on the given node.

get_server_id(Node) ->
{?RA_CLUSTER_NAME, Node}.

-spec get_store_id() -> StoreId when
StoreId :: khepri:store_id().
%% @doc Returns the Khepri store identifier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

-import(prometheus_text_format, [escape_label_value/1]).

-include_lib("stdlib/include/assert.hrl").
-include_lib("kernel/include/logger.hrl").
-include_lib("rabbit_common/include/rabbit.hrl").

-behaviour(prometheus_collector).
Expand Down Expand Up @@ -303,6 +305,12 @@ deregister_cleanup(_) -> ok.
collect_mf('detailed', Callback) ->
collect(true, ?DETAILED_METRIC_NAME_PREFIX, vhosts_filter_from_pdict(), enabled_mfs_from_pdict(?METRICS_RAW), Callback),
collect(true, ?CLUSTER_METRIC_NAME_PREFIX, vhosts_filter_from_pdict(), enabled_mfs_from_pdict(?METRICS_CLUSTER), Callback),
case is_mf_enabled(khepri) of
true ->
collect_khepri_info(Callback);
false ->
ok
end,
%% identity is here to enable filtering on a cluster name (as already happens in existing dashboards)
emit_identity_info(<<"detailed">>, Callback),
ok;
Expand Down Expand Up @@ -339,6 +347,20 @@ totals(Callback) ->
end || {Table, Name, Type, Help} <- ?TOTALS],
ok.

collect_khepri_info(Callback) ->
ServerId = rabbit_khepri:get_server_id(node()),
maps:foreach(
fun (Name, #{type := Type, help := Help, values := #{ServerId := Value}}) ->
Callback(
create_mf(
<<?DETAILED_METRIC_NAME_PREFIX/binary,
"khepri_",
(prometheus_model_helpers:metric_name(Name))/binary>>,
Help, Type, [Value]));
(_Name, _Format) ->
ok
end, seshat:format(ra)).

emit_identity_info(Endpoint, Callback) ->
add_metric_family(build_info(), Callback),
add_metric_family(identity_info(Endpoint), Callback),
Expand Down Expand Up @@ -871,12 +893,19 @@ sum('', B) ->
sum(A, B) ->
A + B.

is_mf_enabled(MF) ->
case get(prometheus_mf_filter) of
undefined ->
false;
MFNameSet ->
sets:is_element(MF, MFNameSet)
end.

enabled_mfs_from_pdict(AllMFs) ->
case get(prometheus_mf_filter) of
undefined ->
[];
MFNames ->
MFNameSet = sets:from_list(MFNames),
MFNameSet ->
[ MF || MF = {Table, _} <- AllMFs, sets:is_element(Table, MFNameSet) ]
end.

Expand All @@ -890,4 +919,3 @@ vhosts_filter_from_pdict() ->
Enabled = maps:from_list([ {VHost, true} || VHost <- L ]),
maps:merge(All, Enabled)
end.

2 changes: 1 addition & 1 deletion deps/rabbitmq_prometheus/src/rabbit_prometheus_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ put_filtering_options_into_process_dictionary(Request) ->
end,
case parse_metric_families(Families) of
Fs when is_list(Fs) ->
put(prometheus_mf_filter, Fs);
put(prometheus_mf_filter, sets:from_list(Fs, [{version, 2}]));
_ -> ok
end,
ok.
Expand Down
Loading