This repository was archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhealthcheck.go
78 lines (68 loc) · 2.4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"net/http"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
"github.com/Financial-Times/message-queue-go-producer/producer"
"github.com/Financial-Times/message-queue-gonsumer/consumer"
"github.com/Financial-Times/service-status-go/gtg"
)
type HealthCheck struct {
consumer consumer.MessageConsumer
producer producer.MessageProducer
}
func NewHealthCheck(p producer.MessageProducer, c consumer.MessageConsumer) *HealthCheck {
return &HealthCheck{
consumer: c,
producer: p,
}
}
func (h *HealthCheck) Health() func(w http.ResponseWriter, r *http.Request) {
checks := []fthealth.Check{h.readQueueCheck(), h.writeQueueCheck()}
hc := fthealth.HealthCheck{
SystemCode: "v1-suggestor",
Name: "V1 Suggestor",
Description: "Checks if all the dependent services are reachable and healthy.",
Checks: checks,
}
return fthealth.Handler(hc)
}
func (h *HealthCheck) readQueueCheck() fthealth.Check {
return fthealth.Check{
ID: "read-message-queue-proxy-reachable",
Name: "Read Message Queue Proxy Reachable",
Severity: 1,
BusinessImpact: "Content V1 Metadata can't be read from queue. This will negatively impact V1 metadata availability.",
TechnicalSummary: "Read message queue proxy is not reachable/healthy",
PanicGuide: "https://dewey.ft.com/",
Checker: h.consumer.ConnectivityCheck,
}
}
func (h *HealthCheck) writeQueueCheck() fthealth.Check {
return fthealth.Check{
ID: "write-message-queue-proxy-reachable",
Name: "Write Message Queue Proxy Reachable",
Severity: 1,
BusinessImpact: "Content V1 Metadata can't be propagated through the stack. V1 metadata won't be available for new content.",
TechnicalSummary: "Write message queue proxy is not reachable/healthy",
PanicGuide: "https://dewey.ft.com/",
Checker: h.producer.ConnectivityCheck,
}
}
func (h *HealthCheck) GTG() gtg.Status {
consumerCheck := func() gtg.Status {
return gtgCheck(h.consumer.ConnectivityCheck)
}
producerCheck := func() gtg.Status {
return gtgCheck(h.producer.ConnectivityCheck)
}
return gtg.FailFastParallelCheck([]gtg.StatusChecker{
consumerCheck,
producerCheck,
})()
}
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}
}