{EventHubs} az eventhubs --help: Args-guided AAZ command tree loading for eventhubs module#33008
{EventHubs} az eventhubs --help: Args-guided AAZ command tree loading for eventhubs module#33008
az eventhubs --help: Args-guided AAZ command tree loading for eventhubs module#33008Conversation
️✔️AzureCLI-FullTest
|
|
Hi @ReaNAiveD, |
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
This PR introduces an args-guided AAZ command loader to avoid eager importing of the full AAZ package tree, and pilots it in the eventhubs command module to improve az eventhubs --help (and related help) performance.
Changes:
- Add
load_aaz_command_table_optimizedinazure-cli-coreto traverse AAZ packages based on CLI args and load only the relevant subtree (or full-load when requested). - Update
eventhubsto use the optimized loader with a config toggle, and refactor AAZ packages/operations to avoid package-level wildcard imports. - Adjust eventhubs operations to import AAZ command classes from concrete modules (e.g.,
._update) instead of relying on__init__.pyre-exports.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/eventhubs/init.py | Switch eventhubs to the optimized AAZ loader; add config toggle + warning. |
| src/azure-cli-core/azure/cli/core/aaz/_command.py | Implement the new args-guided optimized AAZ loader and helpers. |
| src/azure-cli-core/azure/cli/core/aaz/init.py | Export load_aaz_command_table_optimized from the AAZ public surface. |
| src/azure-cli/azure/cli/command_modules/eventhubs/operations/network_rule_set.py | Update AAZ imports to direct _update / _show modules. |
| src/azure-cli/azure/cli/command_modules/eventhubs/operations/namespace_custom.py | Update AAZ imports to direct _create / _update / _show / _delete modules. |
| src/azure-cli/azure/cli/command_modules/eventhubs/operations/event_hub_entity.py | Update AAZ imports to direct _update / _create modules. |
| src/azure-cli/azure/cli/command_modules/eventhubs/operations/app_group_custom_file.py | Update AAZ imports to direct _create / _update / _show modules. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/cluster/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/cluster/namespace/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/eventhub/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/eventhub/authorization_rule/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/eventhub/authorization_rule/keys/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/eventhub/consumer_group/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/georecovery_alias/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/georecovery_alias/authorization_rule/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/georecovery_alias/authorization_rule/keys/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/application_group/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/authorization_rule/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/authorization_rule/keys/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/network_rule_set/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/nsp_configuration/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/private_endpoint_connection/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/private_link_resource/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/schema_registry/init.py | Remove wildcard imports to prevent cascade imports. |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/eventhub/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/eventhub/authorization_rule/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/eventhub/authorization_rule/keys/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/namespace/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/namespace/authorization_rule/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
| src/azure-cli/azure/cli/command_modules/eventhubs/aaz/profile_2019_03_01_hybrid/eventhubs/namespace/authorization_rule/keys/init.py | Remove wildcard imports to prevent cascade imports (hybrid profile). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Try to import a module by relative name, return None on failure.""" | ||
| try: | ||
| return importlib.import_module(relative_name, package) | ||
| except (ModuleNotFoundError, ImportError): |
There was a problem hiding this comment.
_try_import_module currently catches ImportError as well as ModuleNotFoundError and silently returns None. This can mask real import-time failures inside existing modules (e.g., a bug or missing dependency within a command module) and result in commands/groups silently not being registered. Consider only swallowing ModuleNotFoundError (or checking the missing module name), and letting other ImportErrors propagate or at least logging them at debug level with the exception details.
| """Try to import a module by relative name, return None on failure.""" | |
| try: | |
| return importlib.import_module(relative_name, package) | |
| except (ModuleNotFoundError, ImportError): | |
| """Try to import a module by relative name, return None if the module is not found.""" | |
| try: | |
| return importlib.import_module(relative_name, package) | |
| except ModuleNotFoundError as ex: | |
| logger.debug("Module %s could not be imported from package %s: %s", relative_name, package, ex, exc_info=True) |
| if use_optimized and args and args[0:1] == ['eventhubs']: | ||
| logger.warning( | ||
| "The eventhubs module is using optimized command loading for improved performance. " | ||
| "If you encounter any issues, you can disable this by running: " | ||
| "az config set %s.%s=false", | ||
| _OPTIMIZED_LOADING_CONFIG_SECTION, _OPTIMIZED_LOADING_CONFIG_KEY) |
There was a problem hiding this comment.
The optimized-loading warning is emitted on every eventhubs invocation (any args starting with ['eventhubs']). This adds persistent stderr noise for normal command execution and can be disruptive for scripting/log parsing. Consider restricting it to help invocations (args contains --help/-h), emitting it only once per process, or downgrading to a debug message while the feature is enabled by default.
|
Close this experiment since the usage of this module is not enough for us to identify potential issues. |
Related command
az eventhubs --helpDescription
Introduces an optimized AAZ command loader (
load_aaz_command_table_optimized) that navigates the package tree guided by CLI args instead of importing all command modules eagerly. Applied to theeventhubsmodule as a pilot.What changed
_command.py:load_aaz_command_table_optimizedusespkgutil.iter_modules()to match CLI args against subpackages/command modules, loading only the targeted subtree. Helper functions_load_aaz_by_pkg,_get_pkg_children,_load_first_commandsupport the navigation.__init__.pyfiles: Removed wildcard imports (from ._create import *) from 26 eventhubs AAZ__init__.pyfiles to prevent cascade imports.._update import Update) instead of package-level imports.az config set eventhubs.optimized_loading=falsedisables the optimization (falls back to full load). Warning shown only for eventhubs commands.Performance — Hyperfine (10 runs, 3 warmups)
az eventhubs --helpaz eventhubs namespace --helpaz eventhubs namespace create --helpaz eventhubs eventhub --helpPerformance — VizTracer Breakdown (after warmup)
az eventhubs --helpload_aaz_command_table)EventhubCommandsLoader.load_command_tableaz eventhubs namespace create --helpload_aaz_command_table)EventhubCommandsLoader.load_command_tableRisk & Rollback
Users can disable the optimization without code changes:
The fallback uses the same optimized loader with
args=None(full load), ensuring compatibility with the gutted__init__.pyfiles.A warning message is added.

Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.