Skip to content

[AKS] aks-preview: add --enable/--disable-control-plane-metrics#9855

Open
davidkydd wants to merge 12 commits into
Azure:mainfrom
davidkydd:dakydd/ccpmetricsga-20260202preview
Open

[AKS] aks-preview: add --enable/--disable-control-plane-metrics#9855
davidkydd wants to merge 12 commits into
Azure:mainfrom
davidkydd:dakydd/ccpmetricsga-20260202preview

Conversation

@davidkydd
Copy link
Copy Markdown

@davidkydd davidkydd commented May 7, 2026

Surface the new first-class API property
azureMonitorProfile.metrics.controlPlane.enabled (API version 2026-02-02-preview) so users can opt in/out of Azure Monitor managed Prometheus control plane metrics (kube-apiserver, etcd, etc.) without relying on the AFEC-gated preview.

  • Add --enable-control-plane-metrics on az aks create and az aks update, plus --disable-control-plane-metrics on az aks update.
  • Validate that --enable-control-plane-metrics requires Azure Monitor metrics to be enabled (either already on the cluster or via --enable-azure-monitor-metrics in the same command), and that enable and disable cannot be combined.
  • Wire the flags into the create (set_up_azure_monitor_profile) and update (update_azure_monitor_profile) decorator paths.
  • Bump extension to 20.0.0b9 and add HISTORY entry.

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

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Surface the new first-class API property
azureMonitorProfile.metrics.controlPlane.enabled (API version
2026-02-02-preview) so users can opt in/out of Azure Monitor managed
Prometheus control plane metrics (kube-apiserver, etcd, etc.) without
relying on the AFEC-gated preview.

- Add --enable-control-plane-metrics on `az aks create` and `az aks
  update`, plus --disable-control-plane-metrics on `az aks update`.
- Validate that --enable-control-plane-metrics requires Azure Monitor
  metrics to be enabled (either already on the cluster or via
  --enable-azure-monitor-metrics in the same command), and that enable
  and disable cannot be combined.
- Wire the flags into the create (set_up_azure_monitor_profile) and
  update (update_azure_monitor_profile) decorator paths.
- Bump extension to 20.0.0b7 and add HISTORY entry.
Copilot AI review requested due to automatic review settings May 7, 2026 08:29
@davidkydd davidkydd requested a review from FumingZhang as a code owner May 7, 2026 08:29
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented May 7, 2026

⚠️Azure CLI Extensions Breaking Change Test
⚠️aks-preview
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd aks create cmd aks create added parameter enable_control_plane_metrics
⚠️ 1006 - ParaAdd aks update cmd aks update added parameter disable_control_plane_metrics
⚠️ 1006 - ParaAdd aks update cmd aks update added parameter enable_control_plane_metrics

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 7, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the aks-preview extension to surface the new azureMonitorProfile.metrics.controlPlane.enabled API property (2026-02-02-preview) by adding CLI flags to enable/disable Azure Monitor managed Prometheus control plane metrics collection for AKS clusters.

Changes:

  • Added --enable-control-plane-metrics to az aks create / az aks update, and --disable-control-plane-metrics to az aks update.
  • Implemented decorator-context validation and wiring to set azure_monitor_profile.metrics.control_plane.enabled during create/update.
  • Bumped extension version to 20.0.0b7 and added release notes entry.

Reviewed changes

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

Show a summary per file
File Description
src/aks-preview/setup.py Bumps extension version to 20.0.0b7.
src/aks-preview/HISTORY.rst Adds release notes entry for the new flags.
src/aks-preview/azext_aks_preview/managed_cluster_decorator.py Adds new context getters/validation and wires control plane metrics into create/update Azure Monitor profile flows.
src/aks-preview/azext_aks_preview/custom.py Adds new parameters to aks_create / aks_update function signatures so they flow into raw parameters.
src/aks-preview/azext_aks_preview/_params.py Registers the new CLI arguments for aks create and aks update.
src/aks-preview/azext_aks_preview/_help.py Documents the new CLI flags in command help.

Comment on lines +4719 to +4724
# Enable control plane metrics if requested.
if self.context.get_enable_control_plane_metrics():
mc.azure_monitor_profile.metrics.control_plane = (
self.models.ManagedClusterAzureMonitorProfileMetricsControlPlane(enabled=True)
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a7b923c — set_up_azure_monitor_profile now calls get_enable_control_plane_metrics() unconditionally so passing --enable-control-plane-metrics without the parent flag raises RequiredArgumentMissingError on create instead of being silently ignored when _setup_azure_monitor_metrics is skipped.

Comment thread src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Comment on lines +7011 to +7033
# Handle enable / disable of control plane metrics independently of the parent metrics flag,
# so users can toggle control plane metrics on a cluster that already has metrics enabled.
if self.context.get_enable_control_plane_metrics():
if mc.azure_monitor_profile is None:
mc.azure_monitor_profile = self.models.ManagedClusterAzureMonitorProfile() # pylint: disable=no-member
if mc.azure_monitor_profile.metrics is None:
# Should not normally happen — validation requires metrics to be enabled — but guard
# against partially-populated profiles to avoid AttributeError.
mc.azure_monitor_profile.metrics = (
self.models.ManagedClusterAzureMonitorProfileMetrics(enabled=True) # pylint: disable=no-member
)
mc.azure_monitor_profile.metrics.control_plane = (
self.models.ManagedClusterAzureMonitorProfileMetricsControlPlane(enabled=True) # pylint: disable=no-member
)

if self.context.get_disable_control_plane_metrics():
if (
mc.azure_monitor_profile and
mc.azure_monitor_profile.metrics
):
mc.azure_monitor_profile.metrics.control_plane = (
self.models.ManagedClusterAzureMonitorProfileMetricsControlPlane(enabled=False) # pylint: disable=no-member
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 3f343fe — added 5 update-decorator tests covering: (1) enable-cp without parent flag raises RequiredArgumentMissingError, (2) enable-cp succeeds when AM metrics already on cluster, (3) enable-cp + disable-am-metrics raises MutuallyExclusiveArgumentError, (4) enable-cp + disable-cp together raises MutuallyExclusiveArgumentError, (5) disable-cp writes control_plane.enabled=False.

Comment thread src/aks-preview/azext_aks_preview/_help.py Outdated
Comment thread src/aks-preview/azext_aks_preview/_help.py Outdated
Comment thread src/aks-preview/HISTORY.rst Outdated
davidkydd added 8 commits May 12, 2026 16:38
…e-azure-monitor-metrics

Combining the two flags in the same command produced an inconsistent
payload (azureMonitorProfile.metrics.enabled=False AND
metrics.controlPlane.enabled=True). Validator now raises
MutuallyExclusiveArgumentError up-front. Addresses Copilot review
feedback on PR Azure#9855.
…even without parent flag

set_up_azure_monitor_profile now invokes get_enable_control_plane_metrics()
unconditionally so passing --enable-control-plane-metrics without
--enable-azure-monitor-metrics raises RequiredArgumentMissingError instead
of being silently ignored when _setup_azure_monitor_metrics is skipped.
Addresses Copilot review feedback on PR Azure#9855.
…e wording

Previous wording "Requires --enable-azure-monitor-metrics" was misleading
on update for clusters that already have Azure Monitor metrics enabled.
Updated to "Requires Azure Monitor metrics to be enabled (already
enabled or via --enable-azure-monitor-metrics)" for both 'aks create'
and 'aks update'. Addresses Copilot review feedback on PR Azure#9855.
The two unreleased bullets under Pending (cli core minimum bump,
--k8s-support-plan/--tier on upgrade) are part of 20.0.0b7. Moved into
the 20.0.0b7 section so the changelog reflects the actual shipping
version. Addresses Copilot review feedback on PR Azure#9855.
Adds 5 update-decorator tests covering the new validation branches and
update path:
- enable-control-plane-metrics without parent flag raises
- enable-control-plane-metrics succeeds when AM metrics already on cluster
- enable-control-plane-metrics + disable-azure-monitor-metrics raises
- enable + disable control-plane-metrics together raises
- disable-control-plane-metrics writes control_plane.enabled=False

Addresses Copilot review feedback on PR Azure#9855.
Linter (option_length_too_long, threshold 22) flagged
--enable-control-plane-metrics (31) and --disable-control-plane-metrics
(32) as too long. Adds --enable-cp-metrics and --disable-cp-metrics
short aliases on both 'aks create' and 'aks update'. Canonical long
names retained for backward compatibility.
Linter (missing_parameter_help) requires inline help text on c.argument
when options_list is set, since the YAML help block in _help.py is not
matched once the canonical option name is one of several. Adds inline
help= mirroring the YAML wording on all three argument definitions.
- Wrap inline help= strings in _params.py to satisfy line-too-long (C0301).
- Update _help.py entries to include the alias forms
  (--enable-cp-metrics, --disable-cp-metrics) so the linter's
  unrecognized_help_parameter_rule recognizes the canonical option list.
@davidkydd
Copy link
Copy Markdown
Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 9855 in repo Azure/azure-cli-extensions

@davidkydd
Copy link
Copy Markdown
Author

davidkydd commented May 13, 2026

@yonzhan @zhoxing-ms all copilot comments and gates are passing except for the azure build which I don't have permissions to trigger, could I get a review plz?

Keen to get this out to use for testing purposes, thanks!

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Copy Markdown
Member

@FumingZhang FumingZhang left a comment

Choose a reason for hiding this comment

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

lgtm, could you please add a scenario test to validate the change?

Adds live ScenarioTest coverage for --enable-control-plane-metrics and
--disable-control-plane-metrics on `az aks create` and `az aks update`:

Positive cases:
- create with --enable-azure-monitor-metrics + --enable-control-plane-metrics
  asserts azureMonitorProfile.metrics.controlPlane.enabled == True
- update flow on an AM-metrics-enabled cluster: enable then disable
  control plane metrics, asserting the controlPlane.enabled toggles

Negative cases (expect_failure=True):
- create --enable-control-plane-metrics without --enable-azure-monitor-metrics
- create --enable-control-plane-metrics together with --disable-azure-monitor-metrics
- create with both --enable-control-plane-metrics and --disable-control-plane-metrics
- update --enable-control-plane-metrics on a cluster lacking AM metrics

Addresses scenario-test request on PR Azure#9855.
@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@AKSCustomResourceGroupPreparer(
random_name_length=17, name_prefix="clitest", location="westus2"
)
def test_aks_create_with_control_plane_metrics(
Copy link
Copy Markdown
Member

@FumingZhang FumingZhang May 18, 2026

Choose a reason for hiding this comment

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

Re-queued live test to validate the change

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.

tests failed, please fix them according to the error msg

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

Labels

AKS Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants