Skip to content

Commit 2329906

Browse files
committed
Remove ra_metrics
1 parent 69c13f8 commit 2329906

File tree

7 files changed

+34
-75
lines changed

7 files changed

+34
-75
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
@@ -123,11 +123,11 @@ sheet_header() ->
123123
sheet_body(PrevState) ->
124124
{_, RaStates} = rabbit_quorum_queue:all_replica_states(),
125125
Body = [begin
126-
#resource{name = Name, virtual_host = Vhost} = R = amqqueue:get_name(Q),
126+
#resource{name = Name, virtual_host = Vhost} = amqqueue:get_name(Q),
127127
case rabbit_amqqueue:pid_of(Q) of
128128
none ->
129129
empty_row(Name);
130-
{QName, _QNode} = _QQ ->
130+
{QName, _QNode} = ServerId ->
131131
case whereis(QName) of
132132
undefined ->
133133
empty_row(Name);
@@ -139,7 +139,12 @@ sheet_body(PrevState) ->
139139
_ ->
140140
QQCounters = maps:get({QName, node()}, ra_counters:overview()),
141141
{ok, InternalName} = rabbit_queue_type_util:qname_to_internal_name(#resource{virtual_host = Vhost, name= Name}),
142-
[{_, CT, SnapIdx, LA, CI, LW, CL}] = ets:lookup(ra_metrics, R),
142+
#{snapshot_index := SnapIdx,
143+
last_written_index := LW,
144+
term := CT,
145+
commit_latency := CL,
146+
commit_index := CI,
147+
last_applied := LA} = ra:key_metrics(ServerId),
143148
[
144149
Pid,
145150
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
@@ -267,20 +267,8 @@ i(context_switches, State) ->
267267
{Sw, 0} = erlang:statistics(context_switches),
268268
{State, Sw};
269269
i(ra_open_file_metrics, State) ->
270-
{State, [{ra_log_wal, ra_metrics(ra_log_wal)},
271-
{ra_log_segment_writer, ra_metrics(ra_log_segment_writer)}]}.
272-
273-
ra_metrics(K) ->
274-
try
275-
case ets:lookup(ra_open_file_metrics, whereis(K)) of
276-
[] -> 0;
277-
[{_, C}] -> C
278-
end
279-
catch
280-
error:badarg ->
281-
%% On startup the mgmt might start before ra does
282-
0
283-
end.
270+
{State, [{ra_log_wal, 0},
271+
{ra_log_segment_writer, 0}]}.
284272

285273
resource_alarm_set(Source) ->
286274
lists:member({{resource_limit, Source, node()},[]},
@@ -421,7 +409,7 @@ update_state(State0) ->
421409
get_fhc_stats() ->
422410
dict:to_list(dict:merge(fun(_, V1, V2) -> V1 + V2 end,
423411
dict:from_list(zero_fhc_stats()),
424-
dict:from_list(get_ra_io_metrics()))).
412+
dict:from_list(get_zero_ra_io_metrics()))).
425413

426414
zero_fhc_stats() ->
427415
[{{Op, Counter}, 0} || Op <- [io_read, io_write],
@@ -435,5 +423,17 @@ zero_fhc_stats() ->
435423
queue_index_write, queue_index_read],
436424
Counter <- [count]].
437425

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

deps/rabbitmq_prometheus/docker/grafana/dashboards/RabbitMQ-Quorum-Queues-Raft.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
"type": "prometheus",
419419
"uid": "${DS_PROMETHEUS}"
420420
},
421-
"expr": "rabbitmq_raft_entry_commit_latency_seconds * on(instance, job) group_left(rabbitmq_cluster, rabbitmq_node) rabbitmq_identity_info{rabbitmq_cluster=\"$rabbitmq_cluster\", namespace=\"$namespace\",rabbitmq_endpoint=\"$endpoint\"}",
421+
"expr": "rabbitmq_raft_commit_latency_seconds * on(instance, job) group_left(rabbitmq_cluster, rabbitmq_node) rabbitmq_identity_info{rabbitmq_cluster=\"$rabbitmq_cluster\", namespace=\"$namespace\",rabbitmq_endpoint=\"$endpoint\"}",
422422
"format": "time_series",
423423
"instant": false,
424424
"intervalFactor": 1,

deps/rabbitmq_prometheus/metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ These metrics are specific to the stream protocol.
249249

250250
| Metric | Description |
251251
| --- | --- |
252-
| rabbitmq_raft_entry_commit_latency_seconds | Time taken for an entry to be committed |
252+
| rabbitmq_raft_commit_latency_seconds | Time taken for an entry to be committed |
253253
| rabbitmq_raft_log_commit_index | Raft log commit index |
254254
| rabbitmq_raft_log_last_applied_index | Raft log last applied index |
255255
| rabbitmq_raft_log_last_written_index | Raft log last written index |

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) ->

deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ aggregated_metrics_test(Config) ->
392392
?assertEqual(match, re:run(Body, "^rabbitmq_process_open_fds ", [{capture, none}, multiline])),
393393
?assertEqual(match, re:run(Body, "^rabbitmq_process_max_fds ", [{capture, none}, multiline])),
394394
?assertEqual(match, re:run(Body, "^rabbitmq_io_read_ops_total ", [{capture, none}, multiline])),
395-
?assertEqual(match, re:run(Body, "^rabbitmq_raft_term ", [{capture, none}, multiline])),
396395
?assertEqual(match, re:run(Body, "^rabbitmq_queue_messages_ready ", [{capture, none}, multiline])),
397396
?assertEqual(match, re:run(Body, "^rabbitmq_queue_consumers ", [{capture, none}, multiline])),
398397
?assertEqual(match, re:run(Body, "TYPE rabbitmq_auth_attempts_total", [{capture, none}, multiline])),
@@ -403,7 +402,7 @@ aggregated_metrics_test(Config) ->
403402
%% Check the first TOTALS metric value
404403
?assertEqual(match, re:run(Body, "^rabbitmq_connections ", [{capture, none}, multiline])),
405404
%% Check raft_entry_commit_latency_seconds because we are aggregating it
406-
?assertEqual(match, re:run(Body, "^rabbitmq_raft_entry_commit_latency_seconds ", [{capture, none}, multiline])).
405+
?assertEqual(match, re:run(Body, "^rabbitmq_raft_commit_latency_seconds ", [{capture, none}, multiline])).
407406

408407
endpoint_per_object_metrics(Config) ->
409408
per_object_metrics_test(Config, "/metrics/per-object").
@@ -439,7 +438,7 @@ per_object_metrics_test(Config, Path) ->
439438
%% Check the first metric value in each ETS table that requires converting
440439
?assertEqual(match, re:run(Body, "^rabbitmq_erlang_uptime_seconds ", [{capture, none}, multiline])),
441440
?assertEqual(match, re:run(Body, "^rabbitmq_io_read_time_seconds_total ", [{capture, none}, multiline])),
442-
?assertEqual(match, re:run(Body, "^rabbitmq_raft_entry_commit_latency_seconds{", [{capture, none}, multiline])),
441+
?assertEqual(match, re:run(Body, "^rabbitmq_raft_commit_latency_seconds{", [{capture, none}, multiline])),
443442
%% Check the first TOTALS metric value
444443
?assertEqual(match, re:run(Body, "^rabbitmq_connections ", [{capture, none}, multiline])).
445444

0 commit comments

Comments
 (0)