feat(snapshot): add ProbeSource interface with FileProbeSource and CachedProbeSource#32
Open
davidbirdsong wants to merge 1 commit into
Conversation
…chedProbeSource Defines a ProbeSource abstraction over probe data so the Pulumi provider can obtain the full probe list without assuming a pre-fetched file exists. FileProbeSource reads from a fixed path with no freshness logic. Used by CLI tests and any caller that manages its own refresh lifecycle. CachedProbeSource is a read-through cache backed by a file on disk. It serves probes from cache when fresh (shared flock), and fetches from the RIPE Atlas API when stale or absent (exclusive flock with double-check to coalesce concurrent writers). TTL, cache path, and a ProbeRefreshDisabled flag for CI are all configurable. Depends on github.com/gofrs/flock. CLI commands (select, plan, apply) are wired to use CachedProbeSource via Deps.NewProbeSource. The select command treats the API key as optional so a fresh cache requires no credentials. selectAll is updated to accept []snapshot.Probe directly instead of snapshot.Snapshot.
Collaborator
Author
|
This change is part of the following stack: Change managed by git-spice. |
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.
Add ProbeSource interface with FileProbeSource and CachedProbeSource
Problem
The Pulumi provider needs to run probe selection but has no access to a pre-fetched snapshot file and cannot call the RIPE Atlas API on every resource operation. The CLI has the same latent issue:
snapshot.Loaderrors out if the file is missing rather than fetching transparently.What changed
New:
ProbeSourceinterface (pkg/snapshot/source.go)Two implementations:
FileProbeSourcereads from a fixed path with no freshness logic. ReturnsErrNotFoundif the file is absent. Used in CLI tests and by any caller that owns its own refresh lifecycle (e.g. afteratlasctl refresh).CachedProbeSourceis a read-through cache backed by a file on disk.flocklock, checksmtimeagainstTTL, reads and returns if fresh. No API call.ProbeRefreshDisabled boolprevents any API call. ReturnsErrRefreshDisabledwhen the cache is absent or stale. Intended for CI environments that supply the snapshot as a separate step.TTLandPathare configurable. Defaults:/tmp/atlasctl-probes.json, 2 hours.github.com/gofrs/flockfor cross-process and cross-goroutine lock coordination.Updated:
FakeProbeSource(pkg/snapshot/fake.go)FakeProbeSourceimplementsProbeSourcefor tests, matching the existingFakeClientpattern.Updated: CLI wire-up
Deps.NewProbeSourcefactory added todeps.go. Production default isCachedProbeSource. Tests useFileProbeSourceso snapshot files written bysaveSnapare read directly without TTL or API-call logic.planandapply: resolve API key first, constructCachedProbeSourcewith a snapshot client, reuse the key for the measurement client.select: treats the API key as optional (resolveAPIKeyOptional). A fresh cache requires no credentials; a stale or missing cache auto-refreshes if a key is available, otherwise errors clearly.selectAllsignature changed fromsnapshot.Snapshotto[]snapshot.Probesince only the probe list was ever used.Tests
pkg/snapshot/source_test.gocovers:FileProbeSource_ReturnsProbesFileProbeSource_MissingFileErrNotFoundFakeProbeSource_ReturnsProbes/_ErrorCachedProbeSource_FreshCache_NoFetchCachedProbeSource_MissingCache_FetchesAndWritesCachedProbeSource_StaleCache_FetchesAndWritesCachedProbeSource_RefreshDisabled_MissingCacheErrRefreshDisabledCachedProbeSource_RefreshDisabled_StaleCacheErrRefreshDisabledCachedProbeSource_RefreshDisabled_FreshCacheCachedProbeSource_NilClient_StaleCacheCachedProbeSource_ConcurrentCallersFetchProbescalled exactly oncecmd/atlasctl/cli_test.goadds compile-time interface assertions for all three implementations.Dependency
github.com/gofrs/flock v0.13.0added togo.mod.