Repository navigation
fix: honor Options.Parallelism when fetching built-in policy definitions - #253
Open
Yingjie Chen (Y1ngJ1eChen) wants to merge 2 commits into
Open
Yingjie Chen (Y1ngJ1eChen) wants to merge 2 commits into
Yingjie Chen (Y1ngJ1eChen) wants to merge 2 commits into
Conversation
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 26, 2026 10:31 — with
GitHub Actions
Failure
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 26, 2026 10:31 — with
GitHub Actions
Error
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 26, 2026 10:31 — with
GitHub Actions
Error
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 28, 2026 07:44 — with
GitHub Actions
Failure
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 28, 2026 07:44 — with
GitHub Actions
Error
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 28, 2026 07:44 — with
GitHub Actions
Error
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 28, 2026 09:25 — with
GitHub Actions
Error
Yingjie Chen (Y1ngJ1eChen)
had a problem deploying
to
test
October 28, 2026 09:25 — with
GitHub Actions
Failure
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #253 +/- ##
==========================================
+ Coverage 50.75% 51.46% +0.70%
==========================================
Files 55 57 +2
Lines 5004 5320 +316
==========================================
+ Hits 2540 2738 +198
- Misses 2171 2293 +122
+ Partials 293 289 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Options.Parallelismis documented as "the number of parallel requests to make to Azure APIs when getting policy definitions and policy set definitions", but it was only validated inInit()and never used. Built-in policy definitions, policy set definitions and the definitions they reference were fetched one request at a time, andHierarchy.FromArchitecturefetched one management group at a time. Building thealzarchitecture without a cache makes ~700 ARM requests, soalz_architecturereads took minutes.This PR fetches them concurrently, bounded by
Options.Parallelism(default 10, which terraform-provider-alz uses), without changing which requests are made or what is loaded.Fixes Azure/Azure-Landing-Zones#4310
Changes
alzlib
getBuiltInPolicies,getBuiltInPolicySetsandensureReferencedPolicyDefinitionsrun witherrgroup+SetLimit(Parallelism).AllowOverwrite=false).az.mu; the lock only guards map access through the existing accessors.fetchMuserialises concurrentGetDefinitionsFromAzurecallers sharing oneAlzLib(e.g. severalalz_architecturedata sources in the provider). Previously they raced to fetch and add the same definitions.**Clientinitialisation, which would race under concurrency.az.policyDefinitions[name].Versions()without the lock and panicked on a missing entry; it now uses a locked accessor.Parallelism < 1is treated as 1 internally;Init()still rejects 0.Options.Parallelismdoc: same-name requests are serial;1restores serial fetching.golang.org/x/sync v0.18.0becomes a direct dependency. It is already selected by MVS, and thegodirective is unchanged.deployment
FromArchitectureprefetches the definitions of the whole architecture in oneGetDefinitionsFromAzurecall, in a deterministic order, so requests are spread across the configured parallelism instead of one management group at a time. Assignments that cannot be resolved are skipped by the prefetch and still reported byaddManagementGroupwith the existing error. The per-management-group call remains as a no-op fallback.tests
internal/testutil/fakearm: an in-process fake of the ARM built-in policy API (latency, failure injection, request and peak-concurrency counters).BenchmarkGetDefinitionsFromAzureSimulatedLatency.Behaviour notes
FromArchitecturefetch errors are now wrapped asHierarchy.FromArchitecture: getting policy definitions from Azure for architecture ...(inner error unchanged). terraform-provider-alz does not parse these strings.FromArchitecturenow happens before any management group is added. Previously the groups processed before the failing one remained in the hierarchy; callers discard the hierarchy on error.FromArchitecturefetches is now deterministic. Previously child management groups were visited in map order, so the number of requests (and, for a definition needed both as latest and as a constraint, which version was loaded first) could vary between runs.Parallelismabove 10 is not recommended: ARM throttling and per-request latency increase.Validation
go test ./...(incl. read-only Azure integration tests),go vetgolangci-lintv2.11.4 with Go 1.25.2 (--new-from-rev)-count=20go test -race -count=3on.,./deployment,./cache(Windows, MinGW-w64)make testraceis left to CIfetchMu/ remove name groupingTestGetDefinitionsFromAzureConcurrentCallers/...SharedDefinitionsFetchedOncemain(cbf351d)main(incl. a panic on the missing-version path); all 18 guards pass on bothLive Azure, read-only (uncached,
alzarchitecture,mainvs. this branch):mainBenchmarkFromArchitectureWithClient, benchstatalz_architectureReadDataSource interraform plan(provider v0.22.0, platform/alz 2026.10.0)alz_architecturedata sources in one planpolicy definition db048e65-…@1.*.* … does not exist in the library(concurrent-caller race)--from-cache)alzlibtool generate architectureoutput is byte-identical tomain: 334/334 files forintegrationtest/testdata/alzlib-2025-09-0and 320/320 forplatform/alz@2026.10.0, each with and without--for-alz-bicep.Follow-ups (not in this PR)
parallelismprovider attribute (it is hard-coded to 10) for throttled or constrained networks.