-
Notifications
You must be signed in to change notification settings - Fork 69
/
state.go
88 lines (77 loc) · 2.21 KB
/
state.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package moira
// State type describe all default moira triggers or metrics states.
type State string
// TTLState declares all ttl (NODATA) states, used if metric has no values for given interval (ttl).
type TTLState string
// Moira notifier self-states.
const (
SelfStateOK = "OK" // OK means notifier is healthy
SelfStateERROR = "ERROR" // ERROR means notifier is stopped, admin intervention is required
)
// Moira trigger and metric states.
var (
StateOK State = "OK"
StateWARN State = "WARN"
StateERROR State = "ERROR"
StateNODATA State = "NODATA"
StateEXCEPTION State = "EXCEPTION" // Use this for trigger check unexpected errors
StateTEST State = "TEST" // Use this only for test notifications
)
// Moira ttl states.
var (
TTLStateOK TTLState = "OK"
TTLStateWARN TTLState = "WARN"
TTLStateERROR TTLState = "ERROR"
TTLStateNODATA TTLState = "NODATA"
TTLStateDEL TTLState = "DEL"
)
var (
eventStatesPriority = [...]State{StateOK, StateWARN, StateERROR, StateNODATA, StateEXCEPTION, StateTEST}
stateScores = map[State]int64{
StateOK: 0,
StateWARN: 1,
StateERROR: 100, //nolint
StateNODATA: 1000, //nolint
StateEXCEPTION: 100000, //nolint
}
eventStateWeight = map[State]int{
StateOK: 0,
StateWARN: 1,
StateERROR: 100, //nolint
StateNODATA: 10000, //nolint
}
)
// String is a simple Stringer implementation for State.
func (state State) String() string {
return string(state)
}
// ToSelfState converts State to corresponding SelfState.
func (state State) ToSelfState() string {
if state != StateOK {
return SelfStateERROR
}
return SelfStateOK
}
// IsValid checks if valid State.
func (state State) IsValid() bool {
for _, allowedState := range eventStatesPriority {
if state == allowedState {
return true
}
}
return false
}
// ToMetricState is an auxiliary function to handle metric state properly.
func (state TTLState) ToMetricState() State {
if state == TTLStateDEL {
return StateNODATA
}
return State(state)
}
// ToTriggerState is an auxiliary function to handle trigger state properly.
func (state TTLState) ToTriggerState() State {
if state == TTLStateDEL {
return StateOK
}
return State(state)
}