
infra
Package infra exposes the proxy-package backend infrastructure (backend map, usage tracker, drain checker, metrics, admission, per-op timeouts) as an importable type so subpackages can share it without an import cycle back to the root proxy package.
Index
- type BackendRuntime
- func New(cfg *Config) *BackendRuntime
- func (c *BackendRuntime) Acct() *accounting.Recorder
- func (c *BackendRuntime) AcquireAdmission(ctx context.Context) bool
- func (c *BackendRuntime) AdmissionSem() chan struct{}
- func (c *BackendRuntime) BackendOrder() []string
- func (c *BackendRuntime) Backends() map[string]backend.ObjectBackend
- func (c *BackendRuntime) ClassifyWriteError(span trace.Span, operation string, err error) error
- func (c *BackendRuntime) DeleteWithTimeout(ctx context.Context, be backend.ObjectBackend, key string) error
- func (c *BackendRuntime) EligibleForWrite(apiCalls, egress, ingress int64) []string
- func (c *BackendRuntime) ExcludeDraining(eligible []string) []string
- func (c *BackendRuntime) ExcludeUnhealthy(eligible []string) []string
- func (c *BackendRuntime) GetBackend(name string) (backend.ObjectBackend, error)
- func (c *BackendRuntime) GetWithTimeout(ctx context.Context, be backend.ObjectBackend, key, rangeHeader string) (*backend.GetObjectResult, context.CancelFunc, error)
- func (c *BackendRuntime) HeadWithTimeout(ctx context.Context, be backend.ObjectBackend, key string) (*backend.HeadObjectResult, error)
- func (c *BackendRuntime) IsDraining(name string) bool
- func (c *BackendRuntime) Log() *slog.Logger
- func (c *BackendRuntime) MaxObjectSize(name string) int64
- func (c *BackendRuntime) MetricsCollector() *metrics.Collector
- func (c *BackendRuntime) RecordOperation(operation, backend string, start time.Time, err error)
- func (c *BackendRuntime) ReleaseAdmission()
- func (c *BackendRuntime) RoutingStrategy() config.RoutingStrategy
- func (c *BackendRuntime) SetDrainChecker(d DrainChecker)
- func (c *BackendRuntime) SetMetricsCollector(m *metrics.Collector)
- func (c *BackendRuntime) StreamCopy(ctx context.Context, src, dst backend.ObjectBackend, key string) error
- func (c *BackendRuntime) UpdateQuotaMetrics(ctx context.Context) error
- func (c *BackendRuntime) Usage() *counter.UsageTracker
- func (c *BackendRuntime) WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)
- type Config
- type DrainChecker
type BackendRuntime
BackendRuntime composes the five capability services every proxy subpackage needs. Per-role store views live on the root-package BackendManager; *BackendRuntime deliberately holds none. For which methods belong here versus on *BackendManager, see docs/style-guide.md “Where new methods live: infra.BackendRuntime vs *BackendManager”.
func New
New constructs a *BackendRuntime from cfg. The drain checker is wired post-construction via SetDrainChecker to break the BackendManager ↔ drain.Manager cycle. The accounting Recorder is built here so every consumer of *BackendRuntime shares one instance that observes the same usage tracker and the (later-wired) metrics collector via the closure over c.RecordOperation.
func (*BackendRuntime) Acct
Acct returns the shared accounting.Recorder. Consumers should call Acct().APICall / Egress / Ingress / Operation instead of reaching through Usage() and RecordOperation directly so the per-backend accounting rules stay centralised.
func (*BackendRuntime) AcquireAdmission
AcquireAdmission blocks until a slot is available, or returns false if ctx is cancelled. Returns true immediately when no semaphore is wired.
func (*BackendRuntime) AdmissionSem
AdmissionSem returns the underlying semaphore channel (nil if unwired). Callers that need the raw channel (split admission controllers) read this; the AcquireAdmission/ReleaseAdmission methods are preferred.
func (*BackendRuntime) BackendOrder
BackendOrder returns the configured backend ordering (worker.Ops contract).
func (*BackendRuntime) Backends
Backends returns the backend map (worker.Ops contract).
func (*BackendRuntime) ClassifyWriteError
ClassifyWriteError translates store errors from write-path operations into S3-compatible errors and updates the tracing span.
func (*BackendRuntime) DeleteWithTimeout
DeleteWithTimeout deletes an object from a backend using the configured backend timeout.
func (*BackendRuntime) EligibleForWrite
EligibleForWrite returns backends that are not draining, not circuit-broken, and within usage limits / max-object-size for the given operation. Composed pipeline of registry filters + usage filter so each capability owns its half of the decision.
func (*BackendRuntime) ExcludeDraining
ExcludeDraining filters out backends that are currently draining.
func (*BackendRuntime) ExcludeUnhealthy
ExcludeUnhealthy filters out backends whose circuit breaker is open and not probe-eligible.
func (*BackendRuntime) GetBackend
GetBackend returns the named backend, or an error if it doesn’t exist.
func (*BackendRuntime) GetWithTimeout
GetWithTimeout issues a GET against be using the configured backend timeout, returning the result and a cancel func the caller owns.
func (*BackendRuntime) HeadWithTimeout
HeadWithTimeout issues a HEAD against be using the configured backend timeout.
func (*BackendRuntime) IsDraining
IsDraining returns true if the named backend is currently being drained. Returns false when no drain manager is wired.
func (*BackendRuntime) Log
Log returns the component-scoped logger; falls back to slog.Default() when *BackendRuntime was constructed without one.
func (*BackendRuntime) MaxObjectSize
MaxObjectSize returns the per-backend max object size; 0 means unlimited.
func (*BackendRuntime) MetricsCollector
MetricsCollector returns the wired metrics collector (nil if unset).
func (*BackendRuntime) RecordOperation
RecordOperation delegates to the metrics collector.
func (*BackendRuntime) ReleaseAdmission
ReleaseAdmission returns a slot to the admission semaphore.
func (*BackendRuntime) RoutingStrategy
RoutingStrategy returns the configured routing strategy.
func (*BackendRuntime) SetDrainChecker
SetDrainChecker points the eligibility filter at the drain manager so IsDraining reflects live drain state. Called once the drain manager exists, since it is built after the runtime.
func (*BackendRuntime) SetMetricsCollector
SetMetricsCollector installs the metrics collector after BackendRuntime construction. The collector depends on the usage tracker which is owned by *BackendRuntime, so the collector is built after *BackendRuntime and wired back in.
func (*BackendRuntime) StreamCopy
StreamCopy reads an object from src and writes it to dst with timeouts applied to each leg. Returns a *backend.CopyError tagged with the failing phase.
func (*BackendRuntime) UpdateQuotaMetrics
UpdateQuotaMetrics refreshes Prometheus gauges from the metadata store.
func (*BackendRuntime) Usage
Usage returns the usage tracker (worker.Ops contract).
func (*BackendRuntime) WithTimeout
WithTimeout returns a context with the configured backend timeout applied.
type Config
Config bundles every input *BackendRuntime needs at construction. Exposed so callers (root proxy package, tests) can build a *BackendRuntime directly.
type DrainChecker
DrainChecker reports whether a named backend is currently being drained. *BackendRuntime consumes this so drain ownership can live in the drain subpackage while *BackendRuntime filters write eligibility.
Generated by gomarkdoc