package model import ( "time" "gorm.io/gorm" ) // AlertThresholdConfig stores configurable thresholds for traffic spike detection type AlertThresholdConfig struct { ID uint `gorm:"primaryKey" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // Global thresholds GlobalQPS int64 `gorm:"not null;default:100" json:"global_qps"` // System-wide QPS threshold // Per-master thresholds MasterRPM int64 `gorm:"not null;default:20" json:"master_rpm"` // Requests per minute threshold MasterRPD int64 `gorm:"not null;default:1000" json:"master_rpd"` // Requests per day threshold MasterTPM int64 `gorm:"not null;default:10000000" json:"master_tpm"` // Tokens per minute threshold MasterTPD int64 `gorm:"not null;default:100000000" json:"master_tpd"` // Tokens per day threshold // Minimum sample thresholds for 1-minute window checks MinRPMRequests1m int64 `gorm:"not null;default:10" json:"min_rpm_requests_1m"` // Min requests in 1m to trigger RPM check MinTPMTokens1m int64 `gorm:"not null;default:1000000" json:"min_tpm_tokens_1m"` // Min tokens in 1m to trigger TPM check } // DefaultAlertThresholdConfig returns the default threshold configuration func DefaultAlertThresholdConfig() AlertThresholdConfig { return AlertThresholdConfig{ GlobalQPS: 100, MasterRPM: 20, MasterRPD: 1000, MasterTPM: 10_000_000, MasterTPD: 100_000_000, MinRPMRequests1m: 10, MinTPMTokens1m: 1_000_000, } } // TableName returns the table name for AlertThresholdConfig func (AlertThresholdConfig) TableName() string { return "alert_threshold_configs" }