Skip to content

Commit 50d5b80

Browse files
committed
Remove ra_metrics
1 parent 4574477 commit 50d5b80

File tree

4 files changed

+30
-70
lines changed

4 files changed

+30
-70
lines changed

deps/rabbit/src/rabbit_observer_cli_quorum_queues.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ sheet_header() ->
114114
sheet_body(PrevState) ->
115115
{_, RaStates} = rabbit_quorum_queue:all_replica_states(),
116116
Body = [begin
117-
#resource{name = Name, virtual_host = Vhost} = R = amqqueue:get_name(Q),
117+
#resource{name = Name, virtual_host = Vhost} = amqqueue:get_name(Q),
118118
case rabbit_amqqueue:pid_of(Q) of
119119
none ->
120120
empty_row(Name);
121-
{QName, _QNode} = _QQ ->
121+
{QName, _QNode} = ServerId ->
122122
case whereis(QName) of
123123
undefined ->
124124
empty_row(Name);
@@ -130,7 +130,12 @@ sheet_body(PrevState) ->
130130
_ ->
131131
QQCounters = maps:get({QName, node()}, ra_counters:overview()),
132132
{ok, InternalName} = rabbit_queue_type_util:qname_to_internal_name(#resource{virtual_host = Vhost, name= Name}),
133-
[{_, CT, SnapIdx, LA, CI, LW, CL}] = ets:lookup(ra_metrics, R),
133+
#{snapshot_index := SnapIdx,
134+
last_written_index := LW,
135+
term := CT,
136+
commit_latency := CL,
137+
commit_index := CI,
138+
last_applied := LA} = ra:key_metrics(ServerId),
134139
[
135140
Pid,
136141
QName,

deps/rabbit/src/rabbit_quorum_queue.erl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,12 +1598,10 @@ transfer_leadership(Q, Destination) ->
15981598
end.
15991599

16001600
queue_length(Q) ->
1601-
Name = amqqueue:get_name(Q),
1602-
case ets:lookup(ra_metrics, Name) of
1603-
[] -> 0;
1604-
[{_, _, SnapIdx, _, _, LastIdx, _}] ->
1605-
LastIdx - SnapIdx
1606-
end.
1601+
ServerId = amqqueue:get_pid(Q),
1602+
#{snapshot_index := SnapIdx,
1603+
last_written_index := LastIdx} = key_metrics_rpc(ServerId),
1604+
LastIdx - SnapIdx.
16071605

16081606
get_replicas(Q) ->
16091607
get_nodes(Q).

deps/rabbitmq_management_agent/src/rabbit_mgmt_external_stats.erl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,8 @@ i(context_switches, State) ->
264264
{Sw, 0} = erlang:statistics(context_switches),
265265
{State, Sw};
266266
i(ra_open_file_metrics, State) ->
267-
{State, [{ra_log_wal, ra_metrics(ra_log_wal)},
268-
{ra_log_segment_writer, ra_metrics(ra_log_segment_writer)}]}.
269-
270-
ra_metrics(K) ->
271-
try
272-
case ets:lookup(ra_open_file_metrics, whereis(K)) of
273-
[] -> 0;
274-
[{_, C}] -> C
275-
end
276-
catch
277-
error:badarg ->
278-
%% On startup the mgmt might start before ra does
279-
0
280-
end.
267+
{State, [{ra_log_wal, 0},
268+
{ra_log_segment_writer, 0}]}.
281269

282270
resource_alarm_set(Source) ->
283271
lists:member({{resource_limit, Source, node()},[]},
@@ -418,7 +406,7 @@ update_state(State0) ->
418406
get_fhc_stats() ->
419407
dict:to_list(dict:merge(fun(_, V1, V2) -> V1 + V2 end,
420408
dict:from_list(zero_fhc_stats()),
421-
dict:from_list(get_ra_io_metrics()))).
409+
dict:from_list(get_zero_ra_io_metrics()))).
422410

423411
zero_fhc_stats() ->
424412
[{{Op, Counter}, 0} || Op <- [io_read, io_write],
@@ -432,5 +420,17 @@ zero_fhc_stats() ->
432420
queue_index_write, queue_index_read],
433421
Counter <- [count]].
434422

435-
get_ra_io_metrics() ->
436-
lists:sort(ets:tab2list(ra_io_metrics)).
423+
get_zero_ra_io_metrics() ->
424+
%% not tracked anymore
425+
[{{io_file_handle_open_attempt,count},0},
426+
{{io_file_handle_open_attempt,time},0},
427+
{{io_read,bytes},0},
428+
{{io_read,count},0},
429+
{{io_read,time},0},
430+
{{io_seek,count},0},
431+
{{io_seek,time},0},
432+
{{io_sync,count},0},
433+
{{io_sync,time},0},
434+
{{io_write,bytes},0},
435+
{{io_write,count},0},
436+
{{io_write,time},0}].

deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@
106106
{2, ?MICROSECOND, io_seek_time_seconds_total, counter, "Total I/O seek time", io_seek_time}
107107
]},
108108

109-
{ra_metrics, [
110-
{2, undefined, raft_term_total, counter, "Current Raft term number"},
111-
{3, undefined, raft_log_snapshot_index, gauge, "Raft log snapshot index"},
112-
{4, undefined, raft_log_last_applied_index, gauge, "Raft log last applied index"},
113-
{5, undefined, raft_log_commit_index, gauge, "Raft log commit index"},
114-
{6, undefined, raft_log_last_written_index, gauge, "Raft log last written index"},
115-
{7, ?MILLISECOND, raft_entry_commit_latency_seconds, gauge, "Time taken for a log entry to be committed"}
116-
]},
117-
118109
{auth_attempt_metrics, [
119110
{2, undefined, auth_attempts_total, counter, "Total number of authentication attempts"},
120111
{3, undefined, auth_attempts_succeeded_total, counter, "Total number of successful authentication attempts"},
@@ -701,7 +692,6 @@ get_data(Table, false, VHostsFilter) when Table == channel_exchange_metrics;
701692
Table == exchange_metrics;
702693
Table == queue_exchange_metrics;
703694
Table == channel_queue_exchange_metrics;
704-
Table == ra_metrics;
705695
Table == channel_process_metrics ->
706696
Result = ets:foldl(fun
707697
%% For queue_coarse_metrics
@@ -723,33 +713,10 @@ get_data(Table, false, VHostsFilter) when Table == channel_exchange_metrics;
723713
{T, V1 + A1, V2 + A2, V3 + A3, V4 + A4};
724714
({_, V1, V2, V3, V4}, {T, A1, A2, A3, A4}) ->
725715
{T, V1 + A1, V2 + A2, V3 + A3, V4 + A4};
726-
({_, V1, V2, V3, V4, V5, V6}, {T, A1, A2, A3, A4, A5, A6}) ->
727-
%% ra_metrics: raft_entry_commit_latency_seconds needs to be an average
728-
{T, V1 + A1, V2 + A2, V3 + A3, V4 + A4, V5 + A5, accumulate_count_and_sum(V6, A6)};
729716
({_, V1, V2, V3, V4, V5, V6, V7, _}, {T, A1, A2, A3, A4, A5, A6, A7}) ->
730717
{T, V1 + A1, V2 + A2, V3 + A3, V4 + A4, V5 + A5, V6 + A6, V7 + A7}
731718
end, empty(Table), Table),
732-
case Table of
733-
%% raft_entry_commit_latency_seconds needs to be an average
734-
ra_metrics ->
735-
{Count, Sum} = element(7, Result),
736-
[setelement(7, Result, division(Sum, Count))];
737-
_ ->
738-
[Result]
739-
end;
740-
get_data(ra_metrics = Table, true, _) ->
741-
ets:foldl(
742-
fun ({#resource{kind = queue}, _, _, _, _, _, _} = Row, Acc) ->
743-
%% Metrics for QQ records use the queue resource as the table
744-
%% key. The queue name and vhost will be rendered as tags.
745-
[Row | Acc];
746-
({ClusterName, _, _, _, _, _, _} = Row, Acc) when is_atom(ClusterName) ->
747-
%% Other Ra clusters like Khepri and the stream coordinator use
748-
%% the cluster name as the metrics key. Transform this into a
749-
%% value that can be rendered as a "raft_cluster" tag.
750-
Row1 = setelement(1, Row, #{<<"raft_cluster">> => atom_to_binary(ClusterName, utf8)}),
751-
[Row1 | Acc]
752-
end, [], Table);
719+
[Result];
753720
get_data(exchange_metrics = Table, true, VHostsFilter) when is_map(VHostsFilter)->
754721
ets:foldl(fun
755722
({#resource{kind = exchange, virtual_host = VHost}, _, _, _, _, _} = Row, Acc) when
@@ -912,22 +879,12 @@ sum_queue_metrics(Props, {T, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11,
912879
sum(proplists:get_value(segments, Props), A17)
913880
}.
914881

915-
division(0, 0) ->
916-
0;
917-
division(A, B) ->
918-
A / B.
919-
920-
accumulate_count_and_sum(Value, {Count, Sum}) ->
921-
{Count + 1, Sum + Value}.
922-
923882
empty(T) when T == channel_queue_exchange_metrics; T == queue_exchange_metrics; T == channel_process_metrics; T == queue_consumer_count ->
924883
{T, 0};
925884
empty(T) when T == connection_coarse_metrics; T == auth_attempt_metrics; T == auth_attempt_detailed_metrics ->
926885
{T, 0, 0, 0};
927886
empty(T) when T == channel_exchange_metrics; T == exchange_metrics; T == queue_coarse_metrics; T == connection_metrics ->
928887
{T, 0, 0, 0, 0};
929-
empty(T) when T == ra_metrics ->
930-
{T, 0, 0, 0, 0, 0, {0, 0}};
931888
empty(T) when T == channel_queue_metrics; T == queue_delivery_metrics; T == channel_metrics ->
932889
{T, 0, 0, 0, 0, 0, 0, 0};
933890
empty(queue_metrics = T) ->

0 commit comments

Comments
 (0)