Skip to content

{AKS} Fix missing wait on LRO pollers in azuremonitormetrics helpers - #33734

Merged
Julie Zhu (yanzhudd) merged 1 commit into
Azure:devfrom
FumingZhang:fix/azuremonitormetrics-lro-wait
Aug 4, 2026
Merged

{AKS} Fix missing wait on LRO pollers in azuremonitormetrics helpers#33734
Julie Zhu (yanzhudd) merged 1 commit into
Azure:devfrom
FumingZhang:fix/azuremonitormetrics-lro-wait

Conversation

@FumingZhang

@FumingZhang FumingZhang commented Jul 15, 2026

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Related command
az aks create --sku automatic, az aks addon/Azure Monitor metrics enablement commands (any command path that calls ensure_azure_monitor_profile_prerequisites, e.g. create_dce/create_dcr/create_dcra/addon_put/create_default_mac/link_grafana_instance).

Description
create_dce, create_dcr, create_dcra, addon_put, create_default_mac, and link_grafana_instance (in azure.cli.command_modules.acs.azuremonitormetrics) all call begin_create_or_update/begin_create_or_update_by_id but never call .result()/.wait() on the returned poller before returning.

Because the generic ResourceManagementClient used here polls via a background thread, the code proceeds as soon as the initial PUT is accepted instead of waiting for the resource to actually finish provisioning.

This is invisible in VCR-recorded tests (responses replay instantly, so the background poller thread finishes almost immediately), but is exposed in live tests: azure-cli-testsdk's tearDown() asserts that no thread named "LROPoller" is still alive (scenario_tests/base.py). A live az aks create --sku automatic run (which always provisions DCE/DCR/DCRA/Grafana-link resources for Azure Monitor metrics) can leave one of these pollers still polling in the background after the command returns, failing that assertion, and more generally means the CLI can return control to the caller before these dependent resources are actually ready.

Fix: capture the poller returned by each begin_create_or_update/begin_create_or_update_by_id call and call .result() on it before returning, so callers only get control back once the resource has actually finished provisioning. No public interface/behavior changes other than the command now waiting for these ARM operations to complete.

Testing Guide

az aks create -g <rg> -n <name> --sku automatic --enable-hosted-system \
  --workspace-resource-id <log-analytics-workspace-id>

Before the fix, a live test run of any @live_only() scenario that creates a --sku automatic cluster (which always enables Azure Monitor metrics and calls the affected helpers) could fail in tearDown() with:

AssertionError: You need to call 'result' or 'wait' on all LROPoller you have created

After the fix, this teardown assertion should no longer trigger from these code paths, since each begin_create_or_update[_by_id] call is now fully awaited via .result().

History Notes
[AKS] Fix missing wait on LRO pollers when provisioning Azure Monitor metrics artifacts (DCE/DCR/DCRA/Grafana link) for az aks create --sku automatic


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

@azure-client-tools-bot-prd

Copy link
Copy Markdown
Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd

Copy link
Copy Markdown
Validation for Breaking Change Starting...

Thanks for your contribution!

@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

AKS

@FumingZhang

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

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

create_dce, create_dcr, create_dcra, addon_put, create_default_mac and
link_grafana_instance all call begin_create_or_update[_by_id] but never
call .result()/.wait() on the returned poller before returning. Since the
generic ResourceManagementClient used here polls via a background thread,
the calling code proceeds as soon as the initial PUT is accepted, without
waiting for the resource to actually finish provisioning.

This is normally invisible in VCR-recorded tests (responses replay
instantly), but is exposed in live tests: azure-cli-testsdk's tearDown()
asserts that no thread named "LROPoller" is still alive
(scenario_tests/base.py), which fails when a live 'az aks create --sku
automatic' run leaves one of these pollers still polling in the
background after the command returns.

Fix: capture the poller returned by each begin_create_or_update[_by_id]
call and call .result() on it before returning, so callers only get
control back once the resource has actually finished provisioning.
@FumingZhang
FumingZhang force-pushed the fix/azuremonitormetrics-lro-wait branch from 352bbdf to 4f9c713 Compare August 4, 2026 03:41
@FumingZhang
FumingZhang marked this pull request as ready for review August 4, 2026 04:25
@FumingZhang
FumingZhang requested a review from a team as a code owner August 4, 2026 04:25
Copilot AI lite review requested due to automatic review settings August 4, 2026 04:25
@FumingZhang

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 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

This PR addresses a reliability issue in the AKS Azure Monitor metrics provisioning helpers by ensuring ARM long-running operations (LROs) are fully awaited before returning, preventing background LROPoller threads from surviving past command completion in live scenarios.

Changes:

  • Capture the poller returned by begin_create_or_update[_by_id] and call .result() in multiple azuremonitormetrics helper paths (DCE/DCR/DCRA, default AMW, Grafana link).
  • Await the poller returned by managed_clusters.begin_create_or_update in addon_put.

Reviewed changes

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

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dcra_api.py Awaits DCRA create/update-by-id LRO via poller.result().
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dcr_api.py Awaits DCR create/update-by-id LRO via poller.result().
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dce_api.py Awaits DCE create/update-by-id LRO via poller.result().
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/create.py Awaits default AMW create/update-by-id LRO via poller.result().
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amg/link.py Awaits role assignment and Grafana update-by-id LROs via poller.result().
src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/addonput.py Awaits AKS managed cluster update LRO via poller.result().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"properties": {}
}
)
poller.result()
Comment on lines 119 to 120
except CLIError as e:
raise CLIError(e)
Comment on lines +25 to 28
poller = client.begin_create_or_update(cluster_resource_group_name, cluster_name, mc)
poller.result()
except Exception as e:
raise UnknownError(e)
@yanzhudd
Julie Zhu (yanzhudd) merged commit 3555a3f into Azure:dev Aug 4, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad AKS az aks/acs/openshift Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants