dryrun

package
v1.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dryrun observes cache behaviour for a set of repositories without actually caching. Each observed request has its cache key recorded in a shadow store with the same sliding TTL the real cache uses, so metrics accurately report the hit / miss / coalesce rate the caching path would have produced. All requests are transparently proxied to upstream and no packfiles are written to disk. The dry-run allowlist reuses allowlist.Allowlist; the middleware's "enabled" check is `list.Bounded() && list.Contains(repo)`.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToCreateShadow = errors.New("failed to create dry-run shadow cache")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxEntries caps the number of keys the shadow tracks. Well over the
	// real cache's own MaxEntries so shadow evictions never fire before the
	// real cache's would; that way "would-hit" isn't an under-count.
	MaxEntries int64
	// MaxIdleAge mirrors the real cache's sliding TTL.
	MaxIdleAge time.Duration
	// OnEviction, if set, receives "ttl" or "size" for each eviction.
	OnEviction func(reason string)
	// OnEvictSize, if set, receives the evicted entry's repository and
	// size on every eviction, so a per-repo size gauge can be decremented
	// symmetrically with the AddDryRunShadowSizeBytes call made at Put time.
	OnEvictSize func(repo string, size int64)
}

Config configures a Shadow.

type Entry added in v1.46.0

type Entry struct {
	Repository string
	SizeBytes  int64
}

Entry is the value stored per shadow key. It carries just enough metadata to attribute an eviction back to its repository so a per-repo size gauge stays balanced.

type Shadow

type Shadow struct {
	// contains filtered or unexported fields
}

Shadow is a byte-free stand-in for the real cache. It tracks whether a cache key would currently be a hit, applying the same sliding TTL policy the real cache uses so hit-rate metrics reflect real eviction behaviour. The stored value carries the observed response size and owning repository so evictions can decrement a per-repo size gauge; no packfile bytes are ever written to disk.

func NewShadow

func NewShadow(cfg Config) (*Shadow, error)

NewShadow builds a Shadow with the given sliding-TTL policy.

func (*Shadow) Has

func (s *Shadow) Has(ctx context.Context, key string) bool

Has reports whether the key is currently tracked. On a hit it also refreshes the entry's sliding TTL, matching the real cache's Get behaviour. The refresh is fire-and-forget: waiting for Ristretto's write buffer to drain would add latency to every hit on the request path, and eventual visibility of the refreshed TTL is fine because the next Has for the same key comes from a fresh HTTP request that takes far longer than the buffer flush.

func (*Shadow) Put

func (s *Shadow) Put(ctx context.Context, key string, entry Entry)

Put records the key with the configured sliding TTL and the observed entry metadata (repo + size). Waits for the Ristretto write to be observable so a follow-up Has call in the same request path (or a concurrent second request that arrives while the leader is finishing) sees the entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL