-
Notifications
You must be signed in to change notification settings - Fork 2
/
healthcheck.go
62 lines (54 loc) · 1.54 KB
/
healthcheck.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
package main
import (
"net/http"
"time"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
"github.com/Financial-Times/service-status-go/gtg"
)
type ConnectionChecker func() (string, error)
type HealthcheckService struct {
AppSystemCode string
AppName string
AppDescription string
ConnChecker ConnectionChecker
}
func (h *HealthcheckService) HealthHandler() func(w http.ResponseWriter, r *http.Request) {
hc := fthealth.TimedHealthCheck{
HealthCheck: fthealth.HealthCheck{
SystemCode: h.AppSystemCode,
Name: h.AppName,
Description: h.AppDescription,
Checks: h.Checks(),
},
Timeout: 10 * time.Second,
}
return fthealth.Handler(hc)
}
func (h *HealthcheckService) GTG() gtg.Status {
var statusChecker []gtg.StatusChecker
for _, c := range h.Checks() {
checkFunc := func() gtg.Status {
return gtgCheck(c.Checker)
}
statusChecker = append(statusChecker, checkFunc)
}
return gtg.FailFastParallelCheck(statusChecker)()
}
func (h *HealthcheckService) Checks() []fthealth.Check {
return []fthealth.Check{
{
BusinessImpact: "Cannot respond to API requests",
Name: "Check connectivity to Neo4j",
PanicGuide: "https://runbooks.ftops.tech/" + h.AppSystemCode,
Severity: 2,
TechnicalSummary: "Cannot connect to Neo4j instance",
Checker: h.ConnChecker,
},
}
}
func gtgCheck(handler func() (string, error)) gtg.Status {
if _, err := handler(); err != nil {
return gtg.Status{GoodToGo: false, Message: err.Error()}
}
return gtg.Status{GoodToGo: true}
}