Add prometheus tags 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.
This commit is contained in:
Michael Davis 2024-08-30 12:41:37 -04:00
parent 86ceac4016
commit 512f8838fd
No known key found for this signature in database
1 changed files with 13 additions and 0 deletions

View File

@ -640,6 +640,19 @@ get_data(Table, false, VHostsFilter) when Table == channel_exchange_metrics;
_ ->
[Result]
end;
get_data(ra_metrics = Table, true, _) ->
ets:foldl(
fun ({#resource{kind = queue}, _, _, _, _, _, _} = Row, Acc) ->
%% Metrics for QQ records use the queue resource as the table
%% key. The queue name and vhost will be rendered as tags.
[Row | Acc];
({ClusterName, _, _, _, _, _, _} = Row, Acc) when is_atom(ClusterName) ->
%% Other Ra clusters like Khepri and the stream coordinator use
%% the cluster name as the metrics key. Transform this into a
%% value that can be rendered as a "raft_cluster" tag.
Row1 = setelement(1, Row, #{<<"raft_cluster">> => atom_to_binary(ClusterName, utf8)}),
[Row1 | Acc]
end, [], Table);
get_data(exchange_metrics = Table, true, VHostsFilter) when is_map(VHostsFilter)->
ets:foldl(fun
({#resource{kind = exchange, virtual_host = VHost}, _, _, _, _, _} = Row, Acc) when