Skip to content

Commit ed7e79c

Browse files
Rework shovel_prometheus and federation_prometheus plugins
to structure them like applications. This updates Bazel files but not yet Make ones.
1 parent 2766122 commit ed7e79c

14 files changed

+223
-86
lines changed

deps/rabbitmq_federation_prometheus/BUILD.bazel

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
load("@rules_erlang//:eunit2.bzl", "eunit")
22
load("@rules_erlang//:xref2.bzl", "xref")
33
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
4+
load("//:rabbitmq_home.bzl", "rabbitmq_home")
5+
load("//:rabbitmq_run.bzl", "rabbitmq_run")
46
load(
57
"//:rabbitmq.bzl",
8+
"BROKER_VERSION_REQUIREMENTS_ANY",
69
"RABBITMQ_DIALYZER_OPTS",
710
"assert_suites",
8-
"broker_for_integration_suites",
911
"rabbitmq_app",
1012
"rabbitmq_integration_suite",
1113
)
@@ -17,7 +19,9 @@ load(
1719
"test_suite_beam_files",
1820
)
1921

20-
# gazelle:erlang_always_generate_test_beam_files
22+
APP_NAME = "rabbitmq_federation_prometheus"
23+
24+
APP_DESCRIPTION = "Prometheus extension for the Federation plugin"
2125

2226
APP_ENV = """[
2327
]"""
@@ -41,15 +45,14 @@ rabbitmq_app(
4145
name = "erlang_app",
4246
srcs = [":all_srcs"],
4347
hdrs = [":public_hdrs"],
44-
app_description = "Exposes rabbitmq_federation metrics to Prometheus",
48+
app_description = APP_DESCRIPTION,
4549
app_env = APP_ENV,
46-
app_module = "rabbitmq_federation_prometheus",
47-
app_name = "rabbitmq_federation_prometheus",
48-
app_version = module_version(),
50+
app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY,
51+
app_module = "rabbit_federation_prometheus_app",
52+
app_name = APP_NAME,
4953
beam_files = [":beam_files"],
5054
extra_apps = [
5155
"crypto",
52-
"rabbit_common",
5356
],
5457
license_files = [":license_files"],
5558
priv = [":priv"],
@@ -60,12 +63,6 @@ rabbitmq_app(
6063
],
6164
)
6265

63-
alias(
64-
name = "rabbitmq_federation_prometheus",
65-
actual = ":erlang_app",
66-
visibility = ["//visibility:public"],
67-
)
68-
6966
xref(
7067
name = "xref",
7168
target = ":erlang_app",
@@ -75,9 +72,8 @@ plt(
7572
name = "deps_plt",
7673
for_target = ":erlang_app",
7774
ignore_warnings = True,
78-
libs = ["//deps/rabbitmq_cli:elixir"], # keep
75+
libs = ["@rules_elixir//elixir"], # keep
7976
plt = "//:base_plt",
80-
deps = ["//deps/rabbitmq_cli:erlang_app"], # keep
8177
)
8278

8379
dialyze(
@@ -87,7 +83,23 @@ dialyze(
8783
target = ":erlang_app",
8884
)
8985

90-
broker_for_integration_suites()
86+
eunit(
87+
name = "eunit",
88+
target = ":test_erlang_app",
89+
)
90+
91+
rabbitmq_home(
92+
name = "broker-for-tests-home",
93+
plugins = [
94+
"//deps/rabbit:erlang_app",
95+
":erlang_app",
96+
],
97+
)
98+
99+
rabbitmq_run(
100+
name = "rabbitmq-for-tests-run",
101+
home = ":broker-for-tests-home",
102+
)
91103

92104
rabbitmq_integration_suite(
93105
name = "prometheus_rabbitmq_federation_collector_SUITE",
@@ -98,7 +110,8 @@ rabbitmq_integration_suite(
98110

99111
assert_suites()
100112

101-
eunit(
102-
name = "eunit",
103-
target = ":test_erlang_app",
113+
alias(
114+
name = "rabbitmq_federation_prometheus",
115+
actual = ":erlang_app",
116+
visibility = ["//visibility:public"],
104117
)

deps/rabbitmq_federation_prometheus/app.bzl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ def all_beam_files(name = "all_beam_files"):
88
)
99
erlang_bytecode(
1010
name = "other_beam",
11-
srcs = ["src/rabbitmq_federation_prometheus.erl"],
11+
srcs = [
12+
"src/rabbit_federation_prometheus_app.erl",
13+
"src/rabbit_federation_prometheus_collector.erl",
14+
"src/rabbit_federation_prometheus_sup.erl",
15+
],
1216
hdrs = [":public_and_private_hdrs"],
1317
app_name = "rabbitmq_federation_prometheus",
1418
dest = "ebin",
@@ -32,7 +36,11 @@ def all_srcs(name = "all_srcs"):
3236

3337
filegroup(
3438
name = "srcs",
35-
srcs = ["src/rabbitmq_federation_prometheus.erl"],
39+
srcs = [
40+
"src/rabbit_federation_prometheus_app.erl",
41+
"src/rabbit_federation_prometheus_collector.erl",
42+
"src/rabbit_federation_prometheus_sup.erl",
43+
],
3644
)
3745
filegroup(
3846
name = "private_hdrs",
@@ -57,7 +65,11 @@ def all_test_beam_files(name = "all_test_beam_files"):
5765
erlang_bytecode(
5866
name = "test_other_beam",
5967
testonly = True,
60-
srcs = ["src/rabbitmq_federation_prometheus.erl"],
68+
srcs = [
69+
"src/rabbit_federation_prometheus_app.erl",
70+
"src/rabbit_federation_prometheus_collector.erl",
71+
"src/rabbit_federation_prometheus_sup.erl",
72+
],
6173
hdrs = [":public_and_private_hdrs"],
6274
app_name = "rabbitmq_federation_prometheus",
6375
dest = "test",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
-module(rabbit_federation_prometheus_app).
8+
9+
-behavior(application).
10+
11+
-export([start/0, stop/0, start/2, stop/1]).
12+
13+
start(normal, []) ->
14+
{ok, _} = application:ensure_all_started(prometheus),
15+
_ = rabbit_federation_prometheus_collector:start(),
16+
rabbit_federation_prometheus_sup:start_link().
17+
18+
stop(_State) ->
19+
_ = rabbit_federation_prometheus_collector:stop(),
20+
ok.
21+
22+
23+
start() ->
24+
_ = rabbit_federation_prometheus_collector:start().
25+
26+
stop() -> ok.
27+

deps/rabbitmq_federation_prometheus/src/rabbitmq_federation_prometheus.erl renamed to deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_collector.erl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22
%% License, v. 2.0. If a copy of the MPL was not distributed with this
33
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
%%
5-
%% Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66
%%
7-
-module(rabbitmq_federation_prometheus).
7+
-module(rabbit_federation_prometheus_collector).
8+
9+
-behaviour(prometheus_collector).
10+
11+
-export([start/0, stop/0]).
812
-export([deregister_cleanup/1,
913
collect_mf/2]).
1014

1115
-import(prometheus_model_helpers, [create_mf/4]).
1216

13-
-behaviour(prometheus_collector).
14-
15-
-rabbit_boot_step({?MODULE, [
16-
{description, "rabbitmq_federation prometheus collector plugin"},
17-
{mfa, {?MODULE, start, []}},
18-
{cleanup, {?MODULE, stop, []}}
19-
]}).
20-
21-
%% API exports
22-
-export([start/0, stop/0]).
17+
%%====================================================================
18+
%% Collector API
19+
%%====================================================================
2320

2421
start() ->
2522
{ok, _} = application:ensure_all_started(prometheus),
@@ -41,7 +38,7 @@ collect_mf(_Registry, Callback) ->
4138
%% update with will take Init and put into Acc, wuthout calling fun
4239
maps:update_with(proplists:get_value(status, S), fun(C) -> C + 1 end, 1, Acc)
4340
end, #{}, Status),
44-
Metrics = [{rabbitmq_federation_links, gauge, "Current number of federation links",
41+
Metrics = [{rabbitmq_federation_links, gauge, "Number of federation links",
4542
[{[{status, S}], C} || {S, C} <- maps:to_list(StatusGroups)]}],
4643
_ = [add_metric_family(Metric, Callback) || Metric <- Metrics],
4744
ok.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
-module(rabbit_federation_prometheus_sup).
8+
9+
-behaviour(supervisor).
10+
11+
-export([start_link/0]).
12+
-export([init/1]).
13+
14+
start_link() ->
15+
supervisor:start_link(?MODULE, []).
16+
17+
init(_Args) ->
18+
SupFlags = #{strategy => one_for_one, intensity => 1, period => 5},
19+
ChildSpecs = [],
20+
{ok, {SupFlags, ChildSpecs}}.

deps/rabbitmq_federation_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
-compile(export_all).
1515

1616
-define(ONE_RUNNING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>,
17-
help = "Current number of federation links",
17+
help = "Number of federation links",
1818
type = 'GAUGE',
1919
metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>,
2020
value = <<"running">>}],
2121
gauge = #'Gauge'{value = 1}}]}).
2222

2323
-define(TWO_RUNNING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>,
24-
help = "Current number of federation links",
24+
help = "Number of federation links",
2525
type = 'GAUGE',
2626
metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>,
2727
value = <<"running">>}],
2828
gauge = #'Gauge'{value = 2}}]}).
2929

3030
-define(ONE_RUNNING_ONE_STARTING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>,
31-
help = "Current number of federation links",
31+
help = "Number of federation links",
3232
type = 'GAUGE',
3333
metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>,
3434
value = <<"running">>}],
@@ -142,7 +142,7 @@ upstream_downstream() ->
142142
get_metrics(Config) ->
143143
rabbit_ct_broker_helpers:rpc(Config, 0,
144144
?MODULE, collect_mf,
145-
[default, rabbitmq_federation_prometheus]).
145+
[default, rabbit_federation_prometheus_collector]).
146146

147147

148148

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
load("@rules_erlang//:eunit2.bzl", "eunit")
22
load("@rules_erlang//:xref2.bzl", "xref")
33
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
4+
load("//:rabbitmq_home.bzl", "rabbitmq_home")
5+
load("//:rabbitmq_run.bzl", "rabbitmq_run")
46
load(
57
"//:rabbitmq.bzl",
8+
"BROKER_VERSION_REQUIREMENTS_ANY",
69
"RABBITMQ_DIALYZER_OPTS",
710
"assert_suites",
8-
"broker_for_integration_suites",
911
"rabbitmq_app",
1012
"rabbitmq_integration_suite",
1113
)
@@ -17,7 +19,9 @@ load(
1719
"test_suite_beam_files",
1820
)
1921

20-
# gazelle:erlang_always_generate_test_beam_files
22+
APP_NAME = "rabbitmq_shovel_prometheus"
23+
24+
APP_DESCRIPTION = "Prometheus extension for the Shovel plugin"
2125

2226
APP_ENV = """[
2327
]"""
@@ -31,25 +35,22 @@ all_test_beam_files(name = "all_test_beam_files")
3135
test_suite_beam_files(name = "test_suite_beam_files")
3236

3337
# gazelle:erlang_app_extra_app crypto
34-
3538
# gazelle:erlang_app_dep rabbit
3639
# gazelle:erlang_app_dep rabbitmq_prometheus
37-
3840
# gazelle:erlang_app_dep_exclude prometheus
3941

4042
rabbitmq_app(
4143
name = "erlang_app",
4244
srcs = [":all_srcs"],
4345
hdrs = [":public_hdrs"],
44-
app_description = "Exposes rabbitmq_shovel metrics to Prometheus",
46+
app_description = APP_DESCRIPTION,
4547
app_env = APP_ENV,
46-
app_module = "rabbitmq_shovel_prometheus",
47-
app_name = "rabbitmq_shovel_prometheus",
48-
app_version = module_version(),
48+
app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY,
49+
app_module = "rabbit_shovel_prometheus_app",
50+
app_name = APP_NAME,
4951
beam_files = [":beam_files"],
5052
extra_apps = [
5153
"crypto",
52-
"rabbit_common",
5354
],
5455
license_files = [":license_files"],
5556
priv = [":priv"],
@@ -60,12 +61,6 @@ rabbitmq_app(
6061
],
6162
)
6263

63-
alias(
64-
name = "rabbitmq_shovel_prometheus",
65-
actual = ":erlang_app",
66-
visibility = ["//visibility:public"],
67-
)
68-
6964
xref(
7065
name = "xref",
7166
target = ":erlang_app",
@@ -75,9 +70,8 @@ plt(
7570
name = "deps_plt",
7671
for_target = ":erlang_app",
7772
ignore_warnings = True,
78-
libs = ["//deps/rabbitmq_cli:elixir"], # keep
73+
libs = ["@rules_elixir//elixir"], # keep
7974
plt = "//:base_plt",
80-
deps = ["//deps/rabbitmq_cli:erlang_app"], # keep
8175
)
8276

8377
dialyze(
@@ -87,7 +81,23 @@ dialyze(
8781
target = ":erlang_app",
8882
)
8983

90-
broker_for_integration_suites()
84+
eunit(
85+
name = "eunit",
86+
target = ":test_erlang_app",
87+
)
88+
89+
rabbitmq_home(
90+
name = "broker-for-tests-home",
91+
plugins = [
92+
"//deps/rabbit:erlang_app",
93+
":erlang_app",
94+
],
95+
)
96+
97+
rabbitmq_run(
98+
name = "rabbitmq-for-tests-run",
99+
home = ":broker-for-tests-home",
100+
)
91101

92102
rabbitmq_integration_suite(
93103
name = "prometheus_rabbitmq_shovel_collector_SUITE",
@@ -98,7 +108,8 @@ rabbitmq_integration_suite(
98108

99109
assert_suites()
100110

101-
eunit(
102-
name = "eunit",
103-
target = ":test_erlang_app",
111+
alias(
112+
name = "rabbitmq_shovel_prometheus",
113+
actual = ":erlang_app",
114+
visibility = ["//visibility:public"],
104115
)

0 commit comments

Comments
 (0)