From 3f702084d20b3c3a3ea916f3110e99b22bda60b3 Mon Sep 17 00:00:00 2001 From: Chia Date: Thu, 6 Aug 2026 15:58:57 +1200 Subject: feat: complete commercial developer workflows Add tenant-safe usage observability, prepaid billing controls, API key lifecycle management, Embeddings metering, configurable billing alerts, and resilient provider health propagation. Harden Stripe failure handling, migrations, readiness, and the authenticated control-plane UI with end-to-end verification evidence. --- cmd/aigw/main.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'cmd/aigw') diff --git a/cmd/aigw/main.go b/cmd/aigw/main.go index 3ac388a..60956a8 100644 --- a/cmd/aigw/main.go +++ b/cmd/aigw/main.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "os/signal" + "strconv" "syscall" "time" @@ -180,6 +181,27 @@ func run(ctx context.Context, cfg config.Config, logger *slog.Logger) error { billingMeter = billingService } routeHealth := providerhealth.New(providerhealth.Options{}) + var sharedHealth *providerhealth.RedisHistory + if cfg.ProviderHealth.SharedHistoryEnabled { + instanceID := cfg.Server.DeploymentRegion + ":" + strconv.Itoa(os.Getpid()) + ":" + strconv.FormatInt(time.Now().UnixNano(), 36) + sharedHealth = providerhealth.NewRedisHistory(providerhealth.HistoryOptions{ + Enabled: true, RedisURL: cfg.ControlPlane.RedisURL, Stream: cfg.ProviderHealth.SharedHistoryStream, + Instance: instanceID, MaxEvents: cfg.ProviderHealth.SharedHistoryMaxEvents, + TTL: time.Duration(cfg.ProviderHealth.SharedHistoryTTLSeconds) * time.Second, Logger: logger, Metrics: metrics, + }) + if sharedHealth != nil { + routeHealth.SetSink(sharedHealth) + go sharedHealth.Run(ctx, routeHealth) + defer sharedHealth.Close() + } else { + logger.Warn("provider_health_shared_history_disabled", "reason", "redis_not_configured", "fallback", "local") + } + } + go providerhealth.NewProber(providerhealth.ProbeOptions{ + Enabled: cfg.ProviderHealth.ActiveProbesEnabled, Interval: time.Duration(cfg.ProviderHealth.ProbeIntervalSeconds) * time.Second, + Timeout: time.Duration(cfg.ProviderHealth.ProbeTimeoutSeconds) * time.Second, Catalog: modelCatalog, + Tracker: routeHealth, Metrics: metrics, Logger: logger, + }).Run(ctx) inferenceAPI := httpapi.New(httpapi.Options{ Authenticator: authenticator, @@ -204,10 +226,14 @@ func run(ctx context.Context, cfg config.Config, logger *slog.Logger) error { Logger: logger, Prefix: cfg.Admin.BasePath, RegistrationEnabled: cfg.Admin.RegistrationEnabled, SessionTTL: time.Duration(cfg.Admin.SessionTTLHours) * time.Hour, Currency: cfg.Billing.Currency, PublicURL: cfg.Admin.PublicURL, WebAuthn: webAuthn, MailEnabled: cfg.Admin.Mail.Enabled, - InferencePublicURL: cfg.Admin.InferencePublicURL, - DefaultLowBalanceMicros: cfg.Admin.Mail.LowBalanceMicros, - Catalog: modelCatalog, - ProviderHealth: routeHealth, + InferencePublicURL: cfg.Admin.InferencePublicURL, + BillingPreferenceDefaults: controlplane.BillingPreferenceDefaults{ + LowBalanceThresholdMicros: cfg.Admin.Mail.LowBalanceMicros, + SpendAnomalyMultiplier: cfg.Admin.Mail.SpendAnomalyMultiplier, + SpendAnomalyMinMicros: cfg.Admin.Mail.SpendAnomalyMinMicros, + }, + Catalog: modelCatalog, + ProviderHealth: routeHealth, }).Handler() } operationHandler := operations.Handler{Store: store, Manager: manager, Billing: billingService, Metrics: metrics, -- cgit v1.2.3