This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
healthchecks.go
110 lines (93 loc) · 3.55 KB
/
healthchecks.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"fmt"
"net/http"
"time"
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"
)
const systemCode = "kafka-bridge"
type HealthCheck struct {
consumer consumer.MessageConsumer
producer producer.MessageProducer
producerType string
}
func NewHealthCheck(consumerConf *consumer.QueueConfig, p producer.MessageProducer, producerType string, client *http.Client) *HealthCheck {
c := consumer.NewConsumer(*consumerConf, func(m consumer.Message) {}, client)
return &HealthCheck{
consumer: c,
producer: p,
producerType: producerType,
}
}
// Health returns a healthcheck handler
func (hc HealthCheck) Health() func(w http.ResponseWriter, r *http.Request) {
description := "Services: source-kafka-proxy, cms-notifier"
checks := []fthealth.Check{
hc.consumeHealthcheck(), hc.httpForwarderHealthcheck(),
}
if hc.producerType == proxy {
description = "Services: source-kafka-proxy, destination-kafka-proxy"
checks = []fthealth.Check{hc.consumeHealthcheck(), hc.proxyForwarderHealthcheck()}
}
healthCheck := fthealth.TimedHealthCheck{
HealthCheck: fthealth.HealthCheck{
SystemCode: systemCode,
Name: "Dependent services healthcheck",
Description: description,
Checks: checks,
},
Timeout: 10 * time.Second,
}
return fthealth.Handler(healthCheck)
}
func (hc HealthCheck) consumeHealthcheck() fthealth.Check {
return fthealth.Check{
BusinessImpact: "Consuming messages through kafka-proxy won't work. Publishing in the containerised stack won't work.",
Name: "Consume messages from kafka-proxy",
PanicGuide: fmt.Sprintf("https://runbooks.ftops.tech/%s", systemCode),
Severity: 1,
TechnicalSummary: "Consuming messages is broken. Check if source proxy is reachable.",
Checker: hc.consumer.ConnectivityCheck,
}
}
func (hc HealthCheck) proxyForwarderHealthcheck() fthealth.Check {
return fthealth.Check{
BusinessImpact: "Forwarding messages to kafka-proxy in coco won't work. Publishing in the containerised stack won't work.",
Name: "Forward messages to kafka-proxy.",
PanicGuide: fmt.Sprintf("https://runbooks.ftops.tech/%s", systemCode),
Severity: 1,
TechnicalSummary: "Forwarding messages is broken. Check if destination proxy is reachable.",
Checker: hc.producer.ConnectivityCheck,
}
}
func (hc HealthCheck) httpForwarderHealthcheck() fthealth.Check {
return fthealth.Check{
BusinessImpact: "Forwarding messages to cms-notifier in coco won't work. Publishing in the containerised stack won't work.",
Name: "Forward messages to cms-notifier",
PanicGuide: fmt.Sprintf("https://runbooks.ftops.tech/%s", systemCode),
Severity: 1,
TechnicalSummary: "Forwarding messages is broken. Check networking, cluster reachability and/or cms-notifier state.",
Checker: hc.producer.ConnectivityCheck,
}
}
func (hc HealthCheck) GTG() gtg.Status {
consumerCheck := func() gtg.Status {
return gtgCheck(hc.consumer.ConnectivityCheck)
}
producerCheck := func() gtg.Status {
return gtgCheck(hc.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}
}