Repository navigation
feat: add an opt-in library store and fetch libraries concurrently - #255
Open
Yingjie Chen (Y1ngJ1eChen) wants to merge 1 commit into
Open
Yingjie Chen (Y1ngJ1eChen) wants to merge 1 commit into
Yingjie Chen (Y1ngJ1eChen) wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 55.87% 56.42% +0.55%
==========================================
Files 56 57 +1
Lines 5264 5485 +221
==========================================
+ Hits 2941 3095 +154
- Misses 2003 2056 +53
- Partials 320 334 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Qi Zhang (Zhangqi910)
requested review from
Akshay Rohilla (akshayrohilla) and
Shiva Sai Yeddlapuri (yeddlapurishivasai)
November 18, 2026 12:45
This was referenced Nov 20, 2026
Open
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
Two changes to how alzlib fetches libraries. Both target the time terraform-provider-alz spends in
ConfigureProvideron everyplanandapply(~33–37 s reported in Azure/Azure-Landing-Zones#4328), most of which is fetching libraries:FetchWithDependenciesfetches libraries and their dependencies up to four at a time. The result is still built by the same depth-first walk, so the order of the libraries (which decides which library overwrites another) and the errors are unchanged.ALZLIB_LIBRARY_STORE_ENABLED=trueoralzlib.LibraryStoreEnabled.Store(true), libraries that cannot change (ALZ Library members, and git URLs pinned to a commit SHA) are fetched once into<ALZLIB_DIR>/store. They are then reused by later calls, by other processes, and by later pipeline runs that cacheALZLIB_DIR. The store is disabled by default.Refs Azure/Azure-Landing-Zones#4328. Not "Fixes": the issue has four items across alzlib and terraform-provider-alz, and this PR is the alzlib part of Item 2 (see "Where this fits in Azure/Azure-Landing-Zones#4328" below).
Problem
alzlib.Instancein everyConfigure()(provider.go#L152-L153). The libraries therefore go to a new<ALZLIB_DIR>/<random>/<hash>directory each time, and nothing is reused between runs, or betweenplanandapply.FetchLibraryByGetterStringdeletes the destination and downloads the library with go-getter (initialize.go#L120-L159).fetchLibraryWithDependenciesfetches the libraries and their dependencies one at a time (initialize.go#L32-L79). Both are unchanged onmain.mainagainst the ALZ Library on GitHub, fetching takes 21.9 s forplatform/alz@2026.11.0+platform/amba@2026.10.0, and 28.2 s forplatform/slz@2026.11.0+platform/amba@2026.10.0(details under Testing).Changes
initialize.gofetchLibrariesWithDependencies: a concurrent prefetch (prefetchLibraries), then the depth-first walk of before (libraryWalk), with cycle detection. When the store is enabled,FetchAzureLandingZonesLibraryMemberandFetchLibraryByGetterStringuse it for libraries that cannot change; everything else is fetched as before (fetchLibraryToInstanceDir).library_store.go(new)LibraryStoreEnabled, which URLs are stored, the entry layout andfetch.json, the temporary directory and rename, a per-entry lock within a process, the rename retry on Windows, and credential redaction.metadata.goFetchWithDependenciesofLibraryReferences,AlzLibraryReferenceandCustomLibraryReferencecallsfetchLibrariesWithDependencies. Both reference types get an unexportedsetFS, so the walk can reuse a prefetched filesystem. TheLibraryReferenceinterface does not change.internal/environment/environment.goALZLIB_LIBRARY_STORE_ENABLED, read withstrconv.ParseBool.README.mdlibrary_store_test.go,fetch_with_dependencies_test.go,internal/environment/environment_test.go(new)metadata_test.goFetchWithDependenciestests assert the exact order (Equal) instead ofElementsMatch.How it works
Concurrent fetch, same order
prefetchLibrariesfetches the references and then, as soon as a library's metadata has been read, its dependencies, with at most four downloads at a time. Each library (byString()) is fetched once. Errors are not reported in this phase.libraryWalkthen walks the references exactly asfetchLibraryWithDependenciesdid, using the prefetched filesystems. The walk fetches anything that was not prefetched, including a library whose prefetch failed. It therefore returns the same libraries, in the same order, with the same errors as before.References created with
NewCustomLibraryReferenceFromFSare not fetched, as before.LibraryReferenceimplementations from outside this package are not prefetched; the walk fetches them as before.A circular dependency now fails with
circular dependency on library <reference>. Onmain, the walk fetches the cycle again and again until the context is cancelled or expires.Library store
The store is disabled by default. When it is enabled:
refis a full, 40-character commit SHA. Everything else (local directories, branches and tags of custom libraries, other getters) is fetched to<ALZLIB_DIR>/<Instance>/<hash>as before.<ALZLIB_DIR>/store/<SHA-224 of the go-getter URL>/holds the library inlib/and afetch.jsonmarker.ALZLIB_LIBRARY_GIT_URLgets its own entries.fetch.jsonrecords the URL without credentials (the URL's user information and thesshkeyparameter are redacted), the SHA-256 of the complete URL, the alzlib version and the fetch time. This lets the store be shared through a CI/CD cache.store/tmp-*, the marker is written, and the directory is renamed to the entry. Readers see either no entry or a complete one.lib/, is neither used nor changed. The library is fetched as when the store is disabled.<ALZLIB_DIR>/storeto clear it. Atmp-*directory left by an interrupted fetch is never used and can be deleted.Testing
All tests were run locally on Windows 11 with Go 1.27.4, and golangci-lint with
GOTOOLCHAIN=go1.25.2as in CI. CI is authoritative, in particular for directory renames, which behave differently on Linux.In-repo
go build ./...,go vet ./...andgo test ./...pass. The 7 tests that need Azure credentials also pass withaz login.-count=3), and with-race.golangci-lintv2.11.4 reports 0 issues in the changed packages.library_store_test.gocovers:fetch.json.fetch_with_dependencies_test.gocovers the order of the result, at most four downloads at a time, reuse of a prefetched library, a circular dependency, and that the first error in walk order is returned.End-to-end suite outside the repo
This suite ran against this branch and against
main(5461147), with local git repositories and a git wrapper that records every clone.-race.main, the 16 tests that check the new behaviour fail and the 24 tests that check unchanged behaviour pass.alzlibtool generate architectureandalzlibtool document libraryproduce byte-identical output formain, store disabled, cold store and warm store.terraform planwith that build,ALZLIB_LIBRARY_STORE_ENABLED=truein terraform's environment, and a local copy of the Library:Begin fetch library dependenciesandEnd fetch library dependencies, with no download.alz_library_referencesis identical to that of the provider built againstmain.Live, against github.com/Azure/Azure-Landing-Zones-Library on 2026-11-12 (fetch time, median of 3 runs):
mainplatform/alz@2026.11.0+platform/amba@2026.10.0platform/slz@2026.11.0+platform/amba@2026.10.0(3 libraries, slz depends on alz)maindownloads one library at a time. This PR downloaded up to two at a time (as many as these dependency graphs allow), and never more than four.main, store disabled, cold store and warm store:AlzLib.Init;alzlibtool document library;alzlibtool generate architecture ... alz, generated with a built-in definitions cache read from Azure.tmp-*directory. Four more processes then fetch from the store in 6.5–9.4 ms each, with no download.Backwards compatibility and upgrade impact
alzlib.LibraryStoreEnabledand theALZLIB_LIBRARY_STORE_ENABLEDenvironment variable. No signatures change, and theLibraryReferenceinterface is unchanged.FetchAzureLandingZonesLibraryMemberandFetchLibraryByGetterStringignoredstDirfor stored libraries. They return a filesystem under<ALZLIB_DIR>/store, which is shared between processes and must not be modified.Where this fits in Azure/Azure-Landing-Zones#4328
cache_file_save_enabledsaves an empty cacheConfigureProvidertakes ~33–37 s on every commandListBuiltInrequestsThis PR and #253 have no files in common.
Two suggestions of Item 2 are not in this PR:
depth=1for Library tags: it brought no measurable benefit. A bare clone of the Library repository (about 8 MB) took 4.1–4.4 s in full, and 3.8–4.3 s with--depth 1 --branch <tag>.Initand cache load: these belong in terraform-provider-alz and come with Item 1.Questions for reviewers
git ls-remote), or ALZ Library members must stay out of the store.alzlib.LibraryStoreEnabledandALZLIB_LIBRARY_STORE_ENABLED. Are these names fine? Should the store be enabled by default once a release has been in use for a while?Out of scope
planandapply), a provider setting for the store, and documentation on cachingALZLIB_DIRin CI/CD. Until there is a setting,ALZLIB_LIBRARY_STORE_ENABLED=truein the pipeline environment enables the store for a provider built with this alzlib.<ALZLIB_DIR>/<Instance>directories left by earlier runs.processor.Client.Processleaves.jsonand.yamlfiles that are not library assets, such asalz_library_metadata.json, open until the garbage collector closes them. On Windows they cannot be deleted while the process runs.Instanceshare a destination directory.Suggested release note