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 Config

Config bundles every input *Core needs at construction. Exposed so callers (root proxy package, tests) can build a *Core 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 Core

Core composes the five capability services every proxy subpackage needs. Per-role store views live on the root-package BackendManager; *Core deliberately holds none.

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

func New

func New(cfg *Config) *Core

New constructs a *Core 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 *Core shares one instance that observes the same usage tracker and the (later-wired) metrics collector via the closure over c.RecordOperation.

func (*Core) Acct

func (c *Core) 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 (*Core) AcquireAdmission

func (c *Core) 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 (*Core) AdmissionSem

func (c *Core) 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 (*Core) BackendOrder

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

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

func (*Core) Backends

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

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

func (*Core) ClassifyWriteError

func (c *Core) 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 (*Core) DeleteWithTimeout

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

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

func (*Core) EligibleForWrite

func (c *Core) 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 (*Core) ExcludeDraining

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

ExcludeDraining filters out backends that are currently draining.

func (*Core) ExcludeUnhealthy

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

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

func (*Core) GetBackend

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

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

func (*Core) IsDraining

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

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

func (*Core) Log

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

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

func (*Core) MaxObjectSize

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

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

func (*Core) MetricsCollector

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

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

func (*Core) RecordOperation

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

RecordOperation delegates to the metrics collector.

func (*Core) ReleaseAdmission

func (c *Core) ReleaseAdmission()

ReleaseAdmission returns a slot to the admission semaphore.

func (*Core) RoutingStrategy

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

RoutingStrategy returns the configured routing strategy.

func (*Core) SetDrainChecker

func (c *Core) SetDrainChecker(d DrainChecker)

SetDrainChecker installs the drain manager after Core has been constructed; mirrors the historic post-construction WireDrain call on BackendManager.

func (*Core) SetMetricsCollector

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

SetMetricsCollector installs the metrics collector after Core construction. The collector depends on the usage tracker which is owned by *Core, so the collector is built after *Core and wired back in.

func (*Core) StreamCopy

func (c *Core) 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 (*Core) UpdateQuotaMetrics

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

UpdateQuotaMetrics refreshes Prometheus gauges from the metadata store.

func (*Core) Usage

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

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

func (*Core) WithTimeout

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

WithTimeout returns a context with the configured backend timeout applied.

type DrainChecker

DrainChecker reports whether a named backend is currently being drained. *Core consumes this so drain ownership can live in the drain subpackage while *Core filters write eligibility.

type DrainChecker interface {
    IsDraining(name string) bool
}

Generated by gomarkdoc