-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathurgency.go
More file actions
85 lines (78 loc) · 2.01 KB
/
urgency.go
File metadata and controls
85 lines (78 loc) · 2.01 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
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
package libhealth
import "strings"
// Urgency is a level of requirement for a service to be operational. A REQUIRED
// service would cause major service disruption if it is not healthy. Likewise a
// WEAK service can fail without major issues.
type Urgency int
const (
REQUIRED Urgency = iota
STRONG
WEAK
NONE
UNKNOWN
)
// ParseUrgency converts the given string into an Urgency.
// If the string is malformed, UNKNOWN is returned.
func ParseUrgency(urgency string) Urgency {
switch strings.ToUpper(urgency) {
case "REQUIRED":
return REQUIRED
case "STRONG":
return STRONG
case "WEAK":
return WEAK
case "NONE":
return NONE
default:
return UNKNOWN
}
}
// String provides an obvious representation of the Urgency level
func (u Urgency) String() string {
switch u {
case REQUIRED:
return "REQUIRED"
case STRONG:
return "STRONG"
case WEAK:
return "WEAK"
case NONE:
return "NONE"
case UNKNOWN:
return "UNKNOWN"
}
return "UNKNOWN"
}
// Detail provides a detailed representation of the Urgency level
func (u Urgency) Detail() string {
switch u {
case REQUIRED:
return "Required: Failure of this dependency would result in complete system outage"
case STRONG:
return "Strong: Failure of this dependency would result in major functional degradation"
case WEAK:
return "Weak: Failure of this dependency would result in minor functionality loss"
case NONE:
return "None: Failure of this dependency would result in no loss of functionality"
case UNKNOWN:
return "Unknown"
}
return "Invalid"
}
// DowngradeWith returns the downgraded Outage state according to HCv3 math.
func (u Urgency) DowngradeWith(systemState, newState Status) Status {
switch u {
case REQUIRED:
return WorstState(systemState, newState)
case STRONG:
bounded := BestState(newState, MAJOR)
return WorstState(systemState, bounded)
case WEAK:
bounded := BestState(newState, MINOR)
return WorstState(systemState, bounded)
case NONE:
return systemState
default: // UNKNOWN
return WorstState(systemState, newState)
}
}