Skip to content

Commit bd7db6a

Browse files
committed
Add prometheus label for raft_cluster to non-QQ raft metrics
By default Ra will use the cluster name as the metrics key. Currently atom values are ignored by the prometheus plugin's tag rendering functions, so if you have a QQ and Khepri running and request the `/metrics/per-object` or `/metrics/detailed` endpoints you'll see values that don't have labels set for the `ra_metrics` metrics: # TYPE rabbitmq_raft_term_total counter # HELP rabbitmq_raft_term_total Current Raft term number rabbitmq_raft_term_total{vhost="/",queue="qq"} 9 rabbitmq_raft_term_total 10 With this change we map the name of the Ra cluster to a "raft_cluster" tag, so instead an example metric might be: # TYPE rabbitmq_raft_term_total counter # HELP rabbitmq_raft_term_total Current Raft term number rabbitmq_raft_term_total{vhost="/",queue="qq"} 9 rabbitmq_raft_term_total{raft_cluster="rabbitmq_metadata"} 10 This affects metrics for Khepri and the stream coordinator. (cherry picked from commit 512f883) (cherry picked from commit 983ac8c)
1 parent 3c6daef commit bd7db6a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl

+13
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,19 @@ get_data(queue_coarse_metrics = Table, true, VHostsFilter, _) when is_map(VHosts
613613
(_, Acc) ->
614614
Acc
615615
end, [], Table);
616+
get_data(ra_metrics = Table, true, _, _) ->
617+
ets:foldl(
618+
fun ({#resource{kind = queue}, _, _, _, _, _, _} = Row, Acc) ->
619+
%% Metrics for QQ records use the queue resource as the table
620+
%% key. The queue name and vhost will be rendered as tags.
621+
[Row | Acc];
622+
({ClusterName, _, _, _, _, _, _} = Row, Acc) when is_atom(ClusterName) ->
623+
%% Other Ra clusters like Khepri and the stream coordinator use
624+
%% the cluster name as the metrics key. Transform this into a
625+
%% value that can be rendered as a "raft_cluster" tag.
626+
Row1 = setelement(1, Row, #{<<"raft_cluster">> => atom_to_binary(ClusterName, utf8)}),
627+
[Row1 | Acc]
628+
end, [], Table);
616629
get_data(MF, true, VHostsFilter, _) when is_map(VHostsFilter), MF == queue_metrics orelse MF == queue_consumer_count ->
617630
Table = queue_metrics,
618631
ets:foldl(fun

0 commit comments

Comments
 (0)