-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
health_controller.go
95 lines (70 loc) · 2.06 KB
/
health_controller.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
89
90
91
92
93
94
95
package web
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/smartcontractkit/chainlink/v2/core/services"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/web/presenters"
)
type HealthController struct {
App chainlink.Application
}
// NOTE: We only implement the k8s readiness check, *not* the liveness check. Liveness checks are only recommended in cases
// where the app doesn't crash itself on panic, and if implemented incorrectly can cause cascading failures.
// See the following for more information:
// - https://srcco.de/posts/kubernetes-liveness-probes-are-dangerous.html
func (hc *HealthController) Readyz(c *gin.Context) {
status := http.StatusOK
checker := hc.App.GetHealthChecker()
ready, errors := checker.IsReady()
if !ready {
status = http.StatusServiceUnavailable
}
c.Status(status)
if _, ok := c.GetQuery("full"); !ok {
return
}
checks := make([]presenters.Check, 0, len(errors))
for name, err := range errors {
status := services.StatusPassing
var output string
if err != nil {
status = services.StatusFailing
output = err.Error()
}
checks = append(checks, presenters.Check{
JAID: presenters.NewJAID(name),
Name: name,
Status: status,
Output: output,
})
}
// return a json description of all the checks
jsonAPIResponse(c, checks, "checks")
}
func (hc *HealthController) Health(c *gin.Context) {
status := http.StatusOK
checker := hc.App.GetHealthChecker()
healthy, errors := checker.IsHealthy()
if !healthy {
status = http.StatusServiceUnavailable
}
c.Status(status)
checks := make([]presenters.Check, 0, len(errors))
for name, err := range errors {
status := services.StatusPassing
var output string
if err != nil {
status = services.StatusFailing
output = err.Error()
}
checks = append(checks, presenters.Check{
JAID: presenters.NewJAID(name),
Name: name,
Status: status,
Output: output,
})
}
// return a json description of all the checks
jsonAPIResponse(c, checks, "checks")
}