Distinguish disabled from removed backend state; add make fixstyle
Add StateDisabled for operator-initiated disable, keeping StateRemoved for backends that disappear during a config reload. Previously both used StateRemoved, which was confusing: "removed" implies the backend no longer exists in config, but a disabled backend is still present and can be re-enabled on the fly. - health: add StateDisabled with String() "disabled", Disable() method with probe code "disabled". Record() rejects probes in all three inactive states (paused, disabled, removed). - checker: DisableBackend calls backend.Disable() instead of Remove(). - docs: healthchecks.md rewritten for pause (goroutine cancelled, not just results discarded), and separate disabled/removed state rows. user-guide.md updated to match. - Makefile: add fixstyle target (gofmt -w .).
This commit is contained in:
@@ -350,7 +350,7 @@ func (c *Checker) DisableBackend(name string) (BackendSnapshot, bool) {
|
||||
return BackendSnapshot{Health: w.backend, Config: w.entry}, true
|
||||
}
|
||||
maxHistory := c.cfg.HealthChecker.TransitionHistory
|
||||
t := w.backend.Remove(maxHistory)
|
||||
t := w.backend.Disable(maxHistory)
|
||||
slog.Info("backend-disable", "backend", name)
|
||||
c.emitForBackend(name, w.backend.Address, t, c.cfg.Frontends)
|
||||
w.cancel()
|
||||
|
||||
@@ -310,8 +310,8 @@ func TestEnableDisable(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatal("DisableBackend: not found")
|
||||
}
|
||||
if b.Health.State != health.StateRemoved {
|
||||
t.Errorf("after disable: state=%s, want removed", b.Health.State)
|
||||
if b.Health.State != health.StateDisabled {
|
||||
t.Errorf("after disable: state=%s, want disabled", b.Health.State)
|
||||
}
|
||||
if b.Config.Enabled {
|
||||
t.Error("after disable: Enabled should be false")
|
||||
|
||||
@@ -268,8 +268,8 @@ func TestEnableDisableBackend(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("DisableBackend: %v", err)
|
||||
}
|
||||
if info.State != "removed" {
|
||||
t.Errorf("after disable: got %q, want removed", info.State)
|
||||
if info.State != "disabled" {
|
||||
t.Errorf("after disable: got %q, want disabled", info.State)
|
||||
}
|
||||
if info.Enabled {
|
||||
t.Error("after disable: Enabled should be false")
|
||||
|
||||
@@ -29,11 +29,12 @@ type ProbeResult struct {
|
||||
type State int
|
||||
|
||||
const (
|
||||
StateUnknown State = iota // initial state before first probe
|
||||
StateUp
|
||||
StateDown
|
||||
StatePaused
|
||||
StateRemoved // backend was removed from configuration
|
||||
StateUnknown State = iota // initial state before first probe
|
||||
StateUp // backend is healthy
|
||||
StateDown // backend has failed enough probes
|
||||
StatePaused // operator paused health checking
|
||||
StateDisabled // operator disabled the backend
|
||||
StateRemoved // backend removed from configuration by reload
|
||||
)
|
||||
|
||||
func (s State) String() string {
|
||||
@@ -46,6 +47,8 @@ func (s State) String() string {
|
||||
return "down"
|
||||
case StatePaused:
|
||||
return "paused"
|
||||
case StateDisabled:
|
||||
return "disabled"
|
||||
case StateRemoved:
|
||||
return "removed"
|
||||
default:
|
||||
@@ -123,7 +126,7 @@ func New(name string, addr net.IP, rise, fall int) *Backend {
|
||||
// failure means the backend is not yet confirmed reachable), and to StateUp
|
||||
// once the counter reaches Rise consecutive passes.
|
||||
func (b *Backend) Record(r ProbeResult, maxHistory int) bool {
|
||||
if b.State == StatePaused || b.State == StateRemoved {
|
||||
if b.State == StatePaused || b.State == StateDisabled || b.State == StateRemoved {
|
||||
return false
|
||||
}
|
||||
if r.OK {
|
||||
@@ -196,6 +199,13 @@ func (b *Backend) Start(maxHistory int) Transition {
|
||||
return b.Transitions[0]
|
||||
}
|
||||
|
||||
// Disable transitions the backend to StateDisabled. Returns the transition.
|
||||
// After this call no further probe results are accepted.
|
||||
func (b *Backend) Disable(maxHistory int) Transition {
|
||||
b.transition(StateDisabled, ProbeResult{Code: "disabled"}, maxHistory)
|
||||
return b.Transitions[0]
|
||||
}
|
||||
|
||||
// Remove transitions the backend to StateRemoved. Returns the transition.
|
||||
// After this call no further probe results are accepted.
|
||||
func (b *Backend) Remove(maxHistory int) Transition {
|
||||
|
||||
@@ -333,6 +333,7 @@ func TestStateString(t *testing.T) {
|
||||
{StateUp, "up"},
|
||||
{StateDown, "down"},
|
||||
{StatePaused, "paused"},
|
||||
{StateDisabled, "disabled"},
|
||||
{StateRemoved, "removed"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
|
||||
@@ -112,6 +112,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
health.StateUp,
|
||||
health.StateDown,
|
||||
health.StatePaused,
|
||||
health.StateDisabled,
|
||||
health.StateRemoved,
|
||||
}
|
||||
|
||||
@@ -173,4 +174,3 @@ func Register(reg prometheus.Registerer, src StateSource) *Collector {
|
||||
reg.MustRegister(TransitionTotal)
|
||||
return coll
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user