-
Notifications
You must be signed in to change notification settings - Fork 134
/
manualhealthmonitor.go
58 lines (47 loc) · 1.22 KB
/
manualhealthmonitor.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
package healthmonitor
import (
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/armadaproject/armada/internal/common/armadacontext"
)
// ManualHealthMonitor is a manually controlled health monitor.
type ManualHealthMonitor struct {
isHealthy bool
reason string
mu sync.Mutex
}
func NewManualHealthMonitor() *ManualHealthMonitor {
return &ManualHealthMonitor{
reason: ManuallyDisabledReason,
}
}
func (srv *ManualHealthMonitor) SetHealthStatus(isHealthy bool) bool {
srv.mu.Lock()
defer srv.mu.Unlock()
previous := srv.isHealthy
srv.isHealthy = isHealthy
return previous
}
func (srv *ManualHealthMonitor) WithReason(reason string) *ManualHealthMonitor {
srv.mu.Lock()
defer srv.mu.Unlock()
srv.reason = reason
return srv
}
func (srv *ManualHealthMonitor) IsHealthy() (bool, string, error) {
srv.mu.Lock()
defer srv.mu.Unlock()
if srv.isHealthy {
return true, "", nil
} else {
return false, srv.reason, nil
}
}
func (srv *ManualHealthMonitor) Run(_ *armadacontext.Context, _ *logrus.Entry) error {
return nil
}
func (srv *ManualHealthMonitor) Describe(c chan<- *prometheus.Desc) {
}
func (srv *ManualHealthMonitor) Collect(c chan<- prometheus.Metric) {
}