carlos / platform Public

Merge pull request #343 from carlosframework/reliability

memwatch: publish to the box's placement region
Paul Campbell pushed by paul@keymail.dev 0ac8c98a33e7098f1f2cecc8646db6a3dcbfb241 parent d86a5c1parent 2ddebdb
1 file changed, +11 −1
  • internal/host/memwatch.go +11 −1
diff --git a/internal/host/memwatch.go b/internal/host/memwatch.go
index 54781fad8..0a74e14f6 100644
--- a/internal/host/memwatch.go
+++ b/internal/host/memwatch.go
@@ -93,6 +93,16 @@ func memwatchLoop() {
log.Printf("agent: memwatch disabled: load aws config: %v", err)
return
}
+ // The metric goes to the box's OWN region, not host.env's AWS_REGION:
+ // the flagship sets AWS_REGION=eu-west-1 fleet-wide (it names the
+ // deployment bucket's region), and on the first roll all four boxes
+ // dutifully published into Ireland — while the region-host module
+ // creates each box's alarm in the box's region, so three alarms would
+ // have watched an empty namespace forever. IMDS placement wins; "" (not
+ // on EC2) keeps the chain's answer.
+ if r := readPlacementRegion(); r != "" {
+ cfg.Region = r
+ }
id, err := imdsInstanceID()
if err != nil {
log.Printf("agent: memwatch disabled: instance id: %v", err)
@@ -105,7 +115,7 @@ func memwatchLoop() {
pressure: readPressureFile,
logf: log.Printf,
}
- log.Printf("agent: memwatch armed (%s, every %s, instance %s)", memwatchNamespace, memwatchPeriod, id)
+ log.Printf("agent: memwatch armed (%s in %s, every %s, instance %s)", memwatchNamespace, cfg.Region, memwatchPeriod, id)
for now := range time.Tick(memwatchPeriod) {
w.tick(ctx, now)
}