s3-orchestrator

di

import "github.com/afreidah/s3-orchestrator/internal/di"

Package di is the single wiring point for the orchestrator. It uses samber/do/v2 to register every store role, backend, worker, and transport handler as a lazy provider; consumers resolve their dependencies through the injector at the moment they need them.

Index

func IsRegistered

func IsRegistered[T any](inj do.Injector) bool

IsRegistered reports whether T has a provider registered in the injector or any ancestor scope. Cheap; does not invoke the constructor.

func NewInjector

func NewInjector(cfg *config.Config, mode string, logLevel *slog.LevelVar, logBuffer *telemetry.LogBuffer) do.Injector

NewInjector creates and configures the DI container. Required providers are always registered. Optional providers register only when their config section is enabled - do.Invoke returns an error for disabled services, which callers use to detect absence.

func NewLifecycleService

func NewLifecycleService(manager lifecycleOps, locker tickrunner.AdvisoryLocker) lifecycle.Runner

NewLifecycleService constructs the lifecycle-expiration background service. Lives in DI (rather than next to a worker) because the work surface is on *proxy.BackendManager itself (via the lifecycleOps consumer interface) - there is no dedicated worker type.

func NewUsageFlushService

func NewUsageFlushService(manager usageFlushOps, locker tickrunner.AdvisoryLocker) lifecycle.Runner

NewUsageFlushService constructs the usage flush background service.

func ProvideAdminHandler

func ProvideAdminHandler(i do.Injector) (*admin.Handler, error)

ProvideAdminHandler creates the admin API handler.

func ProvideBackendManager

func ProvideBackendManager(i do.Injector) (*proxy.BackendManager, error)

ProvideBackendManager creates the central orchestration manager with the narrow per-role store interfaces supplied. Also installs a recovery listener on the DB breaker so the degraded-mode location cache is cleared the moment the DB transitions back to closed.

func ProvideBreakerRegistry

func ProvideBreakerRegistry(i do.Injector) (*breaker.Registry, error)

ProvideBreakerRegistry assembles the watchdog’s breaker registry from the database circuit breaker and the per-backend breakers produced during backend initialization. Centralizing membership here keeps the watchdog itself free of type-assertions and keeps DI as the single wiring point.

func ProvideBucketAuth

func ProvideBucketAuth(i do.Injector) (*auth.BucketRegistry, error)

ProvideBucketAuth creates the credential-to-bucket registry.

func ProvideCleanupWorker

func ProvideCleanupWorker(i do.Injector) (*worker.CleanupWorker, error)

ProvideCleanupWorker constructs the cleanup-queue worker.

func ProvideDatabaseBreaker

func ProvideDatabaseBreaker(i do.Injector) (*breaker.CircuitBreaker, error)

ProvideDatabaseBreaker constructs the shared *breaker.CircuitBreaker every driver-level SQL statement forwards calls through.

func ProvideDrainManager

func ProvideDrainManager(i do.Injector) (*drain.Manager, error)

ProvideDrainManager constructs the drain manager. Depends on BackendManager (drain.Core seam), the cleanup worker (for the cleanup-queue flush before backend deletion), and the wide MetadataStore for the object/quota/lifecycle role surfaces. The returned manager is wired onto BackendManager by di.WireManager so the provider itself stays free of mutation side effects.

func ProvideEncryptionAdmin

func ProvideEncryptionAdmin(i do.Injector) (core.EncryptionAdmin, error)

ProvideEncryptionAdmin aliases the wide MetadataStore as its EncryptionAdmin role for the admin HTTP handler’s key rotation and encrypt/decrypt batch ops.

func ProvideEncryptionProvider

func ProvideEncryptionProvider(i do.Injector) (encryption.KeyProvider, error)

ProvideEncryptionProvider creates the key provider for admin key rotation operations. Only registered when encryption is enabled.

func ProvideEncryptor

func ProvideEncryptor(i do.Injector) (*encryption.Encryptor, error)

ProvideEncryptor creates the envelope encryption engine.

func ProvideInstanceID

func ProvideInstanceID(_ do.Injector) (instanceid.ID, error)

ProvideInstanceID resolves a stable per-process identifier used as the claimed_by stamp on cleanup_queue rows. The identifier is generated once at first invoke and reused everywhere the value is needed.

func ProvideLifecycleAdmin

func ProvideLifecycleAdmin(i do.Injector) (core.LifecycleAdmin, error)

ProvideLifecycleAdmin aliases the wide MetadataStore as its LifecycleAdmin role for boot/shutdown migrations, schema checks, and Close.

func ProvideLifecycleManager

func ProvideLifecycleManager(i do.Injector) (*lifecycle.Manager, error)

ProvideLifecycleManager creates and registers all background services.

func ProvideLoginThrottle

func ProvideLoginThrottle(_ do.Injector) (*httputil.LoginThrottle, error)

ProvideLoginThrottle creates the per-IP login attempt throttle.

func ProvideMetadataStore

func ProvideMetadataStore(i do.Injector) (core.MetadataStore, error)

ProvideMetadataStore opens the configured driver, runs migrations, syncs quota limits, and returns the wide core.MetadataStore every consumer depends on. CB protection lives inside each driver’s DBTX/DB chokepoint, so this provider does no wrapping of its own.

func ProvideMetricsDeps

func ProvideMetricsDeps(i do.Injector) (metrics.Deps, error)

ProvideMetricsDeps aliases the wide MetadataStore as the metrics.Deps subset metrics.Collector uses to refresh Prometheus gauges.

func ProvideNotificationOutbox

func ProvideNotificationOutbox(i do.Injector) (core.NotificationOutbox, error)

ProvideNotificationOutbox aliases the wide MetadataStore as its NotificationOutbox role for the notifier worker.

func ProvideNotifier

func ProvideNotifier(i do.Injector) (*notify.Notifier, error)

ProvideNotifier creates the webhook notification system.

func ProvideObjectCache

func ProvideObjectCache(i do.Injector) (objcache.ObjectCache, error)

ProvideObjectCache creates the in-memory LRU object data cache.

func ProvideOverReplicationCleaner

func ProvideOverReplicationCleaner(i do.Injector) (*worker.OverReplicationCleaner, error)

ProvideOverReplicationCleaner constructs the over-replication cleanup worker.

func ProvidePendingReaper

func ProvidePendingReaper(i do.Injector) (*worker.PendingReaper, error)

ProvidePendingReaper constructs the pending-reaper worker. This provider is registered in NewInjector ONLY when the pending pattern is enabled, so reaching this function implies the feature is on (#830). Any nil dependency at this point is a wiring bug, not an intentional “feature off” signal - it surfaces as an error so Optional[*worker.PendingReaper] reports Failed instead of conflating it with Disabled.

func ProvideRateLimiter

func ProvideRateLimiter(i do.Injector) (*s3api.RateLimiter, error)

ProvideRateLimiter creates the per-IP rate limiter.

func ProvideRebalancer

func ProvideRebalancer(i do.Injector) (*worker.Rebalancer, error)

ProvideRebalancer constructs the rebalancer worker.

func ProvideReconciler

func ProvideReconciler(i do.Injector) (*worker.Reconciler, error)

ProvideReconciler constructs the bucket reconciler worker. Registered only in worker/all modes because reconciliation is a worker-side background task. Returns the reconciler so the lifecycle manager can register a service for it; the reconciler is also resolvable directly for the admin handler’s inspection endpoints.

func ProvideRedisCounterBackend

func ProvideRedisCounterBackend(i do.Injector) (*counter.RedisCounterBackend, error)

ProvideRedisCounterBackend creates the shared Redis counter backend.

func ProvideReplicator

func ProvideReplicator(i do.Injector) (*worker.Replicator, error)

ProvideReplicator constructs the replication worker.

func ProvideS3Server

func ProvideS3Server(i do.Injector) (*s3api.Server, error)

ProvideS3Server creates the S3-compatible HTTP handler.

func ProvideScrubber

func ProvideScrubber(i do.Injector) (*worker.Scrubber, error)

ProvideScrubber constructs the integrity-verification worker.

func ProvideUIHandler

func ProvideUIHandler(i do.Injector) (*ui.Handler, error)

ProvideUIHandler creates the web dashboard handler.

func WireAuditMetrics

func WireAuditMetrics()

WireAuditMetrics connects the audit event counter to Prometheus. Called from the main binary during startup, outside the injector.

func WireManager

func WireManager(inj do.Injector) error

WireManager resolves the BackendManager plus every required worker (as a smoke check that construction succeeded) and installs the drain manager onto the BackendManager. Returns the first error from resolving a required dependency; the optional PendingReaper Failed resolution is logged so a broken provider stays distinguishable from an intentionally absent one.

type BackendsResult

BackendsResult groups the outputs of backend initialization so multiple providers can resolve it without re-running construction.

type BackendsResult struct {
    Backends       map[string]backend.ObjectBackend
    Order          []string
    UsageLimits    map[string]core.UsageLimits
    MaxObjectSizes map[string]int64
    // Breakers is the per-backend circuit breakers produced when
    // BackendCircuitBreaker is enabled. Empty when CBs are disabled.
    // The watchdog registry consumes this so it never has to rediscover
    // breakers via type assertion at runtime.
    Breakers []breaker.StaleProbeResetter
}

func ProvideBackends

func ProvideBackends(i do.Injector) (*BackendsResult, error)

ProvideBackends initializes all configured storage backends, wrapping each with a per-backend circuit breaker when enabled.

type OptionalResult

OptionalResult carries the outcome of an Optional[T] lookup. Callers pick the field they care about: Value for the resolved instance, Resolution for the operational classification, Err for the failure detail when Resolution is Failed.

type OptionalResult[T any] struct {
    Value      T
    Resolution Resolution
    Err        error
}

func Optional

func Optional[T any](inj do.Injector) OptionalResult[T]

Optional resolves T as an optional dependency. Inspects the injector’s registered service list first so a missing provider is distinguished from a constructor failure: a Disabled result means the feature was never wired in this run mode, while a Failed result means a provider was wired but its constructor (or a transitive dependency it tried to resolve) returned an error.

func (OptionalResult[T]) Applied

func (r OptionalResult[T]) Applied() bool

Applied reports whether the provider resolved cleanly.

func (OptionalResult[T]) Disabled

func (r OptionalResult[T]) Disabled() bool

Disabled reports whether the underlying provider was not registered.

func (OptionalResult[T]) Failed

func (r OptionalResult[T]) Failed() bool

Failed reports whether the provider was registered but failed to construct (or one of its transitive dependencies failed).

type Resolution

Resolution classifies the outcome of an optional dependency lookup.

type Resolution string

const (
    // ResolutionDisabled means no provider was registered for T.
    ResolutionDisabled Resolution = "disabled"
    // ResolutionApplied means the provider resolved cleanly.
    ResolutionApplied Resolution = "applied"
    // ResolutionFailed means the provider was registered but construction failed.
    ResolutionFailed Resolution = "failed"
)

Generated by gomarkdoc