runtime.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package configissues
  2. import "sync"
  3. var (
  4. runtimeMu sync.Mutex
  5. runtimeIssues []Issue
  6. )
  7. // ReportRuntime records an issue discovered while OliveTin is running, rather
  8. // than from the configuration (for example, a call to a deprecated API
  9. // method). Unlike Report, runtime issues are kept when the issue list is
  10. // rebuilt on config reload or entity changes. They are cleared on restart.
  11. func ReportRuntime(issue Issue) {
  12. addRuntime(issue)
  13. Report(issue)
  14. }
  15. func addRuntime(issue Issue) {
  16. runtimeMu.Lock()
  17. defer runtimeMu.Unlock()
  18. fingerprint := issueFingerprint(issue)
  19. for _, existing := range runtimeIssues {
  20. if issueFingerprint(existing) == fingerprint {
  21. return
  22. }
  23. }
  24. runtimeIssues = append(runtimeIssues, issue)
  25. }
  26. // CopyRuntime returns a copy of the runtime issues.
  27. func CopyRuntime() []Issue {
  28. runtimeMu.Lock()
  29. defer runtimeMu.Unlock()
  30. out := make([]Issue, len(runtimeIssues))
  31. copy(out, runtimeIssues)
  32. return out
  33. }
  34. // ClearRuntime removes all runtime issues. Intended for tests.
  35. func ClearRuntime() {
  36. runtimeMu.Lock()
  37. defer runtimeMu.Unlock()
  38. runtimeIssues = nil
  39. }