Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #10345. Add promtheus_rabbitmq_federation_collector.
rabbitmq_federation_links gauge metric with status lable.
- Loading branch information
1 parent
72b2506
commit d94258f
Showing
9 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_federation_collector.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
%% This Source Code Form is subject to the terms of the Mozilla Public | ||
%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%% | ||
%% Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
%% | ||
-module(prometheus_rabbitmq_federation_collector). | ||
-export([deregister_cleanup/1, | ||
collect_mf/2]). | ||
|
||
-import(prometheus_model_helpers, [create_mf/4]). | ||
|
||
-behaviour(prometheus_collector). | ||
|
||
-define(METRICS, [{rabbitmq_federation_links, gauge, | ||
"Current number of federation links."}, | ||
]). | ||
|
||
%% API exports | ||
-export([]). | ||
|
||
%%==================================================================== | ||
%% Collector API | ||
%%==================================================================== | ||
|
||
deregister_cleanup(_) -> ok. | ||
|
||
collect_mf(_Registry, Callback) -> | ||
Status = rabbit_federation_status:status(500), | ||
StatusGroups = lists:foldl(fun(S, Acc) -> | ||
%% note Init value set to 1 because if status seen first time | ||
%% update with will take Init and put into Acc, wuthout calling fun | ||
maps:update_with(proplists:get_value(status, S), fun(C) -> C + 1 end, 1, Acc) | ||
end, #{}, Status), | ||
Metrics = [{rabbitmq_federation_links, gauge, "Current number of federation links.", | ||
[{[{status, S}], C} || {S, C} <- maps:to_list(StatusGroups)]}], | ||
[add_metric_family(Metric, Callback) || Metric <- Metrics], | ||
ok. | ||
|
||
add_metric_family({Name, Type, Help, Metrics}, Callback) -> | ||
Callback(create_mf(Name, Help, Type, Metrics)). | ||
|
||
%%==================================================================== | ||
%% Private Parts | ||
%%==================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
deps/rabbitmq_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
%% This Source Code Form is subject to the terms of the Mozilla Public | ||
%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%% | ||
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
%% | ||
|
||
-module(prometheus_rabbitmq_federation_collector_SUITE). | ||
|
||
-include_lib("common_test/include/ct.hrl"). | ||
-include_lib("amqp_client/include/amqp_client.hrl"). | ||
-include_lib("prometheus/include/prometheus_model.hrl"). | ||
|
||
-compile(export_all). | ||
|
||
-import(rabbit_federation_test_util, | ||
[expect/3, expect_empty/2, | ||
set_upstream/4, clear_upstream/3, set_upstream_set/4, | ||
set_policy/5, clear_policy/3, | ||
set_policy_upstream/5, set_policy_upstreams/4, | ||
no_plugins/1, with_ch/3, q/2]). | ||
|
||
all() -> | ||
[ | ||
{group, non_parallel_tests} | ||
]. | ||
|
||
groups() -> | ||
[ | ||
{non_parallel_tests, [], [ | ||
queue_status | ||
]} | ||
]. | ||
|
||
suite() -> | ||
[{timetrap, {minutes, 5}}]. | ||
|
||
%% ------------------------------------------------------------------- | ||
%% Testsuite setup/teardown. | ||
%% ------------------------------------------------------------------- | ||
init_per_suite(Config) -> | ||
rabbit_ct_helpers:log_environment(), | ||
Config1 = rabbit_ct_helpers:set_config(Config, [ | ||
{rmq_nodename_suffix, ?MODULE} | ||
]), | ||
rabbit_ct_helpers:run_setup_steps(Config1, | ||
rabbit_ct_broker_helpers:setup_steps() ++ | ||
rabbit_ct_client_helpers:setup_steps() ++ | ||
[fun rabbit_federation_test_util:setup_federation/1]). | ||
end_per_suite(Config) -> | ||
rabbit_ct_helpers:run_teardown_steps(Config, | ||
rabbit_ct_client_helpers:teardown_steps() ++ | ||
rabbit_ct_broker_helpers:teardown_steps()). | ||
|
||
init_per_group(_, Config) -> | ||
Config. | ||
|
||
end_per_group(_, Config) -> | ||
Config. | ||
|
||
init_per_testcase(Testcase, Config) -> | ||
rabbit_ct_helpers:testcase_started(Config, Testcase). | ||
|
||
end_per_testcase(Testcase, Config) -> | ||
rabbit_ct_helpers:testcase_finished(Config, Testcase). | ||
|
||
%% ------------------------------------------------------------------- | ||
%% Test cases | ||
%% ------------------------------------------------------------------- | ||
|
||
queue_status(Config) -> | ||
with_ch( | ||
Config, | ||
fun (_Ch) -> | ||
timer:sleep(3000), | ||
[Link] = rabbit_ct_broker_helpers:rpc(Config, 0, | ||
rabbit_federation_status, status, []), | ||
true = is_binary(proplists:get_value(id, Link)), | ||
MFs = rabbit_ct_broker_helpers:rpc(Config, 0, | ||
rabbitmq_prometheus_collector_test_proxy, collect_mf, | ||
[default, prometheus_rabbitmq_federation_collector]), | ||
[#'MetricFamily'{name = <<"rabbitmq_federation_links">>, | ||
help = "Current number of federation links.", | ||
type = 'GAUGE', | ||
metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, | ||
value = <<"running">>}], | ||
gauge = #'Gauge'{value = 1}}]}] = MFs | ||
end, upstream_downstream()). | ||
|
||
upstream_downstream() -> | ||
[q(<<"upstream">>, undefined), q(<<"fed.downstream">>, undefined)]. |
12 changes: 12 additions & 0 deletions
12
deps/rabbitmq_prometheus/test/rabbitmq_prometheus_collector_test_proxy.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-module(rabbitmq_prometheus_collector_test_proxy). | ||
|
||
-export([collect_mf/2]). | ||
|
||
-define(PD_KEY, metric_families). | ||
|
||
collect_mf(Registry, Collector) -> | ||
put(?PD_KEY, []), | ||
Collector:collect_mf(Registry, fun(MF) -> put(?PD_KEY, [MF | get(?PD_KEY)]) end), | ||
MFs = lists:reverse(get(?PD_KEY)), | ||
erase(?PD_KEY), | ||
MFs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters