ops_settings_models.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package service
  2. // Ops settings models stored in DB `settings` table (JSON blobs).
  3. type OpsEmailNotificationConfig struct {
  4. Alert OpsEmailAlertConfig `json:"alert"`
  5. Report OpsEmailReportConfig `json:"report"`
  6. }
  7. type OpsEmailAlertConfig struct {
  8. Enabled bool `json:"enabled"`
  9. Recipients []string `json:"recipients"`
  10. MinSeverity string `json:"min_severity"`
  11. RateLimitPerHour int `json:"rate_limit_per_hour"`
  12. BatchingWindowSeconds int `json:"batching_window_seconds"`
  13. IncludeResolvedAlerts bool `json:"include_resolved_alerts"`
  14. }
  15. type OpsEmailReportConfig struct {
  16. Enabled bool `json:"enabled"`
  17. Recipients []string `json:"recipients"`
  18. DailySummaryEnabled bool `json:"daily_summary_enabled"`
  19. DailySummarySchedule string `json:"daily_summary_schedule"`
  20. WeeklySummaryEnabled bool `json:"weekly_summary_enabled"`
  21. WeeklySummarySchedule string `json:"weekly_summary_schedule"`
  22. ErrorDigestEnabled bool `json:"error_digest_enabled"`
  23. ErrorDigestSchedule string `json:"error_digest_schedule"`
  24. ErrorDigestMinCount int `json:"error_digest_min_count"`
  25. AccountHealthEnabled bool `json:"account_health_enabled"`
  26. AccountHealthSchedule string `json:"account_health_schedule"`
  27. AccountHealthErrorRateThreshold float64 `json:"account_health_error_rate_threshold"`
  28. }
  29. // OpsEmailNotificationConfigUpdateRequest allows partial updates, while the
  30. // frontend can still send the full config shape.
  31. type OpsEmailNotificationConfigUpdateRequest struct {
  32. Alert *OpsEmailAlertConfig `json:"alert"`
  33. Report *OpsEmailReportConfig `json:"report"`
  34. }
  35. type OpsDistributedLockSettings struct {
  36. Enabled bool `json:"enabled"`
  37. Key string `json:"key"`
  38. TTLSeconds int `json:"ttl_seconds"`
  39. }
  40. type OpsAlertSilenceEntry struct {
  41. RuleID *int64 `json:"rule_id,omitempty"`
  42. Severities []string `json:"severities,omitempty"`
  43. UntilRFC3339 string `json:"until_rfc3339"`
  44. Reason string `json:"reason"`
  45. }
  46. type OpsAlertSilencingSettings struct {
  47. Enabled bool `json:"enabled"`
  48. GlobalUntilRFC3339 string `json:"global_until_rfc3339"`
  49. GlobalReason string `json:"global_reason"`
  50. Entries []OpsAlertSilenceEntry `json:"entries,omitempty"`
  51. }
  52. type OpsMetricThresholds struct {
  53. SLAPercentMin *float64 `json:"sla_percent_min,omitempty"` // SLA低于此值变红
  54. TTFTp99MsMax *float64 `json:"ttft_p99_ms_max,omitempty"` // TTFT P99高于此值变红
  55. RequestErrorRatePercentMax *float64 `json:"request_error_rate_percent_max,omitempty"` // 请求错误率高于此值变红
  56. UpstreamErrorRatePercentMax *float64 `json:"upstream_error_rate_percent_max,omitempty"` // 上游错误率高于此值变红
  57. }
  58. type OpsRuntimeLogConfig struct {
  59. Level string `json:"level"`
  60. PersistAccessLogs bool `json:"persist_access_logs"`
  61. EnableSampling bool `json:"enable_sampling"`
  62. SamplingInitial int `json:"sampling_initial"`
  63. SamplingNext int `json:"sampling_thereafter"`
  64. Caller bool `json:"caller"`
  65. StacktraceLevel string `json:"stacktrace_level"`
  66. // RetentionDays is the authoritative retention for ops_system_logs.
  67. RetentionDays int `json:"retention_days"`
  68. Source string `json:"source,omitempty"`
  69. UpdatedAt string `json:"updated_at,omitempty"`
  70. UpdatedByUserID int64 `json:"updated_by_user_id,omitempty"`
  71. Extra map[string]any `json:"extra,omitempty"`
  72. }
  73. type OpsAlertRuntimeSettings struct {
  74. EvaluationIntervalSeconds int `json:"evaluation_interval_seconds"`
  75. DistributedLock OpsDistributedLockSettings `json:"distributed_lock"`
  76. Silencing OpsAlertSilencingSettings `json:"silencing"`
  77. Thresholds OpsMetricThresholds `json:"thresholds"` // 指标阈值配置
  78. }
  79. // OpsAdvancedSettings stores advanced ops configuration (data retention, aggregation).
  80. type OpsAdvancedSettings struct {
  81. DataRetention OpsDataRetentionSettings `json:"data_retention"`
  82. Aggregation OpsAggregationSettings `json:"aggregation"`
  83. OpenAIAccountQuotaAutoPause OpsOpenAIAccountQuotaAutoPauseSettings `json:"openai_account_quota_auto_pause"`
  84. IgnoreCountTokensErrors bool `json:"ignore_count_tokens_errors"`
  85. IgnoreContextCanceled bool `json:"ignore_context_canceled"`
  86. IgnoreNoAvailableAccounts bool `json:"ignore_no_available_accounts"`
  87. // Deprecated compatibility field. It is always normalized to true.
  88. IgnoreInvalidApiKeyErrors bool `json:"ignore_invalid_api_key_errors"`
  89. IgnoreInsufficientBalanceErrors bool `json:"ignore_insufficient_balance_errors"`
  90. DisplayOpenAITokenStats bool `json:"display_openai_token_stats"`
  91. DisplayAlertEvents bool `json:"display_alert_events"`
  92. AutoRefreshEnabled bool `json:"auto_refresh_enabled"`
  93. AutoRefreshIntervalSec int `json:"auto_refresh_interval_seconds"`
  94. }
  95. type OpsOpenAIAccountQuotaAutoPauseSettings struct {
  96. DefaultThreshold5h float64 `json:"default_threshold_5h"`
  97. DefaultThreshold7d float64 `json:"default_threshold_7d"`
  98. }
  99. type OpsDataRetentionSettings struct {
  100. CleanupEnabled bool `json:"cleanup_enabled"`
  101. CleanupSchedule string `json:"cleanup_schedule"`
  102. ErrorLogRetentionDays int `json:"error_log_retention_days"`
  103. MinuteMetricsRetentionDays int `json:"minute_metrics_retention_days"`
  104. HourlyMetricsRetentionDays int `json:"hourly_metrics_retention_days"`
  105. }
  106. type OpsAggregationSettings struct {
  107. AggregationEnabled bool `json:"aggregation_enabled"`
  108. }