s3-orchestrator

infra

import "github.com/afreidah/s3-orchestrator/internal/proxy/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

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”.

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

func New

func New(cfg *Config) *BackendRuntime

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

func (c *BackendRuntime) Acct() *accounting.Recorder

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

func (c *BackendRuntime) AcquireAdmission(ctx context.Context) bool

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

func (c *BackendRuntime) AdmissionSem() chan struct{}

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

func (c *BackendRuntime) BackendOrder() []string

BackendOrder returns the configured backend ordering (worker.Ops contract).

func (*BackendRuntime) Backends

func (c *BackendRuntime) Backends() map[string]backend.ObjectBackend

Backends returns the backend map (worker.Ops contract).

func (*BackendRuntime) ClassifyWriteError

func (c *BackendRuntime) ClassifyWriteError(span trace.Span, operation string, err error) error

ClassifyWriteError translates store errors from write-path operations into S3-compatible errors and updates the tracing span.

func (*BackendRuntime) DeleteWithTimeout

func (c *BackendRuntime) DeleteWithTimeout(ctx context.Context, be backend.ObjectBackend, key string) error

DeleteWithTimeout deletes an object from a backend using the configured backend timeout.

func (*BackendRuntime) EligibleForWrite

func (c *BackendRuntime) EligibleForWrite(apiCalls, egress, ingress int64) []string

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

func (c *BackendRuntime) ExcludeDraining(eligible []string) []string

ExcludeDraining filters out backends that are currently draining.

func (*BackendRuntime) ExcludeUnhealthy

func (c *BackendRuntime) ExcludeUnhealthy(eligible []string) []string

ExcludeUnhealthy filters out backends whose circuit breaker is open and not probe-eligible.

func (*BackendRuntime) GetBackend

func (c *BackendRuntime) GetBackend(name string) (backend.ObjectBackend, error)

GetBackend returns the named backend, or an error if it doesn’t exist.

func (*BackendRuntime) GetWithTimeout

func (c *BackendRuntime) GetWithTimeout(ctx context.Context, be backend.ObjectBackend, key, rangeHeader string) (*backend.GetObjectResult, context.CancelFunc, error)

GetWithTimeout issues a GET against be using the configured backend timeout, returning the result and a cancel func the caller owns.

func (*BackendRuntime) HeadWithTimeout

func (c *BackendRuntime) HeadWithTimeout(ctx context.Context, be backend.ObjectBackend, key string) (*backend.HeadObjectResult, error)

HeadWithTimeout issues a HEAD against be using the configured backend timeout.

func (*BackendRuntime) IsDraining

func (c *BackendRuntime) IsDraining(name string) bool

IsDraining returns true if the named backend is currently being drained. Returns false when no drain manager is wired.

func (*BackendRuntime) Log

func (c *BackendRuntime) Log() *slog.Logger

Log returns the component-scoped logger; falls back to slog.Default() when *BackendRuntime was constructed without one.

func (*BackendRuntime) MaxObjectSize

func (c *BackendRuntime) MaxObjectSize(name string) int64

MaxObjectSize returns the per-backend max object size; 0 means unlimited.

func (*BackendRuntime) MetricsCollector

func (c *BackendRuntime) MetricsCollector() *metrics.Collector

MetricsCollector returns the wired metrics collector (nil if unset).

func (*BackendRuntime) RecordOperation

func (c *BackendRuntime) RecordOperation(operation, backend string, start time.Time, err error)

RecordOperation delegates to the metrics collector.

func (*BackendRuntime) ReleaseAdmission

func (c *BackendRuntime) ReleaseAdmission()

ReleaseAdmission returns a slot to the admission semaphore.

func (*BackendRuntime) RoutingStrategy

func (c *BackendRuntime) RoutingStrategy() config.RoutingStrategy

RoutingStrategy returns the configured routing strategy.

func (*BackendRuntime) SetDrainChecker

func (c *BackendRuntime) SetDrainChecker(d DrainChecker)

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

func (c *BackendRuntime) SetMetricsCollector(m *metrics.Collector)

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

func (c *BackendRuntime) StreamCopy(ctx context.Context, src, dst backend.ObjectBackend, key string) error

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

func (c *BackendRuntime) UpdateQuotaMetrics(ctx context.Context) error

UpdateQuotaMetrics refreshes Prometheus gauges from the metadata store.

func (*BackendRuntime) Usage

func (c *BackendRuntime) Usage() *counter.UsageTracker

Usage returns the usage tracker (worker.Ops contract).

func (*BackendRuntime) WithTimeout

func (c *BackendRuntime) WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

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 Config struct {
    Backends         map[string]backend.ObjectBackend
    Order            []string
    BackendTimeout   time.Duration
    Usage            *counter.UsageTracker
    RoutingStrategy  config.RoutingStrategy
    MaxObjectSizes   map[string]int64
    MetricsCollector *metrics.Collector
    AdmissionSem     chan struct{}
    Log              *slog.Logger
}

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.

type DrainChecker interface {
    IsDraining(name string) bool
}

Generated by gomarkdoc