[Monitor] Fix #32631: az monitor log-analytics query: Add AzureChinaCloud/sovereign cloud Log Analytics query endpoint mapping - #34052
Conversation
…eChinaCloud/sovereign cloud Log Analytics query endpoint mapping * Initial plan * fix: add clear error message for Log Analytics endpoint in sovereign clouds and regression tests Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com> * fix: rename test cloud name to AzureCustomCloud for clarity Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The new error message remediation guidance references a az cloud update flag that is not actually supported, making the guidance misleading and not actionable.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves sovereign-cloud support for Log Analytics query by ensuring the Log Analytics data-plane endpoint is properly defined/validated and by adding regression coverage for endpoint values across public and sovereign clouds.
Changes:
- Add an explicit
has_endpoint_set('log_analytics_resource_id')guard incf_log_analytics_data_planeand raise a user-facing error when missing. - Add core regression tests asserting
log_analytics_resource_idvalues for Azure Public, China, and US Gov clouds. - Add VM module unit tests covering
cf_log_analytics_data_planebehavior across Public/China/USGov clouds and missing-endpoint scenarios.
File summaries
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/vm/_client_factory.py | Adds endpoint presence guard and constructs LogsQueryClient using the cloud’s Log Analytics endpoint. |
| src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_actions.py | Adds unit tests validating Log Analytics endpoint resolution and missing-endpoint error handling. |
| src/azure-cli-core/azure/cli/core/tests/test_cloud.py | Adds regression test ensuring Log Analytics endpoint values are set for public + sovereign clouds. |
Review details
Suppressed comments (1)
src/azure-cli/azure/cli/command_modules/vm/_client_factory.py:56
log_analytics_resource_idis user-configurable (custom clouds) and may include a trailing slash. Concatenatingendpoint + '/' + api_versioncan produce a double-slash path (e.g.,...//v1), which can break some HTTP stacks or signing logic. Normalizing the endpoint before appending the API version avoids this edge case.
api_version = 'v1'
endpoint = cli_ctx.cloud.endpoints.log_analytics_resource_id
return LogsQueryClient(cred, endpoint=endpoint + '/' + api_version, audience=endpoint)
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if not cli_ctx.cloud.endpoints.has_endpoint_set('log_analytics_resource_id'): | ||
| raise CLIError( | ||
| "The Log Analytics query data-plane endpoint is not configured for cloud '{cloud}'. " | ||
| "This feature may not be available in '{cloud}'. " | ||
| "If you believe this is an error, configure the endpoint with: " | ||
| "az cloud update --endpoint-log-analytics-resource-id <endpoint-url>".format( | ||
| cloud=cli_ctx.cloud.name | ||
| ) | ||
| ) |
| AZURE_US_GOV_CLOUD, | ||
| KNOWN_CLOUDS, | ||
| update_cloud, | ||
| CloudEndpointNotSetException, |
|
Monitor |
Live test results —
|
Live test results —
|
Live test results —
|
There was a problem hiding this comment.
Automated review summary
All checks passed:
- Upstream CI: 50/50 checks passed, 0 pending, 0 failed.
- Live test:
azdev testcompleted successfully for the changed test files (test_cloud.py,test_vm_actions.py). - Regression coverage: The production change in
vm/_client_factory.pyis covered by new/updated unit tests in the same PR (test_cloud.py::test_log_analytics_resource_id_sovereign_cloudsand the newTestLogAnalyticsDataPlaneClientcases), including a negative-path test for the missing-endpointCLIError. No coverage gap detected.
No blocking issues found by automated review skills (release-artifact, test-strength, scope-consistency, domain-edge-cases).
Risk assessment
16/100 · Low · High confidence
The Low rating is driven by public CLI behavior.
- Change scope: 3 changed files, 108 changed lines (
+106/-2), including 1 production file. - Affected components:
vm - Risk drivers: public CLI behavior (+18)
- Regression evidence: Changed regression tests are included, reducing risk.
- Confidence: High because changed-line patches were available for every production file.
- Required review: Owning-squad review is recommended for
vmbefore merge.
|
🔔 Routing this PR to @Azure/act-observability-squad. |
🤖 PR Validation — ️✔️ All clear
Description
Fixes #32631.
Related command
az vm monitor log showDescription
cf_log_analytics_data_planeaccessedendpoints.log_analytics_resource_iddirectly, surfacing the opaqueCloudEndpointNotSetExceptionfor any cloud where the endpoint isn't defined. The three production sovereign clouds (AzureCloud,AzureChinaCloud,AzureUSGovernment) already carry the correct values incloud.py; clouds that don't (e.g. custom or future sovereign clouds) previously gave no actionable guidance.Changes:
vm/_client_factory.py— Guardcf_log_analytics_data_planewithhas_endpoint_set()before accessing the endpoint. On failure, raise aCLIErrorthat names the active cloud and tells the user exactly how to configure the missing value:test_cloud.py— Regression test assertinglog_analytics_resource_idis set to the expected URL for all three production sovereign clouds.test_vm_actions.py— Unit tests forcf_log_analytics_data_plane: verifies correctLogsQueryClientconstruction for Public / China / USGov clouds, and that a cloud without the endpoint raises aCLIErrorcontaining the cloud name and remediation hint.Testing Guide
# Unit tests (no live service required) python -m unittest azure.cli.core.tests.test_cloud.TestCloud.test_log_analytics_resource_id_sovereign_clouds python -m unittest azure.cli.command_modules.vm.tests.latest.test_vm_actions.TestLogAnalyticsDataPlaneClientHistory Notes
[Monitor]
az vm monitor log show: Surface actionable error when the Log Analytics data-plane endpoint is not configured for the active cloud