Skip to content
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

πŸ‘Œ Improve usage of configure-rabbitmq #6474

Merged
merged 3 commits into from
Jun 19, 2024

Conversation

mbercx
Copy link
Member

@mbercx mbercx commented Jun 12, 2024

Implements the suggestions in #6454 (comment).

Example UX:

❯ brew services stop rabbitmq
Stopping `rabbitmq`... (might take a while)
==> Successfully stopped `rabbitmq` (label: homebrew.mxcl.rabbitmq)
❯ verdi presto
Report: Option `--use-postgres` not enabled: configuring the profile to use SQLite.
Report: RabbitMQ server not found: configuring the profile without a broker.
Report: Initialising the storage backend.
Report: Storage initialisation completed.
Success: Created new profile `presto-7`.
Success: Configured the localhost as a computer.
❯ verdi status
 βœ” version:     AiiDA v2.5.1.post0
 βœ” config:      /Users/mbercx/project/core/.aiida
 βœ” profile:     presto-7
 βœ” storage:     SqliteDosStorage[/Users/mbercx/project/core/.aiida/repository/sqlite_dos_9334f1ac2f1f42d2b51724491fdb9030]: open,
 ⏺ broker:      No broker defined for this profile: certain functionality not available.
 ⏺ daemon:      No broker defined for this profile: daemon is not available.
❯ brew services start rabbitmq
==> Successfully started `rabbitmq` (label: homebrew.mxcl.rabbitmq)
❯ verdi profile configure-rabbitmq
Success: Successfully connected to RabbitMQ server.
❯ verdi status
 βœ” version:     AiiDA v2.5.1.post0
 βœ” config:      /Users/mbercx/project/core/.aiida
 βœ” profile:     presto-7
 βœ” storage:     SqliteDosStorage[/Users/mbercx/project/core/.aiida/repository/sqlite_dos_9334f1ac2f1f42d2b51724491fdb9030]: open,
Warning: RabbitMQ v3.13.1 is not supported and will cause unexpected problems!
Warning: It can cause long-running workflows to crash and jobs to be submitted multiple times.
Warning: See https://github.com/aiidateam/aiida-core/wiki/RabbitMQ-version-to-use for details.
 βœ” broker:      RabbitMQ v3.13.1 @ amqp://guest:guest@127.0.0.1:5672?heartbeat=600
 ⏺ daemon:      The daemon is not running.

@mbercx mbercx requested a review from sphuber June 12, 2024 09:03
@mbercx mbercx added priority/critical-blocking must be resolved before next release labels Jun 12, 2024
Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.76%. Comparing base (ef60b66) to head (a49e79a).
Report is 112 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/cmdline/commands/cmd_profile.py 91.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6474      +/-   ##
==========================================
+ Coverage   77.51%   77.76%   +0.26%     
==========================================
  Files         560      561       +1     
  Lines       41444    41781     +337     
==========================================
+ Hits        32120    32487     +367     
+ Misses       9324     9294      -30     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mbercx . I'm onboard with the suggestion to change the default to being non-interactive behavior. Just some suggestions on the implementation

src/aiida/brokers/rabbitmq/defaults.py Outdated Show resolved Hide resolved
src/aiida/cmdline/commands/cmd_profile.py Outdated Show resolved Hide resolved
src/aiida/cmdline/params/options/main.py Outdated Show resolved Hide resolved
src/aiida/cmdline/commands/cmd_profile.py Outdated Show resolved Hide resolved
@mbercx mbercx force-pushed the improve/cli-conf-rabbitmq branch 3 times, most recently from 7577bc8 to 2540606 Compare June 18, 2024 07:27
@mbercx
Copy link
Member Author

mbercx commented Jun 18, 2024

@sphuber I made the requested changes:

  1. The NON_INTERACTIVE option has been replaced with INTERACTIVE. This is the switch we discussed, but to me it was more natural to have "interactive" to avoid double negatives in the logic.
  2. The configure-rabbitmq command now checks if it can successfully connect to the broker, if not it will ask for confirmation to configure, unless -f/--force is specified. It's a bit conflicting with the --non-interactive option, I suppose, but ok.

Here is the usage:

❯ verdi presto 
Report: Option `--use-postgres` not enabled: configuring the profile to use SQLite.
Report: RabbitMQ server not found: configuring the profile without a broker.
Report: Initialising the storage backend.
Report: Storage initialisation completed.
Success: Created new profile `presto-9`.
Success: Configured the localhost as a computer.
❯ verdi profile configure-rabbitmq 
Warning: Unable to connect to RabbitMQ server with configuration: {'protocol': 'amqp', 'username': 'guest', 'password': 'guest', 'host': '127.0.0.1', 'port': 5672, 'virtual_host': ''}
Do you want to continue with the provided configuration? [y/N]: N
Aborted!
❯ brew services start rabbitmq
==> Successfully started `rabbitmq` (label: homebrew.mxcl.rabbitmq)
❯ verdi profile configure-rabbitmq
Success: Connected to RabbitMQ with the provided connection parameters
Success: RabbitMQ configuration for `presto-9` updated to: {'protocol': 'amqp', 'username': 'guest', 'password': 'guest', 'host': '127.0.0.1', 'port': 5672, 'virtual_host': ''}
❯ brew services stop rabbitmq
Stopping `rabbitmq`... (might take a while)
==> Successfully stopped `rabbitmq` (label: homebrew.mxcl.rabbitmq)
❯ verdi profile configure-rabbitmq
Warning: Unable to connect to RabbitMQ server with configuration: {'protocol': 'amqp', 'username': 'guest', 'password': 'guest', 'host': '127.0.0.1', 'port': 5672, 'virtual_host': ''}
Do you want to continue with the provided configuration? [y/N]: N
Aborted!
❯ verdi profile configure-rabbitmq -f
Warning: Unable to connect to RabbitMQ server with configuration: {'protocol': 'amqp', 'username': 'guest', 'password': 'guest', 'host': '127.0.0.1', 'port': 5672, 'virtual_host': ''}
Success: RabbitMQ configuration for `presto-9` updated to: {'protocol': 'amqp', 'username': 'guest', 'password': 'guest', 'host': '127.0.0.1', 'port': 5672, 'virtual_host': ''}

I was still considering making the final Success: a Report: instead.

@mbercx mbercx requested a review from sphuber June 18, 2024 08:06
@mbercx
Copy link
Member Author

mbercx commented Jun 18, 2024

@sphuber will update the commits properly once we've agreed on the changes.

src/aiida/brokers/rabbitmq/defaults.py Outdated Show resolved Hide resolved
Comment on lines 347 to 353
NON_INTERACTIVE = OverridableOption(
'-n',
'--non-interactive',
is_flag=True,
is_eager=True,
help='In non-interactive mode, the CLI never prompts but simply uses default values for options that define one.',
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that wasn't quite the change I was aiming for πŸ˜… I see the point of wanting to avoid the double negative though. Ok, fine to keep the change, but I think we cannot just remove the NON_INTERACTIVE option as it is probably used elsewhere. So please reinstate it and just define if as a INTERACTIVE.clone(). Ideally we would deprecate it, but that will take some doing. We probably would have to add a deprecated argument to OverridableOption that is then checked upon option call, or the value parsing. We cannot just do it on import because then it will always show, even if the user is not actually using it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, it can also be used outside of aiida-core. 🀦 I'll reinstate it for now, we can think of the deprecation path later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Van uitstel komt afstel.....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just redefine it using INTERACTIVE.clone() though? As I understand it, we can't override the option name, and this would be used in the function definition of the click command. So I think we need to fully preserve the NON_INTERACTIVE option if we want to maintain backwards compatibility.

I've added the deprecation warning as requested to avoid afstel. ^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now we are exactly in the situation that I was trying to avoid. We now have two options to do the same thing that need to be maintained and the old one is deprecated. Is all of that faf really necessary just to avoid a double negative in one place? It was working fine before wasn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hadn't considered that the options were part of the public API. I still think having an INTERACTIVE switch option makes more sense, but it isn't worth the deprecation. I'll see about turning the NON_INTERACTIVE option into a proper switch instead.

@mbercx mbercx force-pushed the improve/cli-conf-rabbitmq branch 4 times, most recently from e87eb5c to da8db25 Compare June 19, 2024 05:47
mbercx added 3 commits June 19, 2024 13:07
For many setup/configuration CLI commands, the `NON_INTERACTIVE` option is added to
allow the user to run the command without being prompted for input and use the defaults
instead. However, new users are often not aware of this option, and will not understand
some options as they are prompted. Even when a sensible default is offered by the
prompt, users will still want to understand the option and be unsure if the default
works for them.

Hence, it might be preferable to run it non-interactively by default for some commands.
Here we adapt the `NON_INTERACTIVE` option into a switch
(`-n/-I` or `--non-interactive`/`--interactive`) that is `--interactive` by default.
The `configure-rabbitmq` command was introduced mainly to allow new users that set up
their profile with `verdi presto` before they set up RabbitMQ to upgrade their profile
to use the message broker. However, since the command is interactive, they would be
prompted for each of the options when running the command without
`-n`/`--non-interactive`. Users that don't understand these inputs will typically
want to set the defaults, so switching the modus operandi of the commmand to
be non-interactive will make life easier for these users. Users that _do_ want to set
different values than the defaults will understand the options of the command and
should be able to be able to provide them directly or via the interactive mode.
Currently the `verdi profile configure-rabbitmq` command doesn't give any feedback to
the user whether the provided options can successfully connect to the RabbitMQ server.
Here we adapt the `detect_rabbitmq_config` function to accept the broker configuration
as `**kwargs`, and use it to check if the provided options in the `configure-rabbitmq`
can successfully connect to the RabbitMQ server. A "success" message is printed if
we can connect to the server, else a warning is printed and the user is asked for
confirmation before proceeding to configure the broker.

A `--force` flag is also added to avoid asking for confirmation in case the command
is unable to connect to the broker.
@mbercx mbercx force-pushed the improve/cli-conf-rabbitmq branch from da8db25 to a49e79a Compare June 19, 2024 11:27
@mbercx
Copy link
Member Author

mbercx commented Jun 19, 2024

@sphuber the NON_INTERACTIVE option has been reinstated, commit messages updated.

@mbercx mbercx requested a review from sphuber June 19, 2024 11:29
@sphuber
Copy link
Contributor

sphuber commented Jun 19, 2024

@sphuber the NON_INTERACTIVE option has been reinstated, commit messages updated.

Fantastic, thanks a lot for going through that effort, much appreciated

@sphuber sphuber merged commit c2ca642 into aiidateam:main Jun 19, 2024
12 checks passed
@mbercx mbercx deleted the improve/cli-conf-rabbitmq branch June 19, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/critical-blocking must be resolved before next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants