state

package
v1.0.4 Latest Latest
Warning

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

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

Documentation

Overview

Package state holds the desired admin state for haproxy servers and keeps it in sync with consul KV. Keys below the prefix are agent-send identities ("backend/server"), values are agent-check replies. An absent key means ready.

Index

Constants

View Source
const (
	StateReady = "ready"
	StateDrain = "drain"
	StateMaint = "maint"
)

Health states (up, down, stopped, fail) are not accepted: server health belongs to haproxy's own checks, the control plane only sets admin state.

Variables

This section is empty.

Functions

func ValidValue

func ValidValue(v string) bool

ValidValue reports whether v is an agent-check reply this agent is willing to serve. haproxy caps weights at 256.

Types

type Store

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

Store is an in-memory copy of the desired state, so lookups never wait on consul.

func NewStore

func NewStore() *Store

func (*Store) Len

func (s *Store) Len() int

func (*Store) Lookup

func (s *Store) Lookup(identity string) (state string, found bool)

func (*Store) Replace

func (s *Store) Replace(entries map[string]string)

func (*Store) Synced

func (s *Store) Synced() bool

Synced reports whether at least one sync succeeded. Until then an empty lookup result would be indistinguishable from "everything ready".

type Watcher

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

Watcher keeps a Store in sync with a consul KV prefix using blocking queries.

func NewWatcher

func NewWatcher(cfg WatcherConfig) *Watcher

func (*Watcher) Name

func (w *Watcher) Name() string

func (*Watcher) Shutdown

func (w *Watcher) Shutdown(ctx context.Context) error

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context) error

Start fails when consul is unreachable: without a first copy of the desired state there is nothing safe to answer, and exiting lets the supervisor retry.

type WatcherConfig

type WatcherConfig struct {
	Consul     *consulapi.Client
	Prefix     string
	Store      *Store
	Logger     *slog.Logger
	Registerer prometheus.Registerer
	WaitTime   time.Duration
}

Jump to

Keyboard shortcuts

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