Skip to content

Commit 323ce94

Browse files
rabbitmq_shovel_prometheus: handle single atom shovel states
Namely, 'starting'. Previously, a Prometheus scraping endpoint hit just at the right moment (when a shovel was in the 'starting' state) would produce a function_clause exception.
1 parent 9853bda commit 323ce94

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_collector.erl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
%%
77
-module(rabbit_shovel_prometheus_collector).
88

9+
-include_lib("kernel/include/logger.hrl").
10+
-include_lib("rabbit_common/include/logging.hrl").
11+
912
-behaviour(prometheus_collector).
1013

1114
-export([start/0, stop/0]).
@@ -29,10 +32,15 @@ deregister_cleanup(_) -> ok.
2932

3033
collect_mf(_Registry, Callback) ->
3134
Status = rabbit_shovel_status:status(500),
32-
{StaticStatusGroups, DynamicStatusGroups} = lists:foldl(fun({_,static,{S, _}, _, _}, {SMap, DMap}) ->
33-
{maps:update_with(S, fun(C) -> C + 1 end, 1, SMap), DMap};
34-
({_,dynamic,{S, _}, _, _}, {SMap, DMap}) ->
35-
{SMap, maps:update_with(S, fun(C) -> C + 1 end, 1, DMap)}
35+
%% Shovel status can be an atom or a tuple of {string(), proplists:proplist()}
36+
{StaticStatusGroups, DynamicStatusGroups} = lists:foldl(fun({_, static, S, _, _}, {SMap, DMap}) when is_atom(S) ->
37+
{maps:update_with(S, fun(C) -> C + 1 end, 1, SMap), DMap};
38+
({_, static, {S, _}, _, _}, {SMap, DMap}) ->
39+
{maps:update_with(S, fun(C) -> C + 1 end, 1, SMap), DMap};
40+
({_, dynamic, S, _, _}, {SMap, DMap}) when is_atom(S) ->
41+
{SMap, maps:update_with(S, fun(C) -> C + 1 end, 1, DMap)};
42+
({_, dynamic, {S, _}, _, _}, {SMap, DMap}) ->
43+
{SMap, maps:update_with(S, fun(C) -> C + 1 end, 1, DMap)}
3644
end, {#{}, #{}}, Status),
3745

3846
Metrics = [{rabbitmq_shovel_dynamic, gauge, "Number of dynamic shovels",
@@ -47,5 +55,5 @@ add_metric_family({Name, Type, Help, Metrics}, Callback) ->
4755
Callback(create_mf(Name, Help, Type, Metrics)).
4856

4957
%%====================================================================
50-
%% Private Parts
58+
%% Implementation
5159
%%====================================================================

0 commit comments

Comments
 (0)