New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new command for Web MQTT connection listing #10693 #9302 #10761
Merged
michaelklishin
merged 11 commits into
main
from
cloudamqp-fix/9302-list-webmqtt-connections
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
befb3b3
Prevent not_found on list web mqtt connections
LoisSotoLopez 481cac6
Fix/9302 test list Web MQTT connections command
LoisSotoLopez f7de9ba
Remove unnecessary newline
LoisSotoLopez a2f98a8
Add new integration suite in #10693 to BUILD.bazel
michaelklishin f193ce1
bazel run gazelle for #10693
michaelklishin d3ea70f
Web MQTT: make //deps/rabbitmq_web_mqtt:dialyze build (and pass)
michaelklishin 6fd8eba
Web MQTT: make //deps/rabbitmq_web_mqtt:xref build (and pass)
michaelklishin e170bbf
Fix //deps/rabbitmq_web_mqtt:command_SUITE (note: it's -mixed counter…
michaelklishin 5ddc16f
Web MQTT command_SUITE: skip in mixed version mode
michaelklishin e3051f8
Web MQTT command_SUITE: cosmetics
michaelklishin 5271c26
Mixed version test fix
pjk25 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
.../rabbitmq_web_mqtt/src/Elixir.RabbitMQ.CLI.Ctl.Commands.ListWebMqttConnectionsCommand.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
%% 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('Elixir.RabbitMQ.CLI.Ctl.Commands.ListWebMqttConnectionsCommand'). | ||
|
||
-include_lib("rabbitmq_mqtt/include/rabbit_mqtt.hrl"). | ||
|
||
-behaviour('Elixir.RabbitMQ.CLI.CommandBehaviour'). | ||
|
||
-export([formatter/0, | ||
scopes/0, | ||
switches/0, | ||
aliases/0, | ||
usage/0, | ||
usage_additional/0, | ||
usage_doc_guides/0, | ||
banner/2, | ||
validate/2, | ||
merge_defaults/2, | ||
run/2, | ||
output/2, | ||
description/0, | ||
help_section/0]). | ||
|
||
formatter() -> 'Elixir.RabbitMQ.CLI.Formatters.Table'. | ||
scopes() -> [ctl, diagnostics]. | ||
switches() -> [{verbose, boolean}]. | ||
aliases() -> [{'V', verbose}]. | ||
|
||
description() -> <<"Lists all Web MQTT connections">>. | ||
|
||
help_section() -> | ||
{plugin, web_mqtt}. | ||
|
||
validate(Args, _) -> | ||
InfoItems = lists:map(fun atom_to_list/1, ?INFO_ITEMS), | ||
case 'Elixir.RabbitMQ.CLI.Ctl.InfoKeys':validate_info_keys(Args, | ||
InfoItems) of | ||
{ok, _} -> ok; | ||
Error -> Error | ||
end. | ||
|
||
merge_defaults([], Opts) -> | ||
merge_defaults([<<"client_id">>, <<"conn_name">>], Opts); | ||
merge_defaults(Args, Opts) -> | ||
{Args, maps:merge(#{verbose => false}, Opts)}. | ||
|
||
usage() -> | ||
<<"list_web_mqtt_connections [<column> ...]">>. | ||
|
||
usage_additional() -> | ||
Prefix = <<" must be one of ">>, | ||
InfoItems = 'Elixir.Enum':join(lists:usort(?INFO_ITEMS), <<", ">>), | ||
[ | ||
{<<"<column>">>, <<Prefix/binary, InfoItems/binary>>} | ||
]. | ||
|
||
usage_doc_guides() -> | ||
[?WEB_MQTT_GUIDE_URL]. | ||
|
||
run(Args, #{node := NodeName, | ||
timeout := Timeout, | ||
verbose := Verbose}) -> | ||
InfoKeys = case Verbose of | ||
true -> ?INFO_ITEMS; | ||
false -> 'Elixir.RabbitMQ.CLI.Ctl.InfoKeys':prepare_info_keys(Args) | ||
end, | ||
|
||
Nodes = 'Elixir.RabbitMQ.CLI.Core.Helpers':nodes_in_cluster(NodeName), | ||
|
||
'Elixir.RabbitMQ.CLI.Ctl.RpcStream':receive_list_items( | ||
NodeName, | ||
rabbit_web_mqtt_app, | ||
emit_connection_info_all, | ||
[Nodes, InfoKeys], | ||
Timeout, | ||
InfoKeys, | ||
length(Nodes)). | ||
|
||
banner(_, _) -> <<"Listing Web MQTT connections ...">>. | ||
|
||
output(Result, _Opts) -> | ||
'Elixir.RabbitMQ.CLI.DefaultOutput':output(Result). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function calls
supervisor:which_children/1
which documents:So, this implementation is dangerous when there are many connections, which is typical for MQTT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there isn't a more efficient way to do it in Ranch. Introducing connection tracking tables for Web MQTT would completely change the stope of this PR, which is meant to be a bug fix.