-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Monitor} az monitor --help: Args-guided AAZ command tree loading for monitor module
#33024
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
Open
ReaNAiveD
wants to merge
13
commits into
Azure:dev
Choose a base branch
from
ReaNAiveD:optimize-monitor-aaz-loading
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a2055ad
Monitor help optimization
ReaNAiveD ae0a0be
Refactor monitor module loading configuration for full loading support
ReaNAiveD 9fe9d5e
Refactor monitor module imports and enhance autoscale table creation …
ReaNAiveD d6195a0
Fix help
ReaNAiveD 0a80767
Remove redundant actions and conditions arguments from monitor metric…
ReaNAiveD e5579dd
Fix styles
ReaNAiveD ef587ad
Add legacy fallback support
ReaNAiveD 5ea525d
Add header
ReaNAiveD c01eb71
Remove linter exclusions for re-registered commands after optimized-l…
ReaNAiveD c6e76a4
Add linter exclusion
ReaNAiveD 3fbb988
Update linter exclusions for monitor commands and remove obsolete ent…
ReaNAiveD 1746f5d
Fix refactor issues found manually
ReaNAiveD 90d5af6
Fix style
ReaNAiveD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -28,3 +28,4 @@ exclude = | |
| vendored_sdks | ||
| tests | ||
| */command_modules/*/aaz | ||
| */_legacy | ||
This file contains hidden or 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 hidden or 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 hidden or 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
55 changes: 55 additions & 0 deletions
55
src/azure-cli/azure/cli/command_modules/monitor/LEGACY_FALLBACK.md
This file contains hidden or 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,55 @@ | ||
| # Monitor Module: Legacy Fallback | ||
|
|
||
| ## Overview | ||
|
|
||
| The monitor module ships a vendored copy of the pre-refactor code in `_legacy/`. Users can switch to this snapshot via config if the refactored implementation causes issues: | ||
|
|
||
| ```bash | ||
| az config set monitor.use_legacy=true # enable legacy mode | ||
| az config set monitor.use_legacy=false # switch back to new mode (default) | ||
| ``` | ||
|
|
||
| A warning is logged each time legacy mode is active. | ||
|
|
||
| ## How It Works | ||
|
|
||
| In `__init__.py`, `MonitorCommandsLoader` reads the `monitor.use_legacy` config (default `false`): | ||
|
|
||
| - **New mode** — loads from `aaz/`, `operations/`, and `commands.py` using `load_aaz_command_table_args_guided`. | ||
| - **Legacy mode** — loads from `_legacy/aaz/`, `_legacy/commands.py` using `load_aaz_command_table`. Arguments come from `_legacy/_params.py`. | ||
|
|
||
| The `_legacy/` folder is a frozen snapshot extracted from the `dev` branch. All absolute imports were rewritten from `azure.cli.command_modules.monitor.` to `azure.cli.command_modules.monitor._legacy.`. | ||
|
|
||
| ## Known Adjustments | ||
|
|
||
| - **`_legacy/_params.py`**: Removed `monitor metrics alert update` argument registrations (lines for `add_actions`, `remove_actions`, `add_conditions`, `remove_conditions`) because the AAZ `MetricsAlertUpdate._build_arguments_schema` already defines them, and the old-style `action=MetricAlertAddAction` overrides corrupt AAZ argument parsing. | ||
| - **Tests**: `test_monitor_general_operations.py` mocks `gen_guid` at both `azure.cli.command_modules.monitor.operations.monitor_clone_util` and `azure.cli.command_modules.monitor._legacy.operations.monitor_clone_util` so tests pass in either mode. | ||
| - **Linting**: `_legacy/` is excluded via `pylintrc` (`ignore` list) and `.flake8` (`exclude` list). | ||
|
|
||
| ## Dropping Legacy Support | ||
|
|
||
| When legacy mode is no longer needed: | ||
|
|
||
| 1. **Delete the `_legacy/` folder**: | ||
| ```bash | ||
| rm -rf src/azure-cli/azure/cli/command_modules/monitor/_legacy/ | ||
| ``` | ||
|
|
||
| 2. **Simplify `__init__.py`** — remove `_use_legacy`, `_load_legacy_command_table`, and the dispatch in `load_command_table` / `load_arguments`. Inline `_load_new_command_table` as the sole `load_command_table`: | ||
| ```python | ||
| # Remove these | ||
| _CONFIG_SECTION = 'monitor' | ||
| _USE_LEGACY_CONFIG_KEY = 'use_legacy' | ||
| self._use_legacy = ... | ||
| def _load_legacy_command_table(self, args): ... | ||
|
|
||
| # Keep only _load_new_command_table logic directly in load_command_table | ||
| ``` | ||
|
|
||
| 3. **Clean up tests** — remove the second `mock.patch` line for `_legacy` in `test_monitor_general_operations.py`: | ||
| ```python | ||
| # Remove this line from each mock.patch block: | ||
| mock.patch('azure.cli.command_modules.monitor._legacy.operations.monitor_clone_util.gen_guid', ...) | ||
| ``` | ||
|
|
||
| 4. **Revert linter config** — remove `_legacy` from `pylintrc` `ignore` and `*/_legacy` from `.flake8` `exclude`. |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.