carlos / platform Public

ha: name the cause when pool withdrawal is pending

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8482f3d7f2629678ff16e18409b15a15a46a7307 parent d402566
5 files changed, +101 −4
  • internal/activator/poolwithdrawal.go +4 −1
  • internal/activator/poolwithdrawal_test.go +31 −0
  • internal/host/region_ha_g2_pool_root_linux_test.go +18 −1
  • internal/provision/poolwithdrawal.go +19 −2
  • internal/provision/poolwithdrawal_test.go +29 −0

Intent

Human

<task-notification> <task-id>b4yd5abzz</task-id> <tool-use-id>toolu_01FLwKJRn7EFinBjKSMAuCTm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/b4yd5abzz.output</output-file> <status>completed</status> <summary>Background command "Run F-B witness live, run 12" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/activator/poolwithdrawal.go b/internal/activator/poolwithdrawal.go
index ec520cd65..cb7209124 100644
--- a/internal/activator/poolwithdrawal.go
+++ b/internal/activator/poolwithdrawal.go
@@ -80,6 +80,7 @@ func (a *Service) PreparePoolWithdrawal(ctx context.Context, rt registry.Route)
}
func (a *Service) provePoolWithdrawal(b *ExecBackend, job *poolWithdrawal) {
+ log.Printf("ha_pool_withdrawal_proof_start host=%s", job.route.Host)
ctx, cancel := context.WithTimeout(a.life(), 5*time.Minute)
defer cancel()
err := a.poolWithdrawalProof(ctx, b, job)
@@ -88,7 +89,9 @@ func (a *Service) provePoolWithdrawal(b *ExecBackend, job *poolWithdrawal) {
job.retryAt = time.Now().Add(time.Second)
a.mu.Unlock()
if err != nil {
- log.Printf("%v host=%s", err, job.route.Host)
+ log.Printf("ha_pool_withdrawal_proof_finish host=%s result=error error=%v", job.route.Host, err)
+ } else {
+ log.Printf("ha_pool_withdrawal_proof_finish host=%s result=success", job.route.Host)
}
}
diff --git a/internal/activator/poolwithdrawal_test.go b/internal/activator/poolwithdrawal_test.go
index 9919e7be6..7b3562d08 100644
--- a/internal/activator/poolwithdrawal_test.go
+++ b/internal/activator/poolwithdrawal_test.go
@@ -3,6 +3,7 @@ package activator
import (
"context"
"errors"
+ "log"
"strings"
"sync/atomic"
"testing"
@@ -278,3 +279,33 @@ func TestPoolWithdrawalReadsBeforeServiceLock(t *testing.T) {
t.Fatal("changed row started withdrawal")
}
}
+
+func TestPoolWithdrawalLogsProofAttempt(t *testing.T) {
+ for _, fail := range []bool{false, true} {
+ t.Run(map[bool]string{false: "success", true: "error"}[fail], func(t *testing.T) {
+ s := haService(t, "shop.example.com")
+ row := withdrawalFixture(t, s)
+ if fail {
+ s.b.StartupSwept = func() bool { return false }
+ }
+ var logs syncBuffer
+ old := log.Writer()
+ log.SetOutput(&logs)
+ defer log.SetOutput(old)
+ job := &poolWithdrawal{route: row, owner: "pool-withdrawal/" + row.Host}
+ s.a.provePoolWithdrawal(s.b, job)
+ if !job.done || (job.err != nil) != fail {
+ t.Fatalf("unexpected proof result: %+v", job)
+ }
+ start := "ha_pool_withdrawal_proof_start host=" + row.Host
+ finish := "ha_pool_withdrawal_proof_finish host=" + row.Host + " result=success"
+ if fail {
+ finish = "ha_pool_withdrawal_proof_finish host=" + row.Host + " result=error error=ha_pool_withdrawal_pending code=startup"
+ }
+ got := logs.String()
+ if strings.Count(got, start) != 1 || strings.Count(got, finish) != 1 || strings.Index(got, start) > strings.Index(got, finish) {
+ t.Fatalf("want one start then one finish (%q, %q); got %q", start, finish, got)
+ }
+ })
+ }
+}
diff --git a/internal/host/region_ha_g2_pool_root_linux_test.go b/internal/host/region_ha_g2_pool_root_linux_test.go
index 84f8dc091..5a9db5b52 100644
--- a/internal/host/region_ha_g2_pool_root_linux_test.go
+++ b/internal/host/region_ha_g2_pool_root_linux_test.go
@@ -19,6 +19,7 @@ import (
"io"
"net/http"
"os"
+ "os/exec"
"slices"
"strconv"
"strings"
@@ -671,7 +672,7 @@ func TestRootG2PoolIngress(t *testing.T) {
g2Serial(t, storage.deploy)
}
// Observe the release before permitting row disappearance to count as a pass.
- g2Wait(t, "withdrawal stop-release-remove ordering", 100*time.Second, func() bool {
+ g2WaitPoolWithdrawal(t, func() bool {
row, err := a.reg.Get(g2Host)
g2Must(t, err)
if row != nil {
@@ -954,3 +955,19 @@ func TestG2PoolAbsentFixture(t *testing.T) {
}
}
}
+
+func g2WaitPoolWithdrawal(t *testing.T, fn func() bool) {
+ t.Helper()
+ complete := false
+ defer func() {
+ if complete {
+ return
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ out, err := exec.CommandContext(ctx, "journalctl", "-u", "carlos-edge.service", "--no-pager", "--all", "-n", "80", "--grep=ha_pool_withdrawal_|ha_pool_withdrawn").CombinedOutput()
+ t.Logf("A withdrawal and proof-worker journal (last 80 matching lines): error=%v\n%s", err, out)
+ }()
+ g2Wait(t, "withdrawal stop-release-remove ordering", 100*time.Second, fn)
+ complete = true
+}
diff --git a/internal/provision/poolwithdrawal.go b/internal/provision/poolwithdrawal.go
index 5e1558c76..d5f198779 100644
--- a/internal/provision/poolwithdrawal.go
+++ b/internal/provision/poolwithdrawal.go
@@ -94,6 +94,7 @@ func (cfg ReconcileConfig) withdrawPools(ctx context.Context, s release.Store, r
continue
}
code := ""
+ var err error
switch {
case !cfg.poolWithdrawalCandidate(rt, sidecars):
code = "ownership"
@@ -109,11 +110,16 @@ func (cfg ReconcileConfig) withdrawPools(ctx context.Context, s release.Store, r
}
journal, jerr := reg.ImportJournal(rt.Host)
if jerr != nil || journal != nil {
+ err = jerr
code = "ownership"
break
}
if err = cfg.WithdrawPool(ctx, rt); err != nil {
code = "proof"
+ var pending *poolWithdrawalPendingError
+ if errors.As(err, &pending) {
+ code = pending.code
+ }
break
}
if err = cfg.withdrawalRecord(ctx, freshStore(s), &rt); err != nil {
@@ -129,13 +135,24 @@ func (cfg ReconcileConfig) withdrawPools(ctx context.Context, s release.Store, r
log.Printf("ha_pool_withdrawn host=%s", rt.Host)
}
if code != "" {
- log.Printf("ha_pool_withdrawal_pending code=%s host=%s", code, rt.Host)
+ if err == nil {
+ err = PoolWithdrawalPending(code)
+ }
+ log.Printf("ha_pool_withdrawal_pending code=%s host=%s error=%v", code, rt.Host, err)
}
}
}
var errPoolWithdrawalPending = errors.New("ha_pool_withdrawal_pending")
+type poolWithdrawalPendingError struct{ code string }
+
+func (e *poolWithdrawalPendingError) Error() string {
+ return fmt.Sprintf("%s code=%s", errPoolWithdrawalPending, e.code)
+}
+
+func (e *poolWithdrawalPendingError) Unwrap() error { return errPoolWithdrawalPending }
+
func PoolWithdrawalPending(code string) error {
- return fmt.Errorf("%w code=%s", errPoolWithdrawalPending, code)
+ return &poolWithdrawalPendingError{code: code}
}
diff --git a/internal/provision/poolwithdrawal_test.go b/internal/provision/poolwithdrawal_test.go
index 381833057..7e8fb2e46 100644
--- a/internal/provision/poolwithdrawal_test.go
+++ b/internal/provision/poolwithdrawal_test.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
+ "fmt"
"strings"
"testing"
"time"
@@ -151,3 +152,31 @@ func TestPoolWithdrawalSidecarOwnKind(t *testing.T) {
t.Fatalf("proof calls=%d", calls)
}
}
+
+func TestPoolWithdrawalLogsCause(t *testing.T) {
+ for _, code := range []string{"ownership", "changed", "shutdown", "fence", "stopping", "stop", "startup", "cgroup", "record", "release", "lifetime", "duties", "proof"} {
+ t.Run(code, func(t *testing.T) {
+ rt := registry.Route{Host: "shop.example.com", Account: "bbw", App: "shop", Kind: "instance", Status: "ready", Provisioned: true, Hibernate: true, Pool: "old", Region: "ie"}
+ reg := regWith(t, rt)
+ defer reg.Close()
+ s := dirStore(t)
+ if err := CreateRecord(ctx, s, Record{Host: rt.Host, Account: rt.Account, App: rt.App, Pool: rt.Pool, Region: rt.Region, Channel: "stable"}); err != nil {
+ t.Fatal(err)
+ }
+ cause := fmt.Errorf("withdrawal inspection: %w", PoolWithdrawalPending(code))
+ if code == "proof" {
+ cause = errors.New("injected proof error")
+ }
+ logs := captureLog(t)
+ cfg := ReconcileConfig{Region: "ie", Pools: []string{"new"}, WithdrawPool: func(context.Context, registry.Route) error { return cause }}
+ cfg.withdrawPools(ctx, s, reg, false)
+ want := fmt.Sprintf("ha_pool_withdrawal_pending code=%s host=%s error=%s", code, rt.Host, cause)
+ if got := logs.String(); strings.Count(got, want) != 1 {
+ t.Fatalf("want one line %q; got %q", want, got)
+ }
+ if got, err := reg.Get(rt.Host); err != nil || got == nil {
+ t.Fatalf("failed proof removed row: %+v %v", got, err)
+ }
+ })
+ }
+}