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 ¶
- Variables
- type Config
- type Server
- func (s *Server) Addr() net.Addr
- func (s *Server) Drain()
- func (s *Server) HealthAddr() net.Addr
- func (s *Server) Metrics() observability.AppMetrics
- func (s *Server) MetricsAddr() net.Addr
- func (s *Server) PrometheusManager() *observability.PrometheusManager
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start()
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewWithRandomPorts creates a new server with random port allocation. This is primarily useful for testing.
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 ¶
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 ¶
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.