ops_realtime.go 880 B

123456789101112131415161718192021222324252627282930313233343536
  1. package service
  2. import (
  3. "context"
  4. "errors"
  5. "strings"
  6. )
  7. // IsRealtimeMonitoringEnabled returns true when realtime ops features are enabled.
  8. //
  9. // This is a soft switch controlled by the DB setting `ops_realtime_monitoring_enabled`,
  10. // and it is also gated by the hard switch/soft switch of overall ops monitoring.
  11. func (s *OpsService) IsRealtimeMonitoringEnabled(ctx context.Context) bool {
  12. if !s.IsMonitoringEnabled(ctx) {
  13. return false
  14. }
  15. if s.settingRepo == nil {
  16. return true
  17. }
  18. value, err := s.settingRepo.GetValue(ctx, SettingKeyOpsRealtimeMonitoringEnabled)
  19. if err != nil {
  20. // Default enabled when key is missing; fail-open on transient errors.
  21. if errors.Is(err, ErrSettingNotFound) {
  22. return true
  23. }
  24. return true
  25. }
  26. switch strings.ToLower(strings.TrimSpace(value)) {
  27. case "false", "0", "off", "disabled":
  28. return false
  29. default:
  30. return true
  31. }
  32. }