feat(api): add internal alerts reporting endpoint with deduplication

Add ReportAlerts endpoint for Data Plane to report alerts to Control Plane
with fingerprint-based deduplication using a 5-minute cooldown period.

Changes:
- Add POST /internal/alerts/report endpoint with validation
- Add Fingerprint field to Alert model for deduplication
- Extend GetAPIKeyStatsSummary with optional time range filtering
  using since/until query parameters to query from log records
This commit is contained in:
zenfun
2025-12-31 14:18:09 +08:00
parent 71f7578c7b
commit bfba16bbd4
4 changed files with 208 additions and 1 deletions

View File

@@ -48,7 +48,8 @@ type Alert struct {
RelatedID uint `gorm:"index" json:"related_id,omitempty"`
RelatedType string `gorm:"size:50" json:"related_type,omitempty"` // master, key, apikey, provider_group
RelatedName string `gorm:"size:255" json:"related_name,omitempty"`
Metadata string `gorm:"type:text" json:"metadata,omitempty"` // JSON encoded additional data
Fingerprint string `gorm:"size:255;index" json:"fingerprint,omitempty"` // For deduplication: type:related_type:related_id
Metadata string `gorm:"type:text" json:"metadata,omitempty"` // JSON encoded additional data
AckedAt *time.Time `json:"acked_at,omitempty"`
AckedBy string `gorm:"size:100" json:"acked_by,omitempty"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`