| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/provision" |
| 8 | ) |
| 9 | |
| 10 | // discrepancyScanCap bounds one app's record listing. ListRecords treats |
| 11 | // max=0 as "list nothing", so the cap must be explicit. |
| 12 | const discrepancyScanCap = 10000 |
| 13 | |
| 14 | // LogPlacementDiscrepancies is spec §5.7 step 4, run once at console |
| 15 | // start. For each app holding a non-home region, it lists records with an |
| 16 | // empty region created after the app — the shape a console rolled back |
| 17 | // below the floor would have written. Shapes that never inherit the app |
| 18 | // default are skipped (static, addr-backed, replica, pooled, fleet). A |
| 19 | // deliberate home override looks the same and the record keeps no |
| 20 | // provenance, so each line is a CANDIDATE for review, worded as one (C29). |
| 21 | // It only logs: an error is reported and skipped, never returned, so the |
| 22 | // check can neither block nor fail console start. |
| 23 | func (s *Server) LogPlacementDiscrepancies(ctx context.Context) { |
| 24 | s.logPlacementDiscrepancies(ctx, discrepancyScanCap) |
| 25 | } |
| 26 | |
| 27 | func (s *Server) logPlacementDiscrepancies(ctx context.Context, scanCap int) { |
| 28 | if s.cfg.Releases == nil { |
| 29 | return |
| 30 | } |
| 31 | apps, err := s.store.NonHomeAppRegions() |
| 32 | if err != nil { |
| 33 | log.Printf("console: placement discrepancy check: %v", err) |
| 34 | return |
| 35 | } |
| 36 | for _, a := range apps { |
| 37 | recs, truncated, err := provision.ListRecords(ctx, s.cfg.Releases, a.Sqid, a.App, scanCap) |
| 38 | if err != nil { |
| 39 | log.Printf("console: placement discrepancy check %s/%s: %v", a.Sqid, a.App, err) |
| 40 | continue |
| 41 | } |
| 42 | if truncated { |
| 43 | log.Printf("console: placement discrepancy check %s/%s: only the first %d records were checked", a.Sqid, a.App, scanCap) |
| 44 | } |
| 45 | for _, r := range recs { |
| 46 | if r.Region != "" || r.Role != "" || r.Pool != "" || !r.DerivesPaths() || r.CreatedAt.Before(a.CreatedAt) { |
| 47 | continue |
| 48 | } |
| 49 | log.Print("console: " + msgPlacementDiscrepancy(r.Host, a.App, a.Region)) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |