This repository was archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
51 lines (40 loc) · 1.74 KB
/
types.go
File metadata and controls
51 lines (40 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package monitor
import (
"time"
)
type Checker interface {
Status() (interface{}, error)
}
type StatusListener interface {
// CheckFailed is called when a health check state transitions from passing to failing.
// * entry - The recorded state of the health check that triggered the failure
CheckFailed(entry *State)
// CheckRecovered is a function that handles the recovery of a failed health check.
// * entry - The recorded state of the health check that triggered the recovery
// * recordedFailures - the total failed health checks that lapsed
// between the failure and recovery
// * failureDurationSeconds - the lapsed time, in seconds, of the recovered failure
CheckRecovered(entry *State, recordedFailures int64, failureDurationSeconds float64)
StillFailing(entry *State, recordedFailures int64)
}
// State is a struct that contains the results of the latest
// run of a particular check.
type State struct {
// Name of the health check
Name string `json:"name"`
// Status of the health check state ("ok" or "failed")
Status string `json:"status"`
// Err is the error returned from a failed health check
Err string `json:"error,omitempty"`
// Details contains more contextual detail about a
// failing health check.
Details interface{} `json:"details,omitempty"` // contains JSON message (that can be marshaled)
// CheckTime is the time of the last health check
CheckTime time.Time `json:"check_time"`
ContiguousFailures int64 `json:"num_failures"` // the number of failures that occurred in a row
TimeOfFirstFailure time.Time `json:"first_failure_at"` // the time of the initial transitional failure for any given health check
}
// indicates state is failure
func (s *State) isFailure() bool {
return s.Status == "failed"
}