walstatus.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package source
  2. import "time"
  3. // WALStatus reports the health of a data source's write-ahead log: whether updates are being
  4. // persisted, and how complete the most recent restore was. Durations serialize to JSON as integer
  5. // nanoseconds.
  6. type WALStatus struct {
  7. // Enabled is false when the data source has no WAL configured; all other fields are zero.
  8. Enabled bool `json:"enabled"`
  9. // LastExportSuccess is the time of the most recent successful WAL write.
  10. LastExportSuccess time.Time `json:"lastExportSuccess"`
  11. // LastExportError is the most recent WAL write error, with any URL query strings and
  12. // credentials removed.
  13. LastExportError string `json:"lastExportError,omitempty"`
  14. // LastExportErrorAt is the time of the most recent WAL write error.
  15. LastExportErrorAt time.Time `json:"lastExportErrorAt"`
  16. // ConsecutiveExportFailures is the number of WAL writes that have failed since the last success.
  17. ConsecutiveExportFailures int `json:"consecutiveExportFailures"`
  18. // ExportFailuresTotal is the number of WAL writes that have failed since start.
  19. ExportFailuresTotal uint64 `json:"exportFailuresTotal"`
  20. // RestoreCompleted is true once the startup restore has finished, whether or not it had errors.
  21. RestoreCompleted bool `json:"restoreCompleted"`
  22. // RestoreStartedAt is the time the startup restore began.
  23. RestoreStartedAt time.Time `json:"restoreStartedAt"`
  24. // RestoreListError is set when the WAL objects could not be listed, meaning nothing was restored.
  25. RestoreListError string `json:"restoreListError,omitempty"`
  26. // RestoreObjectsSeen is the number of WAL objects inside the retention window.
  27. RestoreObjectsSeen int `json:"restoreObjectsSeen"`
  28. // RestoreObjectsApplied is the number of WAL objects successfully read, decoded and applied.
  29. RestoreObjectsApplied int `json:"restoreObjectsApplied"`
  30. // RestoreErrors is the number of WAL objects that could not be read or decoded.
  31. RestoreErrors int `json:"restoreErrors"`
  32. // RestoreDuration is how long the startup restore took.
  33. RestoreDuration time.Duration `json:"restoreDuration"`
  34. // RestoreOldest and RestoreNewest are the timestamps of the oldest and newest applied objects.
  35. RestoreOldest time.Time `json:"restoreOldest"`
  36. RestoreNewest time.Time `json:"restoreNewest"`
  37. // RestoreLargestGap is the largest interval between consecutive applied objects, starting at
  38. // RestoreLargestGapStart. A gap much larger than the scrape interval means history in that range
  39. // was never persisted or could not be restored.
  40. RestoreLargestGap time.Duration `json:"restoreLargestGap"`
  41. RestoreLargestGapStart time.Time `json:"restoreLargestGapStart"`
  42. // RestoreTailGap is the interval between the newest applied object (or the start of the retention
  43. // window, if nothing was applied) and the start of the restore: history that was not persisted
  44. // before the restart, whether because the process was down or because writes were failing.
  45. RestoreTailGap time.Duration `json:"restoreTailGap"`
  46. }
  47. // WALStatusProvider is optionally implemented by an OpenCostDataSource that persists its state
  48. // through a write-ahead log.
  49. type WALStatusProvider interface {
  50. WALStatus() WALStatus
  51. }