carlos / platform Public

host: log a failed region capacity page instead of dropping it

armHAPlacement's OnHAOverCapacity sent the "Region X needs more
capacity" page with _ = page(...), so a sink that refused it left no
trace and a region could run short with nobody told. A failure is now
logged, the way wireRawSecretPages logs its failed page in agent.go.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 198820a9ca20914d59a06663f49f19152443feff parent a28dd6b
2 files changed, +28 −1
  • internal/host/haplacement.go +6 −1
  • internal/host/haplacement_wiring_test.go +22 −0

CI cancelled — superseded by a newer push — run details

diff --git a/internal/host/haplacement.go b/internal/host/haplacement.go
index 6c6b74425..522c25604 100644
--- a/internal/host/haplacement.go
+++ b/internal/host/haplacement.go
@@ -3,6 +3,7 @@ package host
import (
"context"
"fmt"
+ "log"
"time"
"github.com/carlosframework/platform/internal/activator"
@@ -14,6 +15,10 @@ func armHAPlacement(svc *activator.Service, page func(context.Context, string, s
svc.OnHAOverCapacity = func(region, host, ref string) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- _ = page(ctx, alerting.LevelWarning, fmt.Sprintf("Region %s needs more capacity", region), fmt.Sprintf("Region %s is short on spare capacity. Instance %s is waking on %s. Add capacity to the region.", region, host, ref))
+ if err := page(ctx, alerting.LevelWarning, fmt.Sprintf("Region %s needs more capacity", region), fmt.Sprintf("Region %s is short on spare capacity. Instance %s is waking on %s. Add capacity to the region.", region, host, ref)); err != nil {
+ // As wireRawSecretPages does: a page that fails is logged, or
+ // nobody learns the region ran short.
+ log.Printf("agent: %s: the region %s capacity page failed: %v", host, region, err)
+ }
}
}
diff --git a/internal/host/haplacement_wiring_test.go b/internal/host/haplacement_wiring_test.go
index 043e62b7f..7fc96a197 100644
--- a/internal/host/haplacement_wiring_test.go
+++ b/internal/host/haplacement_wiring_test.go
@@ -1,10 +1,13 @@
package host
import (
+ "bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
+ "log"
"net/http/httputil"
"net/url"
"os/exec"
@@ -111,6 +114,25 @@ func TestHAPlacementPageWiring(t *testing.T) {
}
}
+// TestHAPlacementLogsAFailedPage: a capacity page the sink refuses is
+// logged, as the raw-secret page is (wireRawSecretPages). It used to be
+// dropped with _ =, so a region could run short with no trace anywhere.
+func TestHAPlacementLogsAFailedPage(t *testing.T) {
+ var buf bytes.Buffer
+ prev := log.Writer()
+ log.SetOutput(&buf)
+ t.Cleanup(func() { log.SetOutput(prev) })
+ t.Cleanup(func() { setHAAwakeApps(nil) })
+ svc := &activator.Service{}
+ armHAPlacement(svc, func(context.Context, string, string, string) error {
+ return errors.New("sink unreachable")
+ })
+ svc.OnHAOverCapacity("ie", "shop.example.com", "b")
+ if got := buf.String(); !strings.Contains(got, "shop.example.com") || !strings.Contains(got, "region ie capacity page failed: sink unreachable") {
+ t.Fatalf("log = %q, want the failed capacity page", got)
+ }
+}
+
func armHAPlacementWitness(svc *activator.Service, sink func(context.Context, string, string, string) error) {
if os.Getenv("RHASIM_MUTATE") == "placement-skips-arm" {
return