diff --git a/.github/workflows/templates/test-mixed-versions.template.yaml b/.github/workflows/templates/test-mixed-versions.template.yaml index f8aac9e915cc..5191c9fdbf64 100644 --- a/.github/workflows/templates/test-mixed-versions.template.yaml +++ b/.github/workflows/templates/test-mixed-versions.template.yaml @@ -23,11 +23,8 @@ on: push: branches: - main - - v3.12.x - - v3.11.x - - v3.10.x - - v3.9.x - - v3.8.x + - v4.0.x + - v3.13.x - bump-otp-* - bump-elixir-* - bump-rbe-* diff --git a/.github/workflows/test-mixed-versions.yaml b/.github/workflows/test-mixed-versions.yaml index 9dc2d0f22458..4b03199c0cdf 100644 --- a/.github/workflows/test-mixed-versions.yaml +++ b/.github/workflows/test-mixed-versions.yaml @@ -3,11 +3,8 @@ on: push: branches: - main - - v3.12.x - - v3.11.x - - v3.10.x - - v3.9.x - - v3.8.x + - v4.0.x + - v3.13.x - bump-otp-* - bump-elixir-* - bump-rbe-* @@ -617,6 +614,24 @@ jobs: repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} plugin: rabbitmq_federation_management secrets: inherit + test-rabbitmq_federation_prometheus-mixed: + needs: + - check-workflow + - test-rabbit-0-mixed + - test-rabbit-1-mixed + - test-rabbit-2-mixed + - test-rabbit-3-mixed + - test-rabbit-4-mixed + - test-rabbit-5-mixed + - test-rabbit-6-mixed + - test-rabbit-7-mixed + - test-rabbit-8-mixed + - test-rabbit-9-mixed + uses: ./.github/workflows/test-plugin-mixed.yaml + with: + repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} + plugin: rabbitmq_federation_prometheus + secrets: inherit test-rabbitmq_jms_topic_exchange-mixed: needs: - check-workflow @@ -905,6 +920,24 @@ jobs: repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} plugin: rabbitmq_shovel_management secrets: inherit + test-rabbitmq_shovel_prometheus-mixed: + needs: + - check-workflow + - test-rabbit-0-mixed + - test-rabbit-1-mixed + - test-rabbit-2-mixed + - test-rabbit-3-mixed + - test-rabbit-4-mixed + - test-rabbit-5-mixed + - test-rabbit-6-mixed + - test-rabbit-7-mixed + - test-rabbit-8-mixed + - test-rabbit-9-mixed + uses: ./.github/workflows/test-plugin-mixed.yaml + with: + repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} + plugin: rabbitmq_shovel_prometheus + secrets: inherit test-rabbitmq_stomp-mixed: needs: - check-workflow @@ -1126,6 +1159,7 @@ jobs: - test-rabbitmq_event_exchange-mixed - test-rabbitmq_federation-mixed - test-rabbitmq_federation_management-mixed + - test-rabbitmq_federation_prometheus-mixed - test-rabbitmq_jms_topic_exchange-mixed - test-rabbitmq_management-mixed - test-rabbitmq_management_agent-mixed @@ -1142,6 +1176,7 @@ jobs: - test-rabbitmq_sharding-mixed - test-rabbitmq_shovel-mixed - test-rabbitmq_shovel_management-mixed + - test-rabbitmq_shovel_prometheus-mixed - test-rabbitmq_stomp-mixed - test-rabbitmq_stream-mixed - test-rabbitmq_stream_management-mixed diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d4e313fa8f42..c1a8dfa57b78 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -554,6 +554,24 @@ jobs: repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} plugin: rabbitmq_federation_management secrets: inherit + test-rabbitmq_federation_prometheus: + needs: + - check-workflow + - test-rabbit-0 + - test-rabbit-1 + - test-rabbit-2 + - test-rabbit-3 + - test-rabbit-4 + - test-rabbit-5 + - test-rabbit-6 + - test-rabbit-7 + - test-rabbit-8 + - test-rabbit-9 + uses: ./.github/workflows/test-plugin.yaml + with: + repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} + plugin: rabbitmq_federation_prometheus + secrets: inherit test-rabbitmq_jms_topic_exchange: needs: - check-workflow @@ -842,6 +860,24 @@ jobs: repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} plugin: rabbitmq_shovel_management secrets: inherit + test-rabbitmq_shovel_prometheus: + needs: + - check-workflow + - test-rabbit-0 + - test-rabbit-1 + - test-rabbit-2 + - test-rabbit-3 + - test-rabbit-4 + - test-rabbit-5 + - test-rabbit-6 + - test-rabbit-7 + - test-rabbit-8 + - test-rabbit-9 + uses: ./.github/workflows/test-plugin.yaml + with: + repo_cache_key: ${{ needs.check-workflow.outputs.repo_cache_key }} + plugin: rabbitmq_shovel_prometheus + secrets: inherit test-rabbitmq_stomp: needs: - check-workflow @@ -1063,6 +1099,7 @@ jobs: - test-rabbitmq_event_exchange - test-rabbitmq_federation - test-rabbitmq_federation_management + - test-rabbitmq_federation_prometheus - test-rabbitmq_jms_topic_exchange - test-rabbitmq_management - test-rabbitmq_management_agent @@ -1079,6 +1116,7 @@ jobs: - test-rabbitmq_sharding - test-rabbitmq_shovel - test-rabbitmq_shovel_management + - test-rabbitmq_shovel_prometheus - test-rabbitmq_stomp - test-rabbitmq_stream - test-rabbitmq_stream_management diff --git a/.gitignore b/.gitignore index f5c68fc329d8..1bc1578cb1d2 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ elvis !/deps/rabbitmq_event_exchange/ !/deps/rabbitmq_federation/ !/deps/rabbitmq_federation_management/ +!/deps/rabbitmq_federation_prometheus/ !/deps/rabbitmq_jms_topic_exchange/ !/deps/rabbitmq_management/ !/deps/rabbitmq_management_agent/ @@ -64,6 +65,7 @@ elvis !/deps/rabbitmq_sharding/ !/deps/rabbitmq_shovel/ !/deps/rabbitmq_shovel_management/ +!/deps/rabbitmq_shovel_prometheus/ !/deps/rabbitmq_stomp/ !/deps/rabbitmq_stream/ !/deps/rabbitmq_stream_common/ diff --git a/Makefile b/Makefile index d5409a22ed27..ffa5da854e24 100644 --- a/Makefile +++ b/Makefile @@ -594,6 +594,7 @@ TIER1_PLUGINS := \ rabbitmq_event_exchange \ rabbitmq_federation \ rabbitmq_federation_management \ + rabbitmq_federation_prometheus \ rabbitmq_jms_topic_exchange \ rabbitmq_management \ rabbitmq_management_agent \ @@ -610,6 +611,7 @@ TIER1_PLUGINS := \ rabbitmq_sharding \ rabbitmq_shovel \ rabbitmq_shovel_management \ + rabbitmq_shovel_prometheus \ rabbitmq_stomp \ rabbitmq_stream \ rabbitmq_stream_management \ diff --git a/deps/rabbitmq_federation_prometheus/BUILD.bazel b/deps/rabbitmq_federation_prometheus/BUILD.bazel new file mode 100644 index 000000000000..b6a8c641f149 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/BUILD.bazel @@ -0,0 +1,117 @@ +load("@rules_erlang//:eunit2.bzl", "eunit") +load("@rules_erlang//:xref2.bzl", "xref") +load("@rules_erlang//:dialyze.bzl", "dialyze", "plt") +load("//:rabbitmq_home.bzl", "rabbitmq_home") +load("//:rabbitmq_run.bzl", "rabbitmq_run") +load( + "//:rabbitmq.bzl", + "BROKER_VERSION_REQUIREMENTS_ANY", + "RABBITMQ_DIALYZER_OPTS", + "assert_suites", + "rabbitmq_app", + "rabbitmq_integration_suite", +) +load( + ":app.bzl", + "all_beam_files", + "all_srcs", + "all_test_beam_files", + "test_suite_beam_files", +) + +APP_NAME = "rabbitmq_federation_prometheus" + +APP_DESCRIPTION = "Prometheus extension for the Federation plugin" + +APP_ENV = """[ +]""" + +all_srcs(name = "all_srcs") + +all_beam_files(name = "all_beam_files") + +all_test_beam_files(name = "all_test_beam_files") + +test_suite_beam_files(name = "test_suite_beam_files") + +# gazelle:erlang_app_extra_app crypto + +# gazelle:erlang_app_dep rabbit +# gazelle:erlang_app_dep rabbitmq_prometheus + +# gazelle:erlang_app_dep_exclude prometheus + +rabbitmq_app( + name = "erlang_app", + srcs = [":all_srcs"], + hdrs = [":public_hdrs"], + app_description = APP_DESCRIPTION, + app_env = APP_ENV, + app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY, + app_module = "rabbit_federation_prometheus_app", + app_name = APP_NAME, + beam_files = [":beam_files"], + extra_apps = [ + "crypto", + ], + license_files = [":license_files"], + priv = [":priv"], + deps = [ + "//deps/rabbit:erlang_app", + "//deps/rabbitmq_federation:erlang_app", + "//deps/rabbitmq_prometheus:erlang_app", + ], +) + +xref( + name = "xref", + target = ":erlang_app", +) + +plt( + name = "deps_plt", + for_target = ":erlang_app", + ignore_warnings = True, + libs = ["@rules_elixir//elixir"], # keep + plt = "//:base_plt", +) + +dialyze( + name = "dialyze", + dialyzer_opts = RABBITMQ_DIALYZER_OPTS, + plt = ":deps_plt", + target = ":erlang_app", +) + +eunit( + name = "eunit", + target = ":test_erlang_app", +) + +rabbitmq_home( + name = "broker-for-tests-home", + plugins = [ + "//deps/rabbit:erlang_app", + ":erlang_app", + ], +) + +rabbitmq_run( + name = "rabbitmq-for-tests-run", + home = ":broker-for-tests-home", +) + +rabbitmq_integration_suite( + name = "prometheus_rabbitmq_federation_collector_SUITE", + size = "small", + additional_beam = [ + ], +) + +assert_suites() + +alias( + name = "rabbitmq_federation_prometheus", + actual = ":erlang_app", + visibility = ["//visibility:public"], +) diff --git a/deps/rabbitmq_federation_prometheus/CODE_OF_CONDUCT.md b/deps/rabbitmq_federation_prometheus/CODE_OF_CONDUCT.md new file mode 120000 index 000000000000..a3613c99f0b0 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +../../CODE_OF_CONDUCT.md \ No newline at end of file diff --git a/deps/rabbitmq_federation_prometheus/CONTRIBUTING.md b/deps/rabbitmq_federation_prometheus/CONTRIBUTING.md new file mode 120000 index 000000000000..f939e75f21a8 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/CONTRIBUTING.md @@ -0,0 +1 @@ +../../CONTRIBUTING.md \ No newline at end of file diff --git a/deps/rabbitmq_federation_prometheus/LICENSE b/deps/rabbitmq_federation_prometheus/LICENSE new file mode 100644 index 000000000000..46e08bb41d0b --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/LICENSE @@ -0,0 +1 @@ +This package is licensed under the MPL 2.0. For the MPL 2.0, please see LICENSE-MPL-RabbitMQ. \ No newline at end of file diff --git a/deps/rabbitmq_federation_prometheus/LICENSE-MPL-RabbitMQ b/deps/rabbitmq_federation_prometheus/LICENSE-MPL-RabbitMQ new file mode 100644 index 000000000000..14e2f777f6c3 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/LICENSE-MPL-RabbitMQ @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + 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 http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/deps/rabbitmq_federation_prometheus/Makefile b/deps/rabbitmq_federation_prometheus/Makefile new file mode 100644 index 000000000000..3d069be8ed41 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/Makefile @@ -0,0 +1,16 @@ +PROJECT = rabbitmq_federation_prometheus +PROJECT_DESCRIPTION = Exposes rabbitmq_federation metrics to Prometheus +PROJECT_MOD = rabbit_federation_prometheus_app + +define PROJECT_APP_EXTRA_KEYS + {broker_version_requirements, []} +endef + +DEPS = rabbit_common rabbit rabbitmq_federation rabbitmq_prometheus +TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers eunit_formatters + +DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk +DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk + +include ../../rabbitmq-components.mk +include ../../erlang.mk diff --git a/deps/rabbitmq_federation_prometheus/README.md b/deps/rabbitmq_federation_prometheus/README.md new file mode 100644 index 000000000000..2651c440499b --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/README.md @@ -0,0 +1,16 @@ +# RabbitMQ Federation Prometheus + +This plugin adds Federation metrics to prometheus + +## Installation + +This plugin ships with RabbitMQ. Like all other plugins, it must be enabled +before it can be used: + +```bash +[sudo] rabbitmq-plugins enable rabbitmq_federation_prometheus +``` + +## License + +See [LICENSE](./LICENSE). diff --git a/deps/rabbitmq_federation_prometheus/app.bzl b/deps/rabbitmq_federation_prometheus/app.bzl new file mode 100644 index 000000000000..405196d21119 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/app.bzl @@ -0,0 +1,89 @@ +load("@rules_erlang//:erlang_bytecode2.bzl", "erlang_bytecode") +load("@rules_erlang//:filegroup.bzl", "filegroup") + +def all_beam_files(name = "all_beam_files"): + filegroup( + name = "beam_files", + srcs = [":other_beam"], + ) + erlang_bytecode( + name = "other_beam", + srcs = [ + "src/rabbit_federation_prometheus_app.erl", + "src/rabbit_federation_prometheus_collector.erl", + "src/rabbit_federation_prometheus_sup.erl", + ], + hdrs = [":public_and_private_hdrs"], + app_name = "rabbitmq_federation_prometheus", + dest = "ebin", + erlc_opts = "//:erlc_opts", + deps = ["@prometheus//:erlang_app"], + ) + +def all_srcs(name = "all_srcs"): + filegroup( + name = "all_srcs", + srcs = [":public_and_private_hdrs", ":srcs"], + ) + filegroup( + name = "public_and_private_hdrs", + srcs = [":private_hdrs", ":public_hdrs"], + ) + + filegroup( + name = "priv", + ) + + filegroup( + name = "srcs", + srcs = [ + "src/rabbit_federation_prometheus_app.erl", + "src/rabbit_federation_prometheus_collector.erl", + "src/rabbit_federation_prometheus_sup.erl", + ], + ) + filegroup( + name = "private_hdrs", + ) + filegroup( + name = "public_hdrs", + ) + filegroup( + name = "license_files", + srcs = [ + "LICENSE", + "LICENSE-MPL-RabbitMQ", + ], + ) + +def all_test_beam_files(name = "all_test_beam_files"): + filegroup( + name = "test_beam_files", + testonly = True, + srcs = [":test_other_beam"], + ) + erlang_bytecode( + name = "test_other_beam", + testonly = True, + srcs = [ + "src/rabbit_federation_prometheus_app.erl", + "src/rabbit_federation_prometheus_collector.erl", + "src/rabbit_federation_prometheus_sup.erl", + ], + hdrs = [":public_and_private_hdrs"], + app_name = "rabbitmq_federation_prometheus", + dest = "test", + erlc_opts = "//:test_erlc_opts", + deps = ["@prometheus//:erlang_app"], + ) + +def test_suite_beam_files(name = "test_suite_beam_files"): + erlang_bytecode( + name = "prometheus_rabbitmq_federation_collector_SUITE_beam_files", + testonly = True, + srcs = ["test/prometheus_rabbitmq_federation_collector_SUITE.erl"], + outs = ["test/prometheus_rabbitmq_federation_collector_SUITE.beam"], + app_name = "rabbitmq_federation_prometheus", + erlc_opts = "//:test_erlc_opts", + deps = ["//deps/amqp_client:erlang_app", "@prometheus//:erlang_app"], + ) diff --git a/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_app.erl b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_app.erl new file mode 100644 index 000000000000..fda59b4620e8 --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_app.erl @@ -0,0 +1,27 @@ +%% 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(rabbit_federation_prometheus_app). + +-behavior(application). + +-export([start/0, stop/0, start/2, stop/1]). + +start(normal, []) -> + {ok, _} = application:ensure_all_started(prometheus), + _ = rabbit_federation_prometheus_collector:start(), + rabbit_federation_prometheus_sup:start_link(). + +stop(_State) -> + _ = rabbit_federation_prometheus_collector:stop(), + ok. + + +start() -> + _ = rabbit_federation_prometheus_collector:start(). + +stop() -> ok. + diff --git a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_federation_collector.erl b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_collector.erl similarity index 73% rename from deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_federation_collector.erl rename to deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_collector.erl index c00209177d38..12db4594ddac 100644 --- a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_federation_collector.erl +++ b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_collector.erl @@ -2,22 +2,28 @@ %% 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. +%% 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). +-module(rabbit_federation_prometheus_collector). + +-behaviour(prometheus_collector). + +-export([start/0, stop/0]). -export([deregister_cleanup/1, collect_mf/2]). -import(prometheus_model_helpers, [create_mf/4]). --behaviour(prometheus_collector). +%%==================================================================== +%% Collector API +%%==================================================================== --define(METRICS, [{rabbitmq_federation_links, gauge, - "Current number of federation links."}, - ]). +start() -> + {ok, _} = application:ensure_all_started(prometheus), + prometheus_registry:register_collector(?MODULE). -%% API exports --export([]). +stop() -> + prometheus_registry:deregister_collector(?MODULE). %%==================================================================== %% Collector API @@ -32,7 +38,7 @@ collect_mf(_Registry, Callback) -> %% 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.", + Metrics = [{rabbitmq_federation_links, gauge, "Number of federation links", [{[{status, S}], C} || {S, C} <- maps:to_list(StatusGroups)]}], _ = [add_metric_family(Metric, Callback) || Metric <- Metrics], ok. diff --git a/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_sup.erl b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_sup.erl new file mode 100644 index 000000000000..e9106c29b31f --- /dev/null +++ b/deps/rabbitmq_federation_prometheus/src/rabbit_federation_prometheus_sup.erl @@ -0,0 +1,20 @@ +%% 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(rabbit_federation_prometheus_sup). + +-behaviour(supervisor). + +-export([start_link/0]). +-export([init/1]). + +start_link() -> + supervisor:start_link(?MODULE, []). + +init(_Args) -> + SupFlags = #{strategy => one_for_one, intensity => 1, period => 5}, + ChildSpecs = [], + {ok, {SupFlags, ChildSpecs}}. diff --git a/deps/rabbitmq_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl b/deps/rabbitmq_federation_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl similarity index 55% rename from deps/rabbitmq_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl rename to deps/rabbitmq_federation_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl index e379d1a47b87..5a15a0ffb4d9 100644 --- a/deps/rabbitmq_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl +++ b/deps/rabbitmq_federation_prometheus/test/prometheus_rabbitmq_federation_collector_SUITE.erl @@ -14,21 +14,21 @@ -compile(export_all). -define(ONE_RUNNING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>, - help = "Current number of federation links.", + help = "Number of federation links", type = 'GAUGE', metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, value = <<"running">>}], gauge = #'Gauge'{value = 1}}]}). -define(TWO_RUNNING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>, - help = "Current number of federation links.", + help = "Number of federation links", type = 'GAUGE', metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, value = <<"running">>}], gauge = #'Gauge'{value = 2}}]}). -define(ONE_RUNNING_ONE_STARTING_METRIC, #'MetricFamily'{name = <<"rabbitmq_federation_links">>, - help = "Current number of federation links.", + help = "Number of federation links", type = 'GAUGE', metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, value = <<"running">>}], @@ -37,12 +37,6 @@ value = <<"starting">>}], gauge = #'Gauge'{value = 1}}]}). --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, maybe_declare_queue/3, delete_all/2]). all() -> [ @@ -71,7 +65,7 @@ init_per_suite(Config) -> 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]). + [fun setup_federation/1]). end_per_suite(Config) -> rabbit_ct_helpers:run_teardown_steps(Config, rabbit_ct_client_helpers:teardown_steps() ++ @@ -120,7 +114,7 @@ single_link_then_second_added(Config) -> get_metrics(Config)), 500, 5) - + end, delete_all(Ch, [q(<<"fed.downstream2">>, [{<<"x-queue-type">>, longstr, <<"classic">>}])]) @@ -147,5 +141,163 @@ upstream_downstream() -> get_metrics(Config) -> rabbit_ct_broker_helpers:rpc(Config, 0, - rabbitmq_prometheus_collector_test_proxy, collect_mf, - [default, prometheus_rabbitmq_federation_collector]). + ?MODULE, collect_mf, + [default, rabbit_federation_prometheus_collector]). + + + + +setup_federation(Config) -> + setup_federation_with_upstream_params(Config, []). + +setup_federation_with_upstream_params(Config, ExtraParams) -> + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream">>, <<"localhost">>, [ + {<<"uri">>, rabbit_ct_broker_helpers:node_uri(Config, 0)}, + {<<"consumer-tag">>, <<"fed.tag">>} + ] ++ ExtraParams), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream">>, <<"local5673">>, [ + {<<"uri">>, <<"amqp://localhost:1">>} + ] ++ ExtraParams), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"upstream">>, [ + [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"upstream">>}, + {<<"queue">>, <<"upstream">>} + ] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"upstream2">>, [ + [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"upstream2">>}, + {<<"queue">>, <<"upstream2">>} + ] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"localhost">>, [ + [{<<"upstream">>, <<"localhost">>}] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"upstream12">>, [ + [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"upstream">>}, + {<<"queue">>, <<"upstream">>} + ], [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"upstream2">>}, + {<<"queue">>, <<"upstream2">>} + ] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"one">>, [ + [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"one">>}, + {<<"queue">>, <<"one">>} + ] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"two">>, [ + [ + {<<"upstream">>, <<"localhost">>}, + {<<"exchange">>, <<"two">>}, + {<<"queue">>, <<"two">>} + ] + ]), + + rabbit_ct_broker_helpers:set_parameter(Config, 0, + <<"federation-upstream-set">>, <<"upstream5673">>, [ + [ + {<<"upstream">>, <<"local5673">>}, + {<<"exchange">>, <<"upstream">>} + ] + ]), + + rabbit_ct_broker_helpers:rpc( + Config, 0, rabbit_policy, set, + [<<"/">>, <<"fed">>, <<"^fed\.">>, [{<<"federation-upstream-set">>, <<"upstream">>}], + 0, <<"all">>, <<"acting-user">>]), + + rabbit_ct_broker_helpers:rpc( + Config, 0, rabbit_policy, set, + [<<"/">>, <<"fed12">>, <<"^fed12\.">>, [{<<"federation-upstream-set">>, <<"upstream12">>}], + 2, <<"all">>, <<"acting-user">>]), + + rabbit_ct_broker_helpers:set_policy(Config, 0, + <<"one">>, <<"^two$">>, <<"all">>, [ + {<<"federation-upstream-set">>, <<"one">>}]), + + rabbit_ct_broker_helpers:set_policy(Config, 0, + <<"two">>, <<"^one$">>, <<"all">>, [ + {<<"federation-upstream-set">>, <<"two">>}]), + + rabbit_ct_broker_helpers:set_policy(Config, 0, + <<"hare">>, <<"^hare\.">>, <<"all">>, [ + {<<"federation-upstream-set">>, <<"upstream5673">>}]), + + rabbit_ct_broker_helpers:set_policy(Config, 0, + <<"all">>, <<"^all\.">>, <<"all">>, [ + {<<"federation-upstream-set">>, <<"all">>}]), + + rabbit_ct_broker_helpers:set_policy(Config, 0, + <<"new">>, <<"^new\.">>, <<"all">>, [ + {<<"federation-upstream-set">>, <<"new-set">>}]), + Config. + +with_ch(Config, Fun, Methods) -> + Ch = rabbit_ct_client_helpers:open_channel(Config), + declare_all(Config, Ch, Methods), + %% Clean up queues even after test failure. + try + Fun(Ch) + after + delete_all(Ch, Methods), + rabbit_ct_client_helpers:close_channel(Ch) + end, + ok. + +declare_all(Config, Ch, Methods) -> [maybe_declare_queue(Config, Ch, Op) || Op <- Methods]. +delete_all(Ch, Methods) -> + [delete_queue(Ch, Q) || #'queue.declare'{queue = Q} <- Methods]. + +maybe_declare_queue(Config, Ch, Method) -> + OneOffCh = rabbit_ct_client_helpers:open_channel(Config), + try + amqp_channel:call(OneOffCh, Method#'queue.declare'{passive = true}) + catch exit:{{shutdown, {server_initiated_close, ?NOT_FOUND, _Message}}, _} -> + amqp_channel:call(Ch, Method) + after + catch rabbit_ct_client_helpers:close_channel(OneOffCh) + end. + +delete_queue(Ch, Q) -> + amqp_channel:call(Ch, #'queue.delete'{queue = Q}). + +q(Name) -> + q(Name, []). + +q(Name, undefined) -> + q(Name, []); +q(Name, Args) -> + #'queue.declare'{queue = Name, + durable = true, + arguments = Args}. + +-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. diff --git a/deps/rabbitmq_prometheus/BUILD.bazel b/deps/rabbitmq_prometheus/BUILD.bazel index 6fe47b548007..b0d71c0cda52 100644 --- a/deps/rabbitmq_prometheus/BUILD.bazel +++ b/deps/rabbitmq_prometheus/BUILD.bazel @@ -52,9 +52,7 @@ rabbitmq_app( priv = [":priv"], deps = [ "//deps/rabbit:erlang_app", - "//deps/rabbitmq_federation:erlang_app", "//deps/rabbitmq_management_agent:erlang_app", - "//deps/rabbitmq_shovel:erlang_app", "//deps/rabbitmq_web_dispatch:erlang_app", "@accept//:erlang_app", "@cowboy//:erlang_app", @@ -100,23 +98,6 @@ rabbitmq_integration_suite( flaky = True, ) -rabbitmq_integration_suite( - name = "prometheus_rabbitmq_federation_collector_SUITE", - size = "small", - additional_beam = [ - "//deps/rabbitmq_federation:test/rabbit_federation_test_util.beam", #keep - "test/rabbitmq_prometheus_collector_test_proxy.beam", #keep - ], -) - -rabbitmq_integration_suite( - name = "prometheus_rabbitmq_shovel_collector_SUITE", - size = "small", - additional_beam = [ - "test/rabbitmq_prometheus_collector_test_proxy.beam", #keep - ], -) - assert_suites() alias( diff --git a/deps/rabbitmq_prometheus/Makefile b/deps/rabbitmq_prometheus/Makefile index ed16fd179ed0..8380e81b9a7b 100644 --- a/deps/rabbitmq_prometheus/Makefile +++ b/deps/rabbitmq_prometheus/Makefile @@ -9,7 +9,7 @@ endef PROJECT := rabbitmq_prometheus PROJECT_DESCRIPTION = Prometheus metrics for RabbitMQ PROJECT_MOD := rabbit_prometheus_app -DEPS = accept cowboy rabbit rabbitmq_management_agent prometheus rabbitmq_web_dispatch rabbitmq_federation rabbitmq_shovel +DEPS = accept cowboy rabbit rabbitmq_management_agent prometheus rabbitmq_web_dispatch BUILD_DEPS = amqp_client rabbit_common rabbitmq_management TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers eunit_formatters diff --git a/deps/rabbitmq_prometheus/app.bzl b/deps/rabbitmq_prometheus/app.bzl index ab46829628a5..a77dcbb9bb09 100644 --- a/deps/rabbitmq_prometheus/app.bzl +++ b/deps/rabbitmq_prometheus/app.bzl @@ -13,9 +13,7 @@ def all_beam_files(name = "all_beam_files"): "src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_core_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_dynamic_collector.erl", - "src/collectors/prometheus_rabbitmq_federation_collector.erl", "src/collectors/prometheus_rabbitmq_global_metrics_collector.erl", - "src/collectors/prometheus_rabbitmq_shovel_collector.erl", "src/rabbit_prometheus_app.erl", "src/rabbit_prometheus_dispatcher.erl", "src/rabbit_prometheus_handler.erl", @@ -45,9 +43,7 @@ def all_test_beam_files(name = "all_test_beam_files"): "src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_core_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_dynamic_collector.erl", - "src/collectors/prometheus_rabbitmq_federation_collector.erl", "src/collectors/prometheus_rabbitmq_global_metrics_collector.erl", - "src/collectors/prometheus_rabbitmq_shovel_collector.erl", "src/rabbit_prometheus_app.erl", "src/rabbit_prometheus_dispatcher.erl", "src/rabbit_prometheus_handler.erl", @@ -88,9 +84,7 @@ def all_srcs(name = "all_srcs"): "src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_core_metrics_collector.erl", "src/collectors/prometheus_rabbitmq_dynamic_collector.erl", - "src/collectors/prometheus_rabbitmq_federation_collector.erl", "src/collectors/prometheus_rabbitmq_global_metrics_collector.erl", - "src/collectors/prometheus_rabbitmq_shovel_collector.erl", "src/rabbit_prometheus_app.erl", "src/rabbit_prometheus_dispatcher.erl", "src/rabbit_prometheus_handler.erl", @@ -128,15 +122,7 @@ def test_suite_beam_files(name = "test_suite_beam_files"): "//deps/rabbitmq_ct_helpers:erlang_app", ], ) - erlang_bytecode( - name = "prometheus_rabbitmq_federation_collector_SUITE_beam_files", - testonly = True, - srcs = ["test/prometheus_rabbitmq_federation_collector_SUITE.erl"], - outs = ["test/prometheus_rabbitmq_federation_collector_SUITE.beam"], - app_name = "rabbitmq_prometheus", - erlc_opts = "//:test_erlc_opts", - deps = ["//deps/amqp_client:erlang_app", "@prometheus//:erlang_app"], - ) + erlang_bytecode( name = "rabbitmq_prometheus_collector_test_proxy_beam_files", testonly = True, @@ -145,12 +131,3 @@ def test_suite_beam_files(name = "test_suite_beam_files"): app_name = "rabbitmq_prometheus", erlc_opts = "//:test_erlc_opts", ) - erlang_bytecode( - name = "prometheus_rabbitmq_shovel_collector_SUITE_beam_files", - testonly = True, - srcs = ["test/prometheus_rabbitmq_shovel_collector_SUITE.erl"], - outs = ["test/prometheus_rabbitmq_shovel_collector_SUITE.beam"], - app_name = "rabbitmq_prometheus", - erlc_opts = "//:test_erlc_opts", - deps = ["//deps/amqp_client:erlang_app", "@prometheus//:erlang_app"], - ) diff --git a/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl b/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl index 9d2a4ce68d10..850494e00666 100644 --- a/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl +++ b/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl @@ -18,8 +18,6 @@ build_dispatcher() -> prometheus_rabbitmq_global_metrics_collector, prometheus_rabbitmq_alarm_metrics_collector, prometheus_rabbitmq_dynamic_collector, - prometheus_rabbitmq_federation_collector, - prometheus_rabbitmq_shovel_collector, prometheus_process_collector]), prometheus_registry:register_collectors('per-object', [ prometheus_vm_system_info_collector, diff --git a/deps/rabbitmq_shovel_prometheus/BUILD.bazel b/deps/rabbitmq_shovel_prometheus/BUILD.bazel new file mode 100644 index 000000000000..d34bd895525a --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/BUILD.bazel @@ -0,0 +1,115 @@ +load("@rules_erlang//:eunit2.bzl", "eunit") +load("@rules_erlang//:xref2.bzl", "xref") +load("@rules_erlang//:dialyze.bzl", "dialyze", "plt") +load("//:rabbitmq_home.bzl", "rabbitmq_home") +load("//:rabbitmq_run.bzl", "rabbitmq_run") +load( + "//:rabbitmq.bzl", + "BROKER_VERSION_REQUIREMENTS_ANY", + "RABBITMQ_DIALYZER_OPTS", + "assert_suites", + "rabbitmq_app", + "rabbitmq_integration_suite", +) +load( + ":app.bzl", + "all_beam_files", + "all_srcs", + "all_test_beam_files", + "test_suite_beam_files", +) + +APP_NAME = "rabbitmq_shovel_prometheus" + +APP_DESCRIPTION = "Prometheus extension for the Shovel plugin" + +APP_ENV = """[ +]""" + +all_srcs(name = "all_srcs") + +all_beam_files(name = "all_beam_files") + +all_test_beam_files(name = "all_test_beam_files") + +test_suite_beam_files(name = "test_suite_beam_files") + +# gazelle:erlang_app_extra_app crypto +# gazelle:erlang_app_dep rabbit +# gazelle:erlang_app_dep rabbitmq_prometheus +# gazelle:erlang_app_dep_exclude prometheus + +rabbitmq_app( + name = "erlang_app", + srcs = [":all_srcs"], + hdrs = [":public_hdrs"], + app_description = APP_DESCRIPTION, + app_env = APP_ENV, + app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY, + app_module = "rabbit_shovel_prometheus_app", + app_name = APP_NAME, + beam_files = [":beam_files"], + extra_apps = [ + "crypto", + ], + license_files = [":license_files"], + priv = [":priv"], + deps = [ + "//deps/rabbit:erlang_app", + "//deps/rabbitmq_prometheus:erlang_app", + "//deps/rabbitmq_shovel:erlang_app", + ], +) + +xref( + name = "xref", + target = ":erlang_app", +) + +plt( + name = "deps_plt", + for_target = ":erlang_app", + ignore_warnings = True, + libs = ["@rules_elixir//elixir"], # keep + plt = "//:base_plt", +) + +dialyze( + name = "dialyze", + dialyzer_opts = RABBITMQ_DIALYZER_OPTS, + plt = ":deps_plt", + target = ":erlang_app", +) + +eunit( + name = "eunit", + target = ":test_erlang_app", +) + +rabbitmq_home( + name = "broker-for-tests-home", + plugins = [ + "//deps/rabbit:erlang_app", + ":erlang_app", + ], +) + +rabbitmq_run( + name = "rabbitmq-for-tests-run", + home = ":broker-for-tests-home", +) + +rabbitmq_integration_suite( + name = "prometheus_rabbitmq_shovel_collector_SUITE", + size = "small", + additional_beam = [ + ], +) + +assert_suites() + +alias( + name = "rabbitmq_shovel_prometheus", + actual = ":erlang_app", + visibility = ["//visibility:public"], +) diff --git a/deps/rabbitmq_shovel_prometheus/CODE_OF_CONDUCT.md b/deps/rabbitmq_shovel_prometheus/CODE_OF_CONDUCT.md new file mode 120000 index 000000000000..a3613c99f0b0 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +../../CODE_OF_CONDUCT.md \ No newline at end of file diff --git a/deps/rabbitmq_shovel_prometheus/CONTRIBUTING.md b/deps/rabbitmq_shovel_prometheus/CONTRIBUTING.md new file mode 120000 index 000000000000..f939e75f21a8 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/CONTRIBUTING.md @@ -0,0 +1 @@ +../../CONTRIBUTING.md \ No newline at end of file diff --git a/deps/rabbitmq_shovel_prometheus/LICENSE b/deps/rabbitmq_shovel_prometheus/LICENSE new file mode 100644 index 000000000000..46e08bb41d0b --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/LICENSE @@ -0,0 +1 @@ +This package is licensed under the MPL 2.0. For the MPL 2.0, please see LICENSE-MPL-RabbitMQ. \ No newline at end of file diff --git a/deps/rabbitmq_shovel_prometheus/LICENSE-MPL-RabbitMQ b/deps/rabbitmq_shovel_prometheus/LICENSE-MPL-RabbitMQ new file mode 100644 index 000000000000..14e2f777f6c3 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/LICENSE-MPL-RabbitMQ @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + 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 http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/deps/rabbitmq_shovel_prometheus/Makefile b/deps/rabbitmq_shovel_prometheus/Makefile new file mode 100644 index 000000000000..f448bde8c6ca --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/Makefile @@ -0,0 +1,16 @@ +PROJECT = rabbitmq_shovel_prometheus +PROJECT_DESCRIPTION = Exposes rabbitmq_shovel metrics to Prometheus +PROJECT_MOD = rabbit_shovel_prometheus_app + +define PROJECT_APP_EXTRA_KEYS + {broker_version_requirements, []} +endef + +DEPS = rabbit_common rabbit rabbitmq_shovel rabbitmq_prometheus +TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers eunit_formatters + +DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk +DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk + +include ../../rabbitmq-components.mk +include ../../erlang.mk diff --git a/deps/rabbitmq_shovel_prometheus/README.md b/deps/rabbitmq_shovel_prometheus/README.md new file mode 100644 index 000000000000..0a1b6882f9e3 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/README.md @@ -0,0 +1,16 @@ +# RabbitMQ Shovel Prometheus + +This plugin adds Shovel metrics to prometheus + +## Installation + +This plugin ships with RabbitMQ. Like all other plugins, it must be enabled +before it can be used: + +```bash +[sudo] rabbitmq-plugins enable rabbitmq_shovel_prometheus +``` + +## License + +See [LICENSE](./LICENSE). diff --git a/deps/rabbitmq_shovel_prometheus/app.bzl b/deps/rabbitmq_shovel_prometheus/app.bzl new file mode 100644 index 000000000000..b79594dc27a4 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/app.bzl @@ -0,0 +1,89 @@ +load("@rules_erlang//:erlang_bytecode2.bzl", "erlang_bytecode") +load("@rules_erlang//:filegroup.bzl", "filegroup") + +def all_beam_files(name = "all_beam_files"): + filegroup( + name = "beam_files", + srcs = [":other_beam"], + ) + erlang_bytecode( + name = "other_beam", + srcs = [ + "src/rabbit_shovel_prometheus_app.erl", + "src/rabbit_shovel_prometheus_collector.erl", + "src/rabbit_shovel_prometheus_sup.erl", + ], + hdrs = [":public_and_private_hdrs"], + app_name = "rabbitmq_shovel_prometheus", + dest = "ebin", + erlc_opts = "//:erlc_opts", + deps = ["@prometheus//:erlang_app"], + ) + +def all_srcs(name = "all_srcs"): + filegroup( + name = "all_srcs", + srcs = [":public_and_private_hdrs", ":srcs"], + ) + filegroup( + name = "public_and_private_hdrs", + srcs = [":private_hdrs", ":public_hdrs"], + ) + + filegroup( + name = "priv", + ) + + filegroup( + name = "srcs", + srcs = [ + "src/rabbit_shovel_prometheus_app.erl", + "src/rabbit_shovel_prometheus_collector.erl", + "src/rabbit_shovel_prometheus_sup.erl", + ], + ) + filegroup( + name = "private_hdrs", + ) + filegroup( + name = "public_hdrs", + ) + filegroup( + name = "license_files", + srcs = [ + "LICENSE", + "LICENSE-MPL-RabbitMQ", + ], + ) + +def all_test_beam_files(name = "all_test_beam_files"): + filegroup( + name = "test_beam_files", + testonly = True, + srcs = [":test_other_beam"], + ) + erlang_bytecode( + name = "test_other_beam", + testonly = True, + srcs = [ + "src/rabbit_shovel_prometheus_app.erl", + "src/rabbit_shovel_prometheus_collector.erl", + "src/rabbit_shovel_prometheus_sup.erl", + ], + hdrs = [":public_and_private_hdrs"], + app_name = "rabbitmq_shovel_prometheus", + dest = "test", + erlc_opts = "//:test_erlc_opts", + deps = ["@prometheus//:erlang_app"], + ) + +def test_suite_beam_files(name = "test_suite_beam_files"): + erlang_bytecode( + name = "prometheus_rabbitmq_shovel_collector_SUITE_beam_files", + testonly = True, + srcs = ["test/prometheus_rabbitmq_shovel_collector_SUITE.erl"], + outs = ["test/prometheus_rabbitmq_shovel_collector_SUITE.beam"], + app_name = "rabbitmq_shovel_prometheus", + erlc_opts = "//:test_erlc_opts", + deps = ["//deps/amqp_client:erlang_app", "@prometheus//:erlang_app"], + ) diff --git a/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_app.erl b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_app.erl new file mode 100644 index 000000000000..662ff4a73b30 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_app.erl @@ -0,0 +1,27 @@ +%% 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(rabbit_shovel_prometheus_app). + +-behavior(application). + +-export([start/0, stop/0, start/2, stop/1]). + +start(normal, []) -> + {ok, _} = application:ensure_all_started(prometheus), + _ = rabbit_shovel_prometheus_collector:start(), + rabbit_shovel_prometheus_sup:start_link(). + +stop(_State) -> + _ = rabbit_shovel_prometheus_collector:stop(), + ok. + + +start() -> + _ = rabbit_shovel_prometheus_collector:start(). + +stop() -> ok. + diff --git a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_shovel_collector.erl b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_collector.erl similarity index 78% rename from deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_shovel_collector.erl rename to deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_collector.erl index 9eb0223cce99..acdc6d9df736 100644 --- a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_shovel_collector.erl +++ b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_collector.erl @@ -2,23 +2,29 @@ %% 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. +%% 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_shovel_collector). +-module(rabbit_shovel_prometheus_collector). + +-behaviour(prometheus_collector). + +-export([start/0, stop/0]). -export([deregister_cleanup/1, collect_mf/2]). -import(prometheus_model_helpers, [create_mf/4]). --behaviour(prometheus_collector). - -%% API exports --export([]). - %%==================================================================== %% Collector API %%==================================================================== +start() -> + {ok, _} = application:ensure_all_started(prometheus), + prometheus_registry:register_collector(?MODULE). + +stop() -> + prometheus_registry:deregister_collector(?MODULE). + deregister_cleanup(_) -> ok. collect_mf(_Registry, Callback) -> @@ -29,9 +35,9 @@ collect_mf(_Registry, Callback) -> {SMap, maps:update_with(S, fun(C) -> C + 1 end, 1, DMap)} end, {#{}, #{}}, Status), - Metrics = [{rabbitmq_shovel_dynamic, gauge, "Current number of dynamic shovels.", + Metrics = [{rabbitmq_shovel_dynamic, gauge, "Number of dynamic shovels", [{[{status, S}], C} || {S, C} <- maps:to_list(DynamicStatusGroups)]}, - {rabbitmq_shovel_static, gauge, "Current number of static shovels.", + {rabbitmq_shovel_static, gauge, "Number of static shovels", [{[{status, S}], C} || {S, C} <- maps:to_list(StaticStatusGroups)]} ], _ = [add_metric_family(Metric, Callback) || Metric <- Metrics], diff --git a/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_sup.erl b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_sup.erl new file mode 100644 index 000000000000..433c016af9f7 --- /dev/null +++ b/deps/rabbitmq_shovel_prometheus/src/rabbit_shovel_prometheus_sup.erl @@ -0,0 +1,20 @@ +%% 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(rabbit_shovel_prometheus_sup). + +-behaviour(supervisor). + +-export([start_link/0]). +-export([init/1]). + +start_link() -> + supervisor:start_link(?MODULE, []). + +init(_Args) -> + SupFlags = #{strategy => one_for_one, intensity => 1, period => 5}, + ChildSpecs = [], + {ok, {SupFlags, ChildSpecs}}. diff --git a/deps/rabbitmq_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl b/deps/rabbitmq_shovel_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl similarity index 69% rename from deps/rabbitmq_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl rename to deps/rabbitmq_shovel_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl index 0a642b1d8144..3aa9efe93168 100644 --- a/deps/rabbitmq_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl +++ b/deps/rabbitmq_shovel_prometheus/test/prometheus_rabbitmq_shovel_collector_SUITE.erl @@ -14,28 +14,30 @@ -compile(export_all). --define(DYN_RUNNING_METRIC(Gauge), #'MetricFamily'{name = <<"rabbitmq_shovel_dynamic">>, - help = "Current number of dynamic shovels.",type = 'GAUGE', - metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, - value = <<"running">>}], - gauge = #'Gauge'{value = Gauge}, - counter = undefined,summary = undefined,untyped = undefined, - histogram = undefined,timestamp_ms = undefined}]}). - --define(STAT_RUNNING_METRIC(Gauge), #'MetricFamily'{name = <<"rabbitmq_shovel_static">>, - help = "Current number of static shovels.",type = 'GAUGE', - metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, - value = <<"running">>}], - gauge = #'Gauge'{value = Gauge}, - counter = undefined,summary = undefined,untyped = undefined, - histogram = undefined,timestamp_ms = undefined}]}). +-define(DYN_RUNNING_METRIC(Gauge), + #'MetricFamily'{name = <<"rabbitmq_shovel_dynamic">>, + help = "Number of dynamic shovels",type = 'GAUGE', + metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, + value = <<"running">>}], + gauge = #'Gauge'{value = Gauge}, + counter = undefined,summary = undefined,untyped = undefined, + histogram = undefined,timestamp_ms = undefined}]}). + +-define(STAT_RUNNING_METRIC(Gauge), + #'MetricFamily'{name = <<"rabbitmq_shovel_static">>, + help = "Number of static shovels",type = 'GAUGE', + metric = [#'Metric'{label = [#'LabelPair'{name = <<"status">>, + value = <<"running">>}], + gauge = #'Gauge'{value = Gauge}, + counter = undefined,summary = undefined,untyped = undefined, + histogram = undefined,timestamp_ms = undefined}]}). -define(EMPTY_DYN_METRIC, #'MetricFamily'{name = <<"rabbitmq_shovel_dynamic">>, - help = "Current number of dynamic shovels.",type = 'GAUGE', + help = "Number of dynamic shovels",type = 'GAUGE', metric = []}). -define(EMPTY_STAT_METRIC, #'MetricFamily'{name = <<"rabbitmq_shovel_static">>, - help = "Current number of static shovels.",type = 'GAUGE', + help = "Number of static shovels",type = 'GAUGE', metric = []}). @@ -133,34 +135,50 @@ mix(Config) -> get_metrics(Config) -> rabbit_ct_broker_helpers:rpc(Config, 0, - rabbitmq_prometheus_collector_test_proxy, collect_mf, - [default, prometheus_rabbitmq_shovel_collector]). + ?MODULE, collect_mf, + [default, rabbit_shovel_prometheus_collector]). create_static_shovel(Config, Name) -> - SourceQueue = <<"source-queue">>, - DestQueue = <<"dest-queue">>, Hostname = ?config(rmq_hostname, Config), Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp), Shovel = [{Name, [{source, - [{protocol, amqp10}, - {uris, [rabbit_misc:format("amqp://~ts:~b", + [{uris, [rabbit_misc:format("amqp://~ts:~b", [Hostname, Port])]}, - {source_address, SourceQueue}] + + {declarations, [ {'exchange.declare', + [ {exchange, <<"my_fanout">>}, + {type, <<"fanout">>}, + durable + ]}, + {'queue.declare', + [{arguments, + [{<<"x-message-ttl">>, long, 60000}]}]}, + {'queue.bind', + [ {exchange, <<"my_fanout">>}, + {queue, <<>>} + ]} + ]}, + {queue, <<>>}] }, {destination, - [{uris, [rabbit_misc:format("amqp://~ts:~b/%2f?heartbeat=5", - [Hostname, Port])]}, - {declarations, - [{'queue.declare', [{queue, DestQueue}, auto_delete]}]}, - {publish_fields, [{exchange, <<>>}, - {routing_key, DestQueue}]}, - {publish_properties, [{delivery_mode, 2}, - {content_type, <<"shovelled">>}]}, - {add_forward_headers, true}, - {add_timestamp_header, true}]}, - {queue, <<>>}, - {ack_mode, no_ack} + [ {protocol, amqp091}, + {uris, ["amqp://"]}, + {declarations, [ {'exchange.declare', + [ {exchange, <<"my_direct">>}, + {type, <<"direct">>}, + durable + ]} + ]}, + {publish_properties, [ {delivery_mode, 2} ]}, + {add_forward_headers, true}, + {publish_fields, [ {exchange, <<"my_direct">>}, + {routing_key, <<"from_shovel">>} + ]} + ]}, + {ack_mode, on_confirm}, + {reconnect_delay, 5} + ]}], ok = rabbit_ct_broker_helpers:rpc(Config, 0, ?MODULE, setup_shovel, [Shovel, Name]). @@ -251,3 +269,11 @@ clear_param(Config, Name) -> clear_param(Config, Node, Name) -> rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_runtime_parameters, clear, [<<"/">>, <<"shovel">>, Name, <<"acting-user">>]). + +-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. diff --git a/moduleindex.yaml b/moduleindex.yaml index 687500c4096e..fdb82dada0c4 100755 --- a/moduleindex.yaml +++ b/moduleindex.yaml @@ -185,6 +185,9 @@ emqtt: - emqtt_ws enough: - enough +eunit_formatters: +- binomial_heap +- eunit_progress gen_batch_server: - gen_batch_server getopt: @@ -890,6 +893,10 @@ rabbitmq_federation: - rabbit_log_federation rabbitmq_federation_management: - rabbit_federation_mgmt +rabbitmq_federation_prometheus: +- rabbit_federation_prometheus_app +- rabbit_federation_prometheus_collector +- rabbit_federation_prometheus_sup rabbitmq_jms_topic_exchange: - rabbit_db_jms_exchange - rabbit_db_jms_exchange_m2k_converter @@ -1084,9 +1091,7 @@ rabbitmq_prometheus: - prometheus_rabbitmq_alarm_metrics_collector - prometheus_rabbitmq_core_metrics_collector - prometheus_rabbitmq_dynamic_collector -- prometheus_rabbitmq_federation_collector - prometheus_rabbitmq_global_metrics_collector -- prometheus_rabbitmq_shovel_collector - rabbit_prometheus_app - rabbit_prometheus_dispatcher - rabbit_prometheus_handler @@ -1125,6 +1130,10 @@ rabbitmq_shovel: rabbitmq_shovel_management: - rabbit_shovel_mgmt - rabbit_shovel_mgmt_util +rabbitmq_shovel_prometheus: +- rabbit_shovel_prometheus_app +- rabbit_shovel_prometheus_collector +- rabbit_shovel_prometheus_sup rabbitmq_stomp: - Elixir.RabbitMQ.CLI.Ctl.Commands.ListStompConnectionsCommand - rabbit_stomp diff --git a/plugins.mk b/plugins.mk index 7536c6705ae1..b822296da018 100644 --- a/plugins.mk +++ b/plugins.mk @@ -15,6 +15,7 @@ PLUGINS := rabbitmq_amqp1_0 \ rabbitmq_event_exchange \ rabbitmq_federation \ rabbitmq_federation_management \ + rabbitmq_federation_prometheus \ rabbitmq_jms_topic_exchange \ rabbitmq_management \ rabbitmq_management_agent \ @@ -30,6 +31,7 @@ PLUGINS := rabbitmq_amqp1_0 \ rabbitmq_sharding \ rabbitmq_shovel \ rabbitmq_shovel_management \ + rabbitmq_shovel_prometheus \ rabbitmq_stomp \ rabbitmq_stream \ rabbitmq_stream_management \ diff --git a/rabbitmq-components.mk b/rabbitmq-components.mk index be978ca28cdd..147a08ac8415 100644 --- a/rabbitmq-components.mk +++ b/rabbitmq-components.mk @@ -62,6 +62,7 @@ dep_rabbitmq_dotnet_client = git_rmq rabbitmq-dotnet-client dep_rabbitmq_event_exchange = git_rmq-subfolder rabbitmq-event-exchange $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_federation = git_rmq-subfolder rabbitmq-federation $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_federation_management = git_rmq-subfolder rabbitmq-federation-management $(current_rmq_ref) $(base_rmq_ref) main +dep_rabbitmq_federation_prometheus = git_rmq-subfolder rabbitmq-federation-prometheus $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_java_client = git_rmq rabbitmq-java-client $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_jms_client = git_rmq rabbitmq-jms-client $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_jms_cts = git_rmq rabbitmq-jms-cts $(current_rmq_ref) $(base_rmq_ref) main @@ -89,6 +90,7 @@ dep_rabbitmq_rtopic_exchange = git_rmq rabbitmq-rtopic-exchan dep_rabbitmq_sharding = git_rmq-subfolder rabbitmq-sharding $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_shovel = git_rmq-subfolder rabbitmq-shovel $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_shovel_management = git_rmq-subfolder rabbitmq-shovel-management $(current_rmq_ref) $(base_rmq_ref) main +dep_rabbitmq_shovel_prometheus = git_rmq-subfolder rabbitmq-shovel-prometheus $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_stomp = git_rmq-subfolder rabbitmq-stomp $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_stream = git_rmq-subfolder rabbitmq-stream $(current_rmq_ref) $(base_rmq_ref) main dep_rabbitmq_stream_common = git_rmq-subfolder rabbitmq-stream-common $(current_rmq_ref) $(base_rmq_ref) main @@ -156,6 +158,7 @@ RABBITMQ_COMPONENTS = amqp_client \ rabbitmq_event_exchange \ rabbitmq_federation \ rabbitmq_federation_management \ + rabbitmq_federation_prometheus \ rabbitmq_java_client \ rabbitmq_jms_client \ rabbitmq_jms_cts \ @@ -183,6 +186,7 @@ RABBITMQ_COMPONENTS = amqp_client \ rabbitmq_sharding \ rabbitmq_shovel \ rabbitmq_shovel_management \ + rabbitmq_shovel_prometheus \ rabbitmq_stomp \ rabbitmq_stream \ rabbitmq_stream_common \ diff --git a/rabbitmq.bzl b/rabbitmq.bzl index 8c51a2b16f71..56d2bfa22484 100644 --- a/rabbitmq.bzl +++ b/rabbitmq.bzl @@ -55,6 +55,7 @@ ALL_PLUGINS = [ "//deps/rabbitmq_event_exchange:erlang_app", "//deps/rabbitmq_federation:erlang_app", "//deps/rabbitmq_federation_management:erlang_app", + "//deps/rabbitmq_federation_prometheus:erlang_app", "//deps/rabbitmq_jms_topic_exchange:erlang_app", "//deps/rabbitmq_management:erlang_app", "//deps/rabbitmq_mqtt:erlang_app", @@ -68,6 +69,7 @@ ALL_PLUGINS = [ "//deps/rabbitmq_sharding:erlang_app", "//deps/rabbitmq_shovel:erlang_app", "//deps/rabbitmq_shovel_management:erlang_app", + "//deps/rabbitmq_shovel_prometheus:erlang_app", "//deps/rabbitmq_stomp:erlang_app", "//deps/rabbitmq_stream:erlang_app", "//deps/rabbitmq_stream_management:erlang_app",