summaryrefslogtreecommitdiff
path: root/cmd/aigw
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-06 15:58:57 +1200
committerChia <Chia@93.nz>2026-08-06 15:58:57 +1200
commit3f702084d20b3c3a3ea916f3110e99b22bda60b3 (patch)
tree517f76c51025ce1ee085ea4898c60f799e5c37ea /cmd/aigw
parent41e322c53d7b4b796eb377d0df9c29ecd10ba431 (diff)
feat: complete commercial developer workflowspublish-commercial-control-plane
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.
Diffstat (limited to '')
-rw-r--r--cmd/aigw/main.go34
1 files changed, 30 insertions, 4 deletions
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,