Skip to content

{AKS} az aks alert-config: Add commands to manage alert configurations - #10155

Open
Matheus Mortatti (mamortat) wants to merge 10 commits into
Azure:mainfrom
mamortat:feat/aks-alert-config-pr
Open

{AKS} az aks alert-config: Add commands to manage alert configurations#10155
Matheus Mortatti (mamortat) wants to merge 10 commits into
Azure:mainfrom
mamortat:feat/aks-alert-config-pr

Conversation

@mamortat

@mamortat Matheus Mortatti (mamortat) commented Jul 28, 2026

Copy link
Copy Markdown

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes
⚠️ None
⚠️Azure CLI Extensions Breaking Change Test
⚠️aks-preview
rule cmd_name rule_message suggest_message
⚠️ 1011 - SubgroupAdd aks alert-config sub group aks alert-config added

Ready for review: the command flow and replay coverage were verified against
eastus2euap using API version 2026-05-02-preview.

test_aks_alert_config_cmds now has a committed cassette and passes offline replay. The
scenario uses Disabled mode while Managed alert materialization is blocked by a separate
RP metric-name mismatch (etcd_database_used_size_percentage versus
etcd_database_usage_percentage).

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

az aks alert-config add|update|delete|show|list

Description

Adds the az aks alert-config command group to the aks-preview extension, exposing the
alertConfigurations child resource introduced in API version 2026-05-02-preview
(spec: Azure/azure-rest-api-specs#44598).

The vendored SDK already ships AlertConfigurationsOperations as of #10143, so this PR is
purely the command surface.

az aks alert-config add    -g RG --cluster-name C -n NAME --mode Managed|Disabled \
                           [--action-group-id ID] [--no-wait]
az aks alert-config update -g RG --cluster-name C -n NAME [--mode ...] \
                           [--action-group-id ID] [--no-wait]
az aks alert-config delete -g RG --cluster-name C -n NAME [--yes] [--no-wait]
az aks alert-config show   -g RG --cluster-name C -n NAME
az aks alert-config list   -g RG --cluster-name C

Implementation follows the existing az aks jwtauthenticator pattern.

Design notes

The resource has two writable properties, mode and notification.actionGroupId. Per the
swagger, properties.required = [mode, notification] and
AlertNotification.required = [actionGroupId].

  • --action-group-id is optional. The notification object is always emitted, with
    actionGroupId set to the supplied value or "", so the required key is never absent.
    The RP accepts an empty value.
  • update performs a read-modify-write. The API is PUT-only and both properties are
    required, so update GETs the existing configuration and merges, letting callers change
    one property at a time. An omitted --action-group-id preserves the current value; an
    explicit --action-group-id "" clears it.
  • update on a missing configuration raises ResourceNotFoundError pointing at
    az aks alert-config add rather than silently creating one.
  • --action-group-id is validated client-side to be a
    Microsoft.Insights/actionGroups resource ID before any network call.

Validation

  • azdev style aks-preview
  • azdev linter --include-whl-extensions aks-preview
  • python scripts/ci/test_index.py -q
  • Required PR checks across supported Python versions
  • Live add/show/list/update/delete flow in eastus2euap
  • Recorded and replayed test_aks_alert_config_cmds

The targeted suite passes 26 tests: the replay scenario plus 25 tests in
test_alert_configuration.py. The command table, argument registry, validators, serialized
request bodies, read-modify-write behavior, action-group clearing behavior, and complete CRUD
replay flow are covered.

Replay-test coverage

test_aks_alert_config_cmds exercises add → show → list → update → delete and is pinned to
eastus2euap with preserve_default_location=True. The cassette is committed and the test no
longer uses @live_only().

The alert-config operations are routed to the eastus2euap canary with the AKS Early Bird
header, where the subscription-tenant selection fix is deployed. The scenario records
Disabled mode, including clearing only the action group while preserving the mode through
the read-modify-write update path.

Managed mode is not part of the cassette yet because the RP alert definition requests
etcd_database_used_size_percentage, while Azure Monitor publishes
etcd_database_usage_percentage. The unit tests continue to cover Managed-mode request
serialization independently of that service-side issue.

Per the guidance block at the top of HISTORY.rst, this PR adds an entry under Pending
without bumping VERSION in setup.py.

Copilot AI review requested due to automatic review settings July 28, 2026 19:44
@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi Matheus Mortatti (@mamortat),
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new az aks alert-config command group to the aks-preview extension to manage the AKS alertConfigurations child resource (API version 2026-05-02-preview), including client-side validation, table output formatting, and tests.

Changes:

  • Introduces az aks alert-config add|update|delete|show|list commands wired to the vendored AlertConfigurationsOperations.
  • Adds --action-group-id validation and table transformers for list/show output.
  • Adds unit tests for validators/formatting/internal request shaping and a scenario test covering add→show→list→update→delete.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/aks-preview/HISTORY.rst Adds a Pending changelog entry for the new command group.
src/aks-preview/azext_aks_preview/alertconfiguration.py Implements internal add/update helpers that construct the SDK models and perform PUT semantics.
src/aks-preview/azext_aks_preview/_client_factory.py Adds a client factory for alert_configurations.
src/aks-preview/azext_aks_preview/commands.py Registers the new aks alert-config command group and hooks up custom commands + table transformers.
src/aks-preview/azext_aks_preview/custom.py Adds custom wrappers for alert-config add/update/delete/show/list.
src/aks-preview/azext_aks_preview/_params.py Registers arguments for aks alert-config including enum --mode and validator for --action-group-id.
src/aks-preview/azext_aks_preview/_validators.py Adds validate_action_group_id to enforce Microsoft.Insights/actionGroups resource IDs.
src/aks-preview/azext_aks_preview/_format.py Adds table transformers for alert-config show/list.
src/aks-preview/azext_aks_preview/_help.py Adds help text and examples for the new command group and commands.
src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py Adds unit tests for validator behavior, table formatting tolerance, and add/update internal request construction.
src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Adds a scenario test for the new commands (live/recorded test flow).

Comment thread src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py
Comment thread src/aks-preview/azext_aks_preview/alertconfiguration.py
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Comment thread src/aks-preview/azext_aks_preview/alertconfiguration.py
Comment thread src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py
Matheus Mortatti and others added 4 commits July 29, 2026 12:09
Add the `az aks alert-config` command group to the aks-preview extension,
exposing the alertConfigurations child resource introduced in API version
2026-05-02-preview.

Commands:
  az aks alert-config add/update/delete/show/list

The resource has two writable properties, mode (Managed|Disabled) and
notification.actionGroupId. Since the API is PUT-only and both properties
are required, `update` performs a read-modify-write so callers can change
one property at a time. `--action-group-id` is optional and always emitted
(as an empty string when unset) to satisfy the required-key contract; an
explicit empty string clears it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The alertConfigurations RP endpoint is only deployed to selected regions.
Pin the scenario test to eastus2euap and set preserve_default_location so
AZURE_CLI_TEST_DEV_RESOURCE_GROUP_LOCATION cannot silently redirect the
recording run to a region that rejects the requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The AlertConfigurationPreview AFEC feature flag must be registered on the
test subscription and the RP-side toggle must be active. Both are limited
to eastus2euap/centraluseuap on allow-listed subscriptions today, so the
scenario cannot be recorded yet.

Without a cassette the test would evaluate in_recording as true and attempt
a live run in CI, so mark it live_only until the feature is enabled more
broadly and a recording can be added. This matches the existing treatment
of test_aks_create_and_update_with_managed_nat_gateway_v2.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A live run with the AlertConfigurationPreview flag registered got past the
feature gate but failed on the create call: the RP returns 202 for
PUT alertConfigurations, while the swagger declares only 200/201 for that
operation. The generated SDK therefore treats the 202 as an error and fails
deserializing the empty body.

Record the blocker in the live_only comment so the marker can be removed
once the spec and RP agree and the SDK is re-vendored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@mamortat
Matheus Mortatti (mamortat) marked this pull request as draft July 29, 2026 19:20
The RP contract issue is resolved: PUT alertConfigurations now returns 201
on create and 200 on update, both with the resource body and the
Azure-AsyncOperation header, verified live in eastus2euap against
api-version 2026-05-02-preview.

The scenario test still has no cassette, so it stays live_only to avoid
attempting a live run in CI. Update the comment so it reflects the actual
remaining blocker rather than the now-fixed status code mismatch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@mamortat
Matheus Mortatti (mamortat) marked this pull request as ready for review August 6, 2026 22:21
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Document that the recording toolchain works through the internal package proxy and that the remaining blocker is the RP cross-tenant token failure.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@coopercox-ms Cooper Cox (coopercox-ms) added the Azure Client Tools Agent Requested Request Azure Client Tools Agent testing and review label Aug 20, 2026
@azure-client-tools-agent

Copy link
Copy Markdown

Live test results — azdev test --live --series (changed test files only)

PASS

Selectors: test_aks_commands test_alert_configuration (extension)
PR head ref: feat/aks-alert-config-pr
PR head sha: c18fc165bb1289f27ad3fff5e3f82433a70bfa94
PR base ref: main
New test files in PR: true

Changed test files run
src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py
src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py

New test files
src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/32325353011

Last 80 lines of azdev output

=============
| Run Tests |
=============


=====================
| Discovering Tests |
=====================

/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:13640: SyntaxWarning: invalid escape sequence '\]'
  self.cmd('vmss application set -g {rg} -n {vmss} --app-version-ids {vid1} {vid2} --enable-automatic-upgrade True\]', checks=[
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:18: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_compute': '\{"providers":\["Microsoft.Compute"\]\}',
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:19: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_empty': '\{"providers":\[\]\}'
WARNING: 'test_aks_commands' exists in both 'azext_aks_preview' and 'acs'. Resolve using `azext_aks_preview.test_aks_commands` or `acs.test_aks_commands`Duplication exists in: 
	/home/runner/work/issue-sentinel/issue-sentinel/azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py
	/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py


test index updated: /home/runner/.azdev/env_config/home/runner/work/issue-sentinel/issue-sentinel/.venv/test_index/latest.json

Test on modules: test_aks_commands, test_alert_configuration

WARNING: RUNNING TESTS LIVE
WARNING: 'test_aks_commands' not found. If newly added, re-run with --discover
The tests are set to run against current profile "latest"
============================= test session starts ==============================
platform linux -- Python 3.12.14, pytest-9.1.1, pluggy-1.6.0 -- /home/runner/work/issue-sentinel/issue-sentinel/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/issue-sentinel/issue-sentinel/azure-cli-extensions
configfile: pytest.ini
plugins: forked-1.7.5, xdist-3.8.0
collecting ... collected 25 items

azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_empty_string_is_allowed PASSED [  4%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_none_is_allowed PASSED [  8%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_not_a_resource_id_is_rejected PASSED [ 12%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_valid_action_group_id_is_allowed PASSED [ 16%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_valid_action_group_id_is_case_insensitive PASSED [ 20%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestValidateActionGroupId::test_wrong_resource_type_is_rejected PASSED [ 24%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigTableFormat::test_list_format PASSED [ 28%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigTableFormat::test_show_format PASSED [ 32%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigTableFormat::test_show_format_tolerates_missing_fields PASSED [ 36%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigTableFormat::test_show_format_tolerates_null_notification PASSED [ 40%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigAdd::test_add_sends_mode_and_action_group PASSED [ 44%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigAdd::test_add_without_action_group_sends_empty_string PASSED [ 48%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigAdd::test_add_without_mode_raises PASSED [ 52%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigAdd::test_add_without_name_raises PASSED [ 56%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_action_group_only_preserves_mode PASSED [ 60%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_can_clear_action_group_with_empty_string PASSED [ 64%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_mode_only_preserves_action_group PASSED [ 68%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_on_missing_config_raises_cli_not_found PASSED [ 72%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_with_no_updatable_flags_raises PASSED [ 76%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigUpdate::test_update_without_name_raises PASSED [ 80%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigCustomWrappers::test_add_proceeds_when_config_absent PASSED [ 84%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigCustomWrappers::test_add_rejects_existing_config PASSED [ 88%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigCustomWrappers::test_delete_calls_begin_delete PASSED [ 92%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigCustomWrappers::test_list_calls_list_by_managed_cluster PASSED [ 96%]
azure-cli-extensions/src/aks-preview/azext_aks_preview/tests/latest/test_alert_configuration.py::TestAlertConfigCustomWrappers::test_show_calls_get PASSED [100%]

- generated xml file: /home/runner/work/issue-sentinel/issue-sentinel/test-output/results.xml -
============================== 25 passed in 0.86s ==============================

Posted by agent-assist live-test workflow.

@azure-client-tools-agent azure-client-tools-agent Bot added the azure-client-tools-agent Pull request reviewed by Azure Client Tools Agent label Aug 20, 2026

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated Review Summary

PR: {AKS} az aks alert-config: Add commands to manage alert configurations

  • CI checks: 28/28 completed checks passed, 0 failed, 0 pending.
  • Live test: dispatched live-test workflow run completed with success conclusion.

No issues found. This PR looks ready from an automated-validation standpoint.

@azure-client-tools-agent azure-client-tools-agent Bot removed the Azure Client Tools Agent Requested Request Azure Client Tools Agent testing and review label Aug 20, 2026
Comment thread src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Outdated
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Matheus Mortatti and others added 2 commits August 28, 2026 12:10
Record the alert configuration CRUD scenario against the eastus2euap canary and enable offline replay. Use Disabled mode while Managed alert materialization is blocked by the RP metric-name mismatch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Describe why the replay scenario uses Disabled mode without implying that replay coverage is missing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Comment on lines +627 to +636
def _get_alert_config_table_row(result):
"""Extract information from an alert configuration for table display."""
properties = result.get('properties') or {}
notification = properties.get('notification') or {}
return OrderedDict([
('name', result.get('name', '')),
('mode', properties.get('mode', '')),
('actionGroupId', notification.get('actionGroupId', '')),
('provisioningState', properties.get('provisioningState', '')),
])

@FumingZhang FumingZhang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix the failing CI checks. The default API version has been updated to 2026-06-02-preview, so you’ll need to either re-record the test case or replace all occurrences of 2026-05-02-preview with 2026-06-02-preview in the existing recording file.

21.0.0b12
++++++++
* Add `--allowed-subjects-from-file` to `az aks identity-binding create` and add a new `az aks identity-binding update` command to manage the `allowedSubjects` list on identity bindings.
* Add `az aks alert-config` commands to manage AKS-managed alert configurations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please choose a new version number or move your notes to the Pending section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad AKS Auto-Assign Auto assign by bot azure-client-tools-agent Pull request reviewed by Azure Client Tools Agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants