Commit Graph

847 Commits

Author SHA1 Message Date
Arnaud Cogoluègnes 49a70a0f9f
Handle last_stream_member more gently in CLI 2021-06-04 16:35:46 +02:00
Michael Klishin 040f8cc912
Replace a few more leftover MPLv1.1 license headers
Most files have been using the MPLv2 headers for months now.
These were detected by the OSL process.
2021-05-19 21:20:47 +03:00
Michael Klishin 09cae9252f
Update status command module name, references #3014 2021-05-02 04:34:50 +03:00
Michael Klishin a5373d71d6
Make it possible to update virtual host tags
Currently they can only be specified at creation time
2021-05-01 21:48:50 +03:00
dcorbacho 310a483221 CLI command to for stream details
rabbitmq-queues stream_status [--tracking] <queue>
If the --tracking option is enabled, it returns a table with all offset tracking
for that queue.
2021-04-13 15:29:40 +01:00
Michael Klishin 6ad235cc64
Update rabbitmq-diagnostics {drain, revive} tests
to enable the feature flag they depend for
their functionality.
2021-03-24 21:22:40 +03:00
Jean-Sébastien Pédron cdcf602749
Switch from Lager to the new Erlang Logger API for logging
The configuration remains the same for the end-user. The only exception
is the log root directory: it is now set through the `log_root`
application env. variable in `rabbit`. People using the Cuttlefish-based
configuration file are not affected by this exception.

The main change is how the logging facility is configured. It now
happens in `rabbit_prelaunch_logging`. The `rabbit_lager` module is
removed.

The supported outputs remain the same: the console, text files, the
`amq.rabbitmq.log` exchange and syslog.

The message text format slightly changed: the timestamp is more precise
(now to the microsecond) and the level can be abbreviated to always be
4-character long to align all messages and improve readability. Here is
an example:

    2021-03-03 10:22:30.377392+01:00 [dbug] <0.229.0> == Prelaunch DONE ==
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>  Starting RabbitMQ 3.8.10+115.g071f3fb on Erlang 23.2.5
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>  Licensed under the MPL 2.0. Website: https://rabbitmq.com

The example above also shows that multiline messages are supported and
each line is prepended with the same prefix (the timestamp, the level
and the Erlang process PID).

JSON is also supported as a message format and now for any outputs.
Indeed, it is possible to use it with e.g. syslog or the exchange. Here
is an example of a JSON-formatted message sent to syslog:

    Mar  3 11:23:06 localhost rabbitmq-server[27908] <0.229.0> - {"time":"2021-03-03T11:23:06.998466+01:00","level":"notice","msg":"Logging: configured log handlers are now ACTIVE","meta":{"domain":"rabbitmq.prelaunch","file":"src/rabbit_prelaunch_logging.erl","gl":"<0.228.0>","line":311,"mfa":["rabbit_prelaunch_logging","configure_logger",1],"pid":"<0.229.0>"}}

For quick testing, the values accepted by the `$RABBITMQ_LOGS`
environment variables were extended:
  * `-` still means stdout
  * `-stderr` means stderr
  * `syslog:` means syslog on localhost
  * `exchange:` means logging to `amq.rabbitmq.log`

`$RABBITMQ_LOG` was also extended. It now accepts a `+json` modifier (in
addition to the existing `+color` one). With that modifier, messages are
formatted as JSON intead of plain text.

The `rabbitmqctl rotate_logs` command is deprecated. The reason is
Logger does not expose a function to force log rotation. However, it
will detect when a file was rotated by an external tool.

From a developer point of view, the old `rabbit_log*` API remains
supported, though it is now deprecated. It is implemented as regular
modules: there is no `parse_transform` involved anymore.

In the code, it is recommended to use the new Logger macros. For
instance, `?LOG_INFO(Format, Args)`. If possible, messages should be
augmented with some metadata. For instance (note the map after the
message):

    ?LOG_NOTICE("Logging: switching to configured handler(s); following "
                "messages may not be visible in this log output",
                #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),

Domains in Erlang Logger parlance are the way to categorize messages.
Some predefined domains, matching previous categories, are currently
defined in `rabbit_common/include/logging.hrl` or headers in the
relevant plugins for plugin-specific categories.

At this point, very few messages have been converted from the old
`rabbit_log*` API to the new macros. It can be done gradually when
working on a particular module or logging.

The Erlang builtin console/file handler, `logger_std_h`, has been forked
because it lacks date-based file rotation. The configuration of
date-based rotation is identical to Lager. Once the dust has settled for
this feature, the goal is to submit it upstream for inclusion in Erlang.
The forked module is calld `rabbit_logger_std_h` and is based
`logger_std_h` in Erlang 23.0.
2021-03-11 15:17:36 +01:00
Loïc Hoguin 5c829ff599
Add rabbitmq-diagnostics remote_shell 2021-03-03 11:28:54 +01:00
Michael Klishin 83ae131dea
Refactor this test in attempt to help a scoping issue on Concourse 2021-02-01 23:09:07 +03:00
Michael Klishin e735025b2c
Use await_condition/2 in these tests 2021-02-01 20:19:39 +03:00
Michal Kuratczyk ea1f4a355a New command: `rabbitmqctl close_all_user_connections` 2021-02-01 16:04:16 +01:00
Michal Kuratczyk ce65586405
Allow "all" as a feature flag name
`rabbitmqctl enable_feature_flag all` enables all currently disabled feature flags.
While https://github.com/rabbitmq/rabbitmq-cli/issues/455 asked for
`--all`, I decided to just use "all" for consistency with
`rabbitmq-queues rebalance all`.

Closes rabbitmq/rabbitmq-cli#455

(cherry picked from commit af9e877848)
2020-11-17 14:17:35 +03:00
Michael Klishin 5a95b3b847 Merge pull request #450 from rabbitmq/auth-attempt-metrics
Add enable/disable and list auth attempt metrics
2020-10-14 23:56:47 +03:00
Michael Klishin c43db9d4d9 Auth attempt command naming, add JSON --formatter support 2020-10-14 23:32:16 +03:00
Luke Bakken 6232f18eed mix format 2020-10-12 10:07:04 -07:00
Jean-Sébastien Pédron 15eef0b52a test: Remove assertions around `mnesia_dir_not_found`
... when no Mnesia directory is specified. The reason is that the
default behavior changed: if the node is unavailable and no Mnesia
directory is configured, we use the default directory.
2020-10-12 17:42:50 +02:00
dcorbacho a40f08fbc4 Fix stream commands 2020-09-30 16:34:53 +01:00
dcorbacho eaacd594f5 Move set stream retention policy to rabbitm-streams
Add forgotten tests
2020-09-30 16:34:53 +01:00
dcorbacho b2698901d3 Set stream retention policy command
[#171207092]
2020-09-30 16:34:13 +01:00
Michael Klishin c691658476 Squash a couple of compiler warnings 2020-09-22 05:55:56 +03:00
Michael Klishin 446e164f27 'rabbitmq-queues peek': tighter position validation, basic JSON formatter support 2020-09-21 12:00:45 +03:00
Michael Klishin aa2b985461 Merge branch 'master' into qq-peek-command 2020-09-20 20:02:53 +03:00
dcorbacho dd5bed6308 Reclaim quorum memory command 2020-09-16 12:38:55 +01:00
kjnilsson 53a5839ae7 Quorum queue peek command 2020-09-14 12:05:46 +01:00
Michael Klishin 9b8b7436e8 Wording 2020-08-25 19:09:00 +03:00
Michael Klishin 6f17c6cbd0 More reliable drain and revive command assertions 2020-08-20 14:27:30 +03:00
Michael Klishin 51b60e3ac3 More reliable drain and revive command assertions 2020-07-21 03:42:48 +03:00
Ayanda-D 30160430b2 Update license, ref: #447 2020-07-17 15:59:20 +01:00
Ayanda-D afcae06cd9 Include acting-user in user-limit operations & doc-guides 2020-07-17 15:59:20 +01:00
Anupama Singh 128201baa6 New command added to list user limits 2020-07-17 15:59:20 +01:00
Ayanda-D dbbe62e8a4 Test case added for command to set both max-connections and max-channels
Clearing all user limits
Testcase to test clearing all limits for user
2020-07-17 15:59:20 +01:00
Anupama Singh d1301e5ce5 Test cases for setting and clearing user connection/channel limits 2020-07-17 15:59:20 +01:00
Michael Klishin 5553a24545 Sync license headers with MPL2 in master 2020-07-14 03:54:19 +03:00
Michael Klishin 998701eb05 Introduce 'rabbitmq-upgrade drain' and 'rabbitmq-upgrade revive'
A part of rabbitmq/rabbitmq-server#2321
2020-07-14 03:52:02 +03:00
Michael Klishin 35103fe7da Introduce 'rabbitmqctl {suspend,resume}_listeners'
Not directly related to rabbitmq/rabbitmq-server#2321
but useful on its own. We've had requests for and discussions
about such commands in the past and now that Ranch supports
listener suspension, there aren't many reasons not to do it.
2020-07-14 03:52:01 +03:00
dcorbacho 679ca254f3 Switch to Mozilla Public License 2.0 (MPL 2.0) 2020-07-11 19:23:07 +01:00
Michael Klishin db299967e0 Introduce 'rabbitmq-diagnostics erlang_cookie_sources'
to help troubleshoot authentication issues.

Inspired by an idea from @gerhard.
2020-07-05 03:19:50 +07:00
Michael Klishin 31550672da Squash a compiler warning 2020-07-03 10:57:23 +07:00
Michael Klishin f8c9b3db33 More end-to-end integration tests for #439 2020-07-02 07:32:26 +03:00
Michael Klishin 2101043257 Introduce a first class autocomplete command
Currently we have a --auto-complete magic argument which
does not show up in `help` and requires its argument to be
explcitly -- separated from the actual flag, which is
counter-intuitive.

This introduces a new autocomplete command which is delegated
to by --auto-complete, much like --help is simply a special
way of invoking the `help` command.

Closes #439
2020-07-02 07:29:40 +03:00
Michael Klishin a98e38dd80 Introduce 'rabbitmqctl eval_file [file path]'
for evaluation of scripts in environments where standard input
redirection is not an option or problematic, e.g.
certain Windows environments.

Closes #438
2020-07-01 03:11:13 +03:00
Michael Klishin 0f1f6d2be7 'rabbitmqctl eval': accept expression to evaluate from stdin
References #438
2020-07-01 02:29:22 +03:00
Michael Klishin 921d349e37 Make --help, help usage help messages consistent
* `help` printed an "Error:" at the top for no reason
 * `help [command]` with a non-existent command did not offer a suggestion
   like an attempt to invoke a non-existent command would
 * Exit codes were not consistent
 * `help --list-commands` had line break issues

With this change,

  * `help` is consistent with --help
  * `help [command]` is consistent with `[command] --help`
  * If a command is not found, either during the execution flow
    or `help [commnad]`, we consistently attempt a Jaro distance suggestion
  * Successful or effectively successful exits from the `help`
    command do not produce any error messages at the top
2020-06-29 03:57:52 +03:00
Michael Klishin ca815978dd Drop a low importance test that only fails in one environment 2020-06-26 06:35:55 +03:00
Michael Klishin 37c9a5cb75 An attempt to fix a test failing only on Concourse 2020-06-26 06:26:25 +03:00
Michael Klishin ef329b88b1 rabbitmqctl export_definitions: ensure that parameter value is a map
otherwise it would be serialised as a list of pairs, which is
not the format the import path (or an operator) expects

Closes #435
2020-06-26 05:55:57 +03:00
Michael Klishin d11bd12a97 Make 'rabbitmqctl hipe_compile' a no-op
HiPE has been deprecated/only partially supported in Erlang 22
and will be removed completely in Erlang 24 next year.

Part of rabbitmq/rabbitmq-server#2392
2020-06-25 18:39:12 +03:00
Michael Klishin f11384fe86 Introduce 'rabbitmq-diagnostics resolver_info'
To inspect effective inetrc [1] settings used
by a node or CLI tools.

1. https://erlang.org/doc/apps/erts/inet_cfg.html
2020-06-21 15:09:21 +03:00
Michael Klishin b17fda724b Introduce 'rabbitmq-diagnostics resolve_hostname'
Helps with troubleshooting hostname resolution behavior
on nodes and locally for CLI tools. This is obviously not meant
to be a replacement for existing tools such as dig, only
a way to quickly spot obvious irregularities, e.g. those
in environments that use custom Erlang inetrc files.

Per discussion @harshac.
2020-06-20 16:55:21 +03:00
Michael Klishin 6986086b88 User and permission management command: adopt a more suitable exit code
Apparently [1], which is the most standardized set of exit codes
we could find, includes a dedicated exit code for cases where
a user does not exist.

References #425, rabbitmq/rabbitmq-server#2363, bda0cbfdc3.

1. https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+12.0-RELEASE&arch=default&format=html
2020-06-08 05:35:33 +03:00
Michael Klishin bda0cbfdc3 Update test expectation
References #425, rabbitmq/rabbitmq-server#2363
2020-06-08 05:03:55 +03:00
Michael Klishin 3003b9e615 Introduce 'rabbitmq-diagnostics list_network_interfaces'
To make it easier to discover them without using eval and
obscure functions.

Part of rabbitmq/rabbitmq-cli#424
2020-06-05 17:16:10 +03:00
Michael Klishin 92bb8dee18 Cosmetics 2020-06-04 04:42:49 +03:00
Michael Klishin 2bd6c95375 Rely on rabbit_env to infer node name
During the 3.8.4 cycle we have backported `rabbit_env` to v3.8.x.
Instead of messing with env variable prefixing, it tries both
RABBITMQ_{VAR} and {VAR} environment variables. However,
in CLI tools node name currently only picks up RABBITMQ_NODENAME,
so environments where node name has to be explicitly configured
via rabbitmq-env.conf:

NODENAME=rabbit@our.custom.hostname

would not pick this node name up. RABBITMQ_NODENAME had to be added
as a workaround.

With this change the behavior of CLI tools and the server is closer.

Note that this updates a few places which used `Config.get_option/2`
to get a "default node name" which more often than not ended up
being a node prefix ("rabbit"). Those tests had to be updated
to use `Config.default/1`.

Closes #421.
References c8e766dec7, 8a5ab87038.
2020-05-28 02:54:33 +03:00
Michael Klishin 61a927ffb6 Brush up encode and decode commands 2020-05-21 09:37:08 +03:00
Michael Klishin bc95259d29 Adapt one more test 2020-05-21 08:13:46 +03:00
Luke Bakken a4669adf94 Update for version 2 of credentials-obfuscation
Part of rabbitmq/credentials-obfuscation#5
2020-05-20 18:54:40 -07:00
Michael Klishin 56da1bb71e Update test assertion expectations 2020-05-19 06:59:03 +03:00
Michael Klishin 0ff2e3fb77 Explain 2020-05-16 19:12:31 +03:00
Michael Klishin a2ec22023f Handle variable case in this test 2020-05-16 00:39:07 +03:00
Michael Klishin 0537a9ca36 Don't depend on a single env variable in this test 2020-05-16 00:36:33 +03:00
Michael Klishin 947940ccd5 Introduce 'rabbitmq-diagnostics os_env'
It prints RabbitMQ-specific environment variables that
are set on the target node. Can be used to inspect env variable-based
configuration without access to the target host.
2020-05-06 23:19:04 +03:00
Michael Klishin ab1c80062d Introduce 'rabbitmq-upgrade await_online_synchronized_mirror'
Similar in purpose to await_online_quorum_plus_one but
for classic mirrored queues.

Part of rabbitmq/rabbitmq-cli#408
2020-04-22 03:12:32 +03:00
Michael Klishin d99cdd04f5 Introduce rabbitmq-upgrade await_online_quorum_plus_one
The readiness is similar to that of 'rabbitmq-diagnostics check_if_node_is_quorum_critical'
but this command awaits for it up to --timeout seconds.

While at it, refactor DefautOutput to detect and support JSON formatting
of most basic return values suc has :ok or {:error, map}.

Part of #408.
2020-04-22 01:25:55 +03:00
Michael Klishin d54876be57 Drive by change: correct a typo 2020-04-22 01:23:50 +03:00
Michael Klishin a3d60d35c5 Be less generous in empty whitespace use in setup_all functions 2020-03-24 19:08:00 +03:00
Michael Klishin 58b404650a WaitCommandTest: make sure distribution is started before used 2020-03-24 17:49:42 +03:00
Michael Klishin 2f5a182a68 TestHelper.await_rabbitmq_startup/0: introduce retries 2020-03-24 17:49:22 +03:00
Jean-Sébastien Pédron 0e15591bf5 Update copyright (year 2020) 2020-03-10 15:39:56 +01:00
Jean-Sébastien Pédron 4e6e87b9fc Update mock_rabbitmq_plugin_for_3_8 to support RabbitMQ 3.9.x 2020-03-06 08:19:31 +01:00
Michael Klishin 5b7063d07d More sensible JSON formatting for some commands
Fall back to a JSON document if command returns a bitstring
(does not do any preformatting for JSON).

Per discussion with @lukebakken

Closes #394.
2020-01-18 02:06:04 +03:00
Jean-Sébastien Pédron cccf81d0ff test/fixtures: Fix mock plugins' dependencies
They should depend on `rabbit`, not on `rabbit_common`.

This will be even required #rabbitmq/rabbitmq-server#2212 is accepted.
2020-01-16 14:39:47 +01:00
Michael Klishin 73776fbf04 (c) bump 2019-12-29 05:50:26 +03:00
Michael Klishin 7158eec954 Introduce rabbitmq-queues check_if_node_is_mirror_sync_critical
Part two of #389.
2019-12-19 03:59:30 +03:00
Michael Klishin b5c47be4e6 Tests for the CLI part of rabbitmq-queues check_if_node_is_quorum_critical
Key tests for the target function are in the server repo.
2019-12-12 17:11:52 +03:00
Michael Klishin c49eb2fafc A typo 2019-12-12 16:55:59 +03:00
Jean-Sébastien Pédron 8a5ab87038 Load `rabbit_env` context to know about node configuration
The context is either initialized from the CLI's process environment or
from the remote node's own context.

This is required to e.g. find plugins or Mnesia directory.

In `code_path`, we don't append `ebin` anymore to the code path because
the `rabbit` application is now packaged as an .ez archive like plugins.
This simplifies the overall layout of the project.
2019-12-11 15:08:00 +01:00
Michael Klishin 01e950fd18 Make tests that mess with node or quorum state sequential
As most tests already are. It's highly unlikely that these
were meant to execute in parallel by design.
2019-12-11 14:51:10 +01:00
Michael Klishin 8b7c83bf6e Rename a test file 2019-12-11 04:56:04 +03:00
Michael Klishin b49b639add ctl export_definitions: fail validation w/o positional args 2019-11-19 00:41:30 +03:00
Michael Klishin 7c5933052e Finish ctl import_definitions 2019-11-16 06:46:26 +03:00
Michael Klishin 7c0718800f Introduce rabbitmqctl export_definitions [path] 2019-11-15 02:20:02 +03:00
Michael Klishin 99e9b0b2b6 Simplify these assertions a bit 2019-10-08 09:41:31 -05:00
Michael Klishin 7b1bf6c734 Squash a warning 2019-10-08 09:41:17 -05:00
Arnaud Cogoluègnes f0bba26e8c Add test for certificate expiration verification
References #304, #305
2019-10-08 16:10:04 +02:00
Michael Klishin c7e60774d0 Minor Prometheus listener description edits 2019-09-26 13:05:32 +03:00
Michael Klishin 254fe20453 Move quorum_status to rabbitmq-queues, add basic tests 2019-09-26 08:16:33 +03:00
Arnaud Cogoluègnes 67a38fc2e9 Handle empty output in JSON stream
Some streaming commands with a duration argument can send the empty
string as the output (along with a finishing marker). This case was not
handled properly and would result in a stack trace when the command
returned once the duration has elapsed.
2019-09-25 16:56:47 +02:00
Jean-Sébastien Pédron 0cb95e7b55 log_tail_stream_command_test: Bump stream duration to 15 seconds
... from 5 seconds. Hopefully this will increase the chance of seeing
the messages logged by the testcase.
2019-09-24 11:48:47 +02:00
Michael Klishin 5a137480b3 Merge pull request #378 from rabbitmq/consume-events-command
Consume event command
2019-09-24 01:55:57 +03:00
Michael Klishin 99f1790ac3 Update test expectations 2019-09-24 01:52:31 +03:00
Michael Klishin 4c33ce0961 Move command_line_arguments to rabbitmq-diagnostics 2019-09-24 00:54:11 +03:00
dcorbacho b5e5d0a274 Command line arguments command
* Reports the command line flags returned by `init:get_arguments()`

[#159699409]
2019-09-23 20:07:33 +01:00
dcorbacho 15d7eb2858 Diagnostics: test consume_event_stream_command
[#168224266]
2019-09-23 17:19:07 +01:00
Michael Klishin 6193023a18 Merge pull request #375 from rabbitmq/post-upgrade-command
Post upgrade command
2019-09-22 08:32:30 +03:00
Michael Klishin ccc7ebbafc rabbitmq-upgrade: basic tests for post_upgrade, polishing 2019-09-22 08:31:20 +03:00
Whitespirit0 ea2ace438c Update set_parameter test to match new output 2019-09-20 11:41:33 +02:00
Michael Klishin 4505b9a85f ctl add_vhost: suggest a comma-separated list of tags
For consistency with user tags.
2019-08-15 15:52:09 +10:00
Michael Klishin 2c6f5a1146 ctl add_vhost: make it possible to provide a description 2019-08-15 15:42:06 +10:00
Michael Klishin 5b1086156e diagnostics log_tail_stream: remove a fragile test
It makes a lot of assumptions about Lager's log flush
timing and can be tripped by the peak rate protection
mechanism. This test module has a high rate of false
positives on Concourse.

There is another test that asserts over a "folded" stream, so
code coverage is kept about the same.
2019-08-11 13:20:19 +10:00