mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
feat(multiplayer): expose allocator quota metrics
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@@ -27,6 +28,7 @@ func main() {
|
||||
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")
|
||||
metricsAddr := flag.String("metrics-addr", envOrDefault("COSMIC_CLASH_ALLOCATOR_METRICS_ADDR", ":9091"), "allocator Prometheus metrics address; empty disables metrics")
|
||||
flag.Parse()
|
||||
if *dsn == "" || *agonesURL == "" {
|
||||
fatalf("--dsn/COSMIC_CLASH_POSTGRES_DSN and --agones-url/COSMIC_CLASH_AGONES_URL are required")
|
||||
@@ -62,6 +64,7 @@ func main() {
|
||||
}
|
||||
log.Printf("allocator: enabled per-replica regional allocation quota=%d window=%s", *allocationQuota, *allocationQuotaWindow)
|
||||
}
|
||||
metrics := allocator.NewMetrics()
|
||||
client := agones.Client{BaseURL: *agonesURL, Namespace: *namespace, WorkloadSecret: []byte(*workloadSecret)}
|
||||
worker := allocator.Worker{
|
||||
Claims: store.AllocatingMatchClaims{DB: db, Transport: *transport},
|
||||
@@ -70,12 +73,30 @@ func main() {
|
||||
Durable: store.AllocationRegistry{DB: db},
|
||||
Quota: store.AllocationQuota{DB: db},
|
||||
Budget: budget,
|
||||
Metrics: metrics,
|
||||
Now: now,
|
||||
},
|
||||
Now: now,
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
var metricsServer *http.Server
|
||||
if *metricsAddr != "" {
|
||||
metricsServer = &http.Server{Addr: *metricsAddr, Handler: allocator.MetricsHandler(metrics)}
|
||||
go func() {
|
||||
if err := metricsServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Printf("allocator: metrics server: %v", err)
|
||||
}
|
||||
}()
|
||||
log.Printf("allocator: metrics listening on %s", *metricsAddr)
|
||||
}
|
||||
defer func() {
|
||||
if metricsServer != nil {
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = metricsServer.Shutdown(shutdownCtx)
|
||||
}
|
||||
}()
|
||||
ticker := time.NewTicker(*interval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user