{Monitor} az monitor --help: Args-guided AAZ command tree loading for monitor module#33024
{Monitor} az monitor --help: Args-guided AAZ command tree loading for monitor module#33024
az monitor --help: Args-guided AAZ command tree loading for monitor module#33024Conversation
❌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
Optimizes az monitor --help (and nested help) performance by introducing an args-guided AAZ command tree loader that imports only the relevant command subtree, and by restructuring the monitor module’s custom AAZ commands into an operations/latest/ package tree to avoid eager imports.
Changes:
- Added
load_aaz_command_table_args_guided(args-guided loader) to selectively import AAZ command modules/packages. - Refactored monitor custom AAZ commands into
operations/latest/and updated call sites to import leaf modules (e.g.,._create,._update) instead of package-level__init__wildcard imports. - Removed many AAZ
__init__.pywildcard imports to prevent cascade imports and enable lazy loading.
Reviewed changes
Copilot reviewed 101 out of 101 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli-core/azure/cli/core/aaz/_command.py | Adds args-guided loader and helpers to trim imports to the requested command subtree. |
| src/azure-cli-core/azure/cli/core/aaz/init.py | Exposes the new args-guided loader from azure.cli.core.aaz. |
| src/azure-cli/azure/cli/command_modules/monitor/init.py | Switches monitor to args-guided loading for both aaz and operations trees with a config toggle. |
| src/azure-cli/azure/cli/command_modules/monitor/commands.py | Removes explicit custom AAZ registrations in favor of auto-discovery from operations tree. |
| src/azure-cli/azure/cli/command_modules/monitor/custom.py | Updates imports to use leaf AAZ modules (e.g., ._list) to avoid package-level eager imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/private_link_scope.py | Moves command classes out; keeps only helper validation with lazy imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/monitor_clone_util.py | Defers heavy imports and switches to leaf AAZ module imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/metric_alert.py | Removes moved class and defers heavy imports into function scope. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/log_analytics_workspace.py | Removes moved classes; updates to leaf AAZ imports and adds lazy imports in functions. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/log_analytics_linked_storage_account.py | Moves create class out; uses inner Update-derived classes with leaf AAZ imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/general_operations.py | Defers import of clone utilities to reduce module import cost. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/diagnostics_settings.py | Removes custom AAZ command classes; keeps shared helpers for latest ops tree wrappers. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/autoscale_settings.py | Removes custom AAZ classes; uses latest ops wrappers and defers imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/activity_log_alerts.py | Removes custom AAZ classes/registrations; keeps shared helpers and updates to leaf AAZ imports. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/action_groups_identity.py | Keeps only assign wrapper and switches to leaf AAZ module import. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/action_groups.py | Removes AAZ classes; keeps receiver parsing helper and defers ValidationError import. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/init.py | Adds package marker for operations latest tree (loading root). |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/init.py | Adds package marker for operations latest tree under monitor. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/private_link_scope/init.py | Adds marker/noqa init to support lazy discovery. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/private_link_scope/_create.py | Adds custom wrapper for private-link-scope create defaults. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/private_link_scope/private_endpoint_connection/init.py | Adds marker/noqa init to support lazy discovery. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/private_link_scope/private_endpoint_connection/_update.py | Adds custom wrappers for approve/reject + id validation + schema tweaks. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/metrics/init.py | Adds marker package header for metrics subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/metrics/alert/init.py | Adds marker/noqa init for metrics alert subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/metrics/alert/_update.py | Moves MetricsAlertUpdate wrapper with deferred imports into operations latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/init.py | Adds marker package header for log analytics subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/init.py | Adds marker/noqa init for workspace subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/table/init.py | Adds marker/noqa init for table subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/table/search_job/init.py | Adds marker/noqa init for search-job subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/table/search_job/_cancel.py | Moves search-job cancel validation wrapper to operations latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/linked_storage/init.py | Adds marker/noqa init for linked-storage subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/linked_storage/_create.py | Moves linked-storage create element format customization to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/data_export/init.py | Adds marker/noqa init for data-export subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/data_export/_create.py | Moves data-export destination validation/customization to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/data_export/_update.py | Moves data-export destination validation/customization to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/init.py | Adds marker/noqa init for diagnostic-settings subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_create.py | Moves diagnostic-settings create custom validation/arg wiring to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_delete.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_list.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_show.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_update.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/categories/init.py | Adds marker/noqa init for categories subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/categories/_list.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/categories/_show.py | Adds wrapper to inject shared resource args and parameter update logic. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/autoscale/init.py | Adds marker/noqa init for autoscale subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/autoscale/_list.py | Adds output adjustment wrapper for autoscale list. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/autoscale/_show.py | Adds output adjustment wrapper for autoscale show. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/autoscale/_update.py | Moves autoscale update wrapper (args schema + instance updates) to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/init.py | Adds marker package header for activity-log subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/init.py | Adds marker/noqa init for activity-log alert subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/_create.py | Moves activity-log alert create wrapper + validation to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/_update.py | Moves activity-log alert update wrapper + condition defaults to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/init.py | Adds marker package header for action-group subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/__cmd_group.py | Creates virtual subgroup header for action-group. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/_add.py | Adds add action-group wrapper with strict mode and webhook property processing. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/_remove.py | Adds remove action-group wrapper. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/scope/init.py | Adds marker package header for scope subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/scope/__cmd_group.py | Creates virtual subgroup header for scope. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/scope/_add.py | Adds scope add wrapper with reset option. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/scope/_remove.py | Adds scope remove wrapper. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/init.py | Adds marker/noqa init for action-group subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/_create.py | Moves action-group create wrapper + validation/table transformer to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/_update.py | Moves action-group update wrapper + receiver add/remove logic to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/identity/init.py | Adds marker/noqa init for identity subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/identity/_remove.py | Moves identity remove wrapper to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/identity/_show.py | Moves identity show wrapper to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/test_notifications/init.py | Adds marker/noqa init for test-notifications subtree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/action_group/test_notifications/_create.py | Moves test-notifications create wrapper + receiver parsing to latest tree. |
| src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/categories/_show.py | Adds category show wrapper using shared diagnostics_settings helpers. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/account/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/action_group/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/action_group/identity/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/action_group/test_notifications/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/activity_log/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/activity_log/alert/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/autoscale/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/dashboard/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/diagnostic_settings/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/diagnostic_settings/categories/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/diagnostic_settings/subscription/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/cluster/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/cluster/identity/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/query_pack/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/query_pack/query/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/data_export/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/identity/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/linked_service/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/linked_storage/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/pack/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/saved_search/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/table/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_analytics/workspace/table/search_job/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/log_profiles/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/metrics/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/metrics/alert/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/private_link_scope/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/private_link_scope/private_endpoint_connection/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/private_link_scope/private_link_resource/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
| src/azure-cli/azure/cli/command_modules/monitor/aaz/latest/monitor/private_link_scope/scoped_resource/init.py | Removes wildcard imports to prevent cascade imports; keeps minimal init. |
Comments suppressed due to low confidence (8)
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/diagnostic_settings/_create.py:1
- The error message references a flag name that doesn't match the argument defined earlier (
--export-to-resource-specific). This will confuse users troubleshooting CLI usage. Update the message to mention the correct option name and clarify that--workspaceis required when--export-to-resource-specificis set.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/data_export/_create.py:1 - Correct typo in help/error text: 'evenhug' should be 'event hub'.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/log_analytics/workspace/data_export/_update.py:1 - Correct typo in help/error text: 'evenhug' should be 'event hub'.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/autoscale/_update.py:1 - Typo in help text: 'numer' should be 'number'.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/_remove.py:1 - This is the
action-group removecommand, but the help text says 'to be added'. This is user-facing CLI help and should say 'to be removed' (or similar) to avoid misuse.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/scope/_add.py:1 - The
scope addcommand's--resethelp text references action groups/conditions, which appears unrelated to scopes. This should describe resetting scopes (e.g., removing existing scopes before adding the provided--scopevalues).
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/activity_log/alert/action_group/_add.py:1 - Raising a plain
ValueErrorhere is likely to produce a less user-friendly CLI failure mode than anAzCLIError-derived exception. Consider raisingValidationError(or a more specific CLI error type) so the CLI formats the error consistently and avoids exposing a Python exception type to end users.
src/azure-cli/azure/cli/command_modules/monitor/operations/latest/monitor/private_link_scope/private_endpoint_connection/_update.py:1 private_endpoint_connection/_update.pynow contains wrappers for delete/show as well as update-derived approve/reject. This makes the file name misleading and increases future discovery/maintenance cost. Consider splitting wrappers into_delete.py,_show.py, and_update.py(and keeping approve/reject in_update.py), aligning file names with the command operation they customize.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if use_optimized and args and args[0:1] == ['monitor']: | ||
| logger.warning( | ||
| "The monitor 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.
This will emit a warning for every az monitor ... invocation (not just --help), which may be noisy and could surprise users who treat warnings as actionable failures in automation logs. Consider reducing the level (e.g., info/debug), limiting it to help scenarios, or gating it behind a one-time marker (config/env) so it’s shown once per user/session.
Related command
az monitor --helpaz monitor foo bar --helpDescription
Introduces an optimized AAZ command loader (
load_aaz_command_table_args_guided) that navigates the package tree guided by CLI args instead of importing all command modules eagerly. Applied to themonitormodule (151 AAZ commands). Also restructures customized command classes into anoperations/latest/tree to eliminate eager imports incommands.py.Performance — Hyperfine (10 runs, 3 warmups, Windows)
az monitor --helpaz monitor log-analytics workspace --helpaz monitor metrics alert create --helpaz monitor diagnostic-settings create --helpPerformance — VizTracer Breakdown
az monitor --helpcommands.py load_command_tableMonitorCommandsLoader.load_command_tableaz monitor diagnostic-settings create --helpcommands.py load_command_tableMonitorCommandsLoader.load_command_tableWhat changed
Core (
_command.py)load_aaz_command_table_optimizedfunction + helpers (_load_aaz_by_pkg,_get_pkg_children,_load_first_command,_try_import_module,_register_from_module)pkgutil.iter_modules()to match CLI args against subpackages, loading only the targeted subtreeAAZ
__init__.pyfiles (33 files)from ._create import *) to prevent cascade importsDirect module imports (14 files)
._create,._updatemodules instead of package-level importsOperations tree (
operations/latest/, 26 new files)operations/*.pyfiles into a tree mirroring the AAZ structuretable_transformerin__init__(no more explicitcommand_table[...] =registrations)__cmd_group.pyfor virtual subgroups (activity-log alert action-group,activity-log alert scope)commands.pyreduced from ~35 explicit registrations to zeroLazy imports
antlr4,msrest.serialization,azure.mgmt.core.tools,azure.cli.command_modules.network.custom, grammar parsers from module-level to inside methodsAutoScaleProfileDelete,AutoScaleRuleCopy) bundled inside their wrapper functionsConfig toggle & rollback
Falls back to legecy loading — compatible with gutted
__init__.pyfiles.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.