mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
feat(multiplayer): add regional allocation budget
This commit is contained in:
@@ -25,6 +25,8 @@ func main() {
|
||||
transport := flag.String("transport", envOrDefault("COSMIC_CLASH_TRANSPORT", "enet"), "game transport: enet or steam_sdr")
|
||||
interval := flag.Duration("interval", time.Second, "allocation poll interval")
|
||||
workloadSecret := flag.String("workload-secret", os.Getenv("COSMIC_CLASH_WORKLOAD_SECRET"), "HMAC secret for control-plane-issued workload tokens (see workload/signed_token.go); must match cmd/control-plane's own --workload-secret. Unset skips minting a cosmic-clash.io/workload-token annotation entirely")
|
||||
allocationQuota := flag.Int("allocation-quota", 0, "optional per-replica allocation attempts per region per quota window; zero disables this local guard")
|
||||
allocationQuotaWindow := flag.Duration("allocation-quota-window", time.Minute, "window for --allocation-quota")
|
||||
flag.Parse()
|
||||
if *dsn == "" || *agonesURL == "" {
|
||||
fatalf("--dsn/COSMIC_CLASH_POSTGRES_DSN and --agones-url/COSMIC_CLASH_AGONES_URL are required")
|
||||
@@ -32,6 +34,9 @@ func main() {
|
||||
if (*transport != "enet" && *transport != "steam_sdr") || *interval <= 0 {
|
||||
fatalf("--transport must be enet or steam_sdr and --interval must be positive")
|
||||
}
|
||||
if *allocationQuota < 0 || *allocationQuotaWindow <= 0 {
|
||||
fatalf("--allocation-quota must be non-negative and --allocation-quota-window must be positive")
|
||||
}
|
||||
db, err := sql.Open("pgx", *dsn)
|
||||
if err != nil {
|
||||
fatalf("open PostgreSQL: %v", err)
|
||||
@@ -49,12 +54,21 @@ func main() {
|
||||
log.Printf("allocator: warning: --workload-secret / COSMIC_CLASH_WORKLOAD_SECRET is unset; allocated GameServers will receive no cosmic-clash.io/workload-token annotation, and control-plane registration will fail unless a --workload-token-path is separately configured on the supervisor")
|
||||
}
|
||||
now := func() time.Time { return time.Now().UTC() }
|
||||
var budget allocator.AllocationBudget
|
||||
if *allocationQuota > 0 {
|
||||
budget, err = allocator.NewFixedWindowBudget(*allocationQuota, *allocationQuotaWindow)
|
||||
if err != nil {
|
||||
fatalf("allocation quota: %v", err)
|
||||
}
|
||||
log.Printf("allocator: enabled per-replica regional allocation quota=%d window=%s", *allocationQuota, *allocationQuotaWindow)
|
||||
}
|
||||
client := agones.Client{BaseURL: *agonesURL, Namespace: *namespace, WorkloadSecret: []byte(*workloadSecret)}
|
||||
worker := allocator.Worker{
|
||||
Claims: store.AllocatingMatchClaims{DB: db, Transport: *transport},
|
||||
Service: allocator.Service{
|
||||
Provider: client,
|
||||
Durable: store.AllocationRegistry{DB: db},
|
||||
Budget: budget,
|
||||
Now: now,
|
||||
},
|
||||
Now: now,
|
||||
|
||||
Reference in New Issue
Block a user