server

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package server is the HAPTIC agent: an HTTP endpoint that owns one HAProxy pod's file tree and its runtime socket. It executes what the controller decided and reports truthfully; it makes no HAProxy decisions of its own.

Index

Constants

View Source
const (
	DefaultDrainQuietPeriod = 2 * time.Second
	DefaultDrainMaxWait     = 10 * time.Second
	MaxDrainWait            = 5 * time.Minute
)

Drain defaults. A terminating pod keeps its listeners until kube-proxy has stopped routing new connections to it; the pod cannot observe kube-proxy, but it can observe the effect, so the hook ends after a quiet period and never later than the bound, which must stay inside the termination grace period together with hard-stop-after.

View Source
const (
	DrainReasonQuiet       = "quiet"
	DrainReasonBound       = "bound"
	DrainReasonUnavailable = "unavailable"
	DrainReasonCancelled   = "cancelled"
)

Drain reasons reported to the hook and the log.

View Source
const DefaultReloadTimeout = api.MaxReloadMs * time.Millisecond

DefaultReloadTimeout bounds the wait for the new worker to answer after a reload. Past it the apply reports what it knows rather than blocking.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseDir           string
	ConfigFile        string
	MasterSocket      string
	WorkerSocket      string
	StateFile         string
	Listen            string
	ReloadIntervalMin time.Duration
	// ReloadTimeout bounds one reload. Zero means DefaultReloadTimeout.
	ReloadTimeout time.Duration
	Username      string
	Password      string
	TLS           *transportsecurity.Source
	AgentVersion  string
	Logger        *slog.Logger
	Registry      *prometheus.Registry
	// DrainSocket is the unix socket path of GET /drain; empty disables it.
	DrainSocket string
	// AdminSocket exposes read-only state through the pod's filesystem permissions.
	AdminSocket string
	// DrainQuietPeriod ends the drain once no traffic frontend accepted a new
	// connection for this long; DrainMaxWait bounds the whole drain.
	DrainQuietPeriod time.Duration
	DrainMaxWait     time.Duration
	// DrainIgnoreFrontends names frontends whose connections are not traffic
	// (probes, scrapes); the chart passes its status frontend.
	DrainIgnoreFrontends []string
}

Config is everything the agent needs to run.

type DrainResult

type DrainResult struct {
	// Reason is why the drain ended: quiet, bound, unavailable (the worker no
	// longer answers, so there is nothing to keep open) or cancelled.
	Reason string `json:"reason"`
	// Waited is how long the caller was held.
	Waited string `json:"waited"`
	// Connections is the last accepted-connection count seen on the traffic frontends.
	Connections uint64 `json:"connections"`
}

DrainResult is the answer of GET /drain on the drain socket.

type Metrics

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

Metrics is the agent's own Prometheus surface plus the invariant helper. Everything here is instance-based so a test registry stays isolated.

func NewMetrics

func NewMetrics(registry prometheus.Registerer, logger *slog.Logger) *Metrics

NewMetrics registers the agent's metrics on registry.

func (*Metrics) DeferredDeleteAbandoned

func (m *Metrics) DeferredDeleteAbandoned(kind string)

DeferredDeleteAbandoned implements cli.Observer.

func (*Metrics) DeferredDeleteDeferred

func (m *Metrics) DeferredDeleteDeferred(kind string)

DeferredDeleteDeferred implements cli.Observer.

func (*Metrics) DeferredDeleteDone

func (m *Metrics) DeferredDeleteDone(kind string)

DeferredDeleteDone implements cli.Observer.

func (*Metrics) DeferredDeleteSuperseded

func (m *Metrics) DeferredDeleteSuperseded(kind string)

DeferredDeleteSuperseded implements cli.Observer.

func (*Metrics) LastViolation

func (m *Metrics) LastViolation() string

LastViolation is the invariant that failed most recently, for /v1/state.

type Server

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

Server owns the tree, the runtime plumbing and the apply state machine.

func New

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

New builds the agent. It probes the mounts under the base directory and loads the state file, but it does not touch HAProxy: Start does that, and readiness is what reports it.

func (*Server) Addr

func (s *Server) Addr() string

Addr is the address the endpoint bound to, which is the resolved port when the configured address asked for any.

func (*Server) Ready

func (s *Server) Ready() bool

Ready reports whether startup initialisation finished.

func (*Server) Start

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

Start serves the API until ctx ends. Startup initialisation runs first and is what flips readiness; a failure there is retried, never fatal, because HAProxy may simply be slower to come up than the agent.

Jump to

Keyboard shortcuts

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