server

package
v1.40.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package server provides a reusable server implementation for Packhorse. It encapsulates the initialization and management of the main HTTP server and metrics server, along with their dependencies.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUpstreamURLRequired           = errors.New("upstream URL is required")
	ErrCacheDirRequired              = errors.New("cache directory is required")
	ErrUpstreamURLMustHaveSchemeHost = errors.New("upstream URL must include scheme and host")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Required fields
	UpstreamURL string
	CacheDir    string

	// Cache configuration
	MaxCacheSizeBytes int64
	MaxEntries        int64
	// MaxCacheIdleAge, if non-zero, enables a sliding TTL on cache entries.
	// Passed through to cache.Config.MaxIdleAge.
	MaxCacheIdleAge time.Duration

	// HTTP server timeouts (optional, will use sensible defaults if not set)
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration

	// Proxy configuration
	AddXForwardedFor bool

	// Object storage for packfile parser (optional)
	// If nil, base packfile registration API will be available but extraction will not occur
	BlobBucket *blob.Bucket

	// BlobBucketURL is the URL used to open the blob bucket (e.g., "gs://bucket-name/")
	// Used to convert full URIs to bucket-relative keys
	BlobBucketURL string

	// Allowlist gates which repositories flow through the caching path.
	// Repositories not allowed are proxied directly to the upstream.
	// If nil, all repositories are allowed (equivalent to a disabled allowlist).
	Allowlist *allowlist.Allowlist

	// Metrics (optional, will create PrometheusAppMetrics if not set)
	Metrics observability.AppMetrics
}

Config holds the configuration for the Packhorse server.

type Server

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

Server represents a Packhorse server instance with main, metrics, and health servers.

func New

func New(ctx context.Context, cfg Config, mainListener, metricsListener, healthListener net.Listener) (*Server, error)

New creates a new Packhorse server with the provided listeners. This allows callers to control the listening addresses (e.g., for random ports in tests).

func NewWithRandomPorts

func NewWithRandomPorts(ctx context.Context, cfg Config) (*Server, error)

NewWithRandomPorts creates a new server with random port allocation. This is primarily useful for testing.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the network address of the main server.

func (*Server) Drain added in v1.27.0

func (s *Server) Drain()

Drain marks the server as not ready so that Kubernetes fails the readiness probe and deregisters this instance from the Service endpoints. The servers keep accepting and serving requests; callers should wait for a drain period (see the drain_timeout config) before calling Shutdown, giving the endpoint deregistration time to propagate before new connections stop being accepted.

func (*Server) HealthAddr

func (s *Server) HealthAddr() net.Addr

HealthAddr returns the network address of the health server.

func (*Server) Metrics

func (s *Server) Metrics() observability.AppMetrics

Metrics returns the metrics instance for accessing metrics data.

func (*Server) MetricsAddr

func (s *Server) MetricsAddr() net.Addr

MetricsAddr returns the network address of the metrics server.

func (*Server) PrometheusManager

func (s *Server) PrometheusManager() *observability.PrometheusManager

PrometheusManager returns the Prometheus manager for accessing the registry.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all servers.

The health server is shut down last so that the readiness probe keeps reporting not-ready (see Drain) for the whole shutdown, rather than the endpoint disappearing before Kubernetes has finished draining traffic.

func (*Server) Start

func (s *Server) Start()

Start starts the main, metrics, and health servers in background goroutines.

Jump to

Keyboard shortcuts

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