Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 15 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.

View Source
const DefaultInitialSyncTimeout = 5 * time.Minute

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. Replace publishes a whole new map; maps are never mutated after publication, so readers need no lock.

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 blocks until a first copy of the desired state is read; without one there is nothing safe to answer.

type WatcherConfig

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

Jump to

Keyboard shortcuts

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