-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.go
46 lines (38 loc) · 1.01 KB
/
main.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
package main
import (
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/andreas-schroeder/kafka-health-check/check"
)
func main() {
healthCheck := check.New(checkConfiguration)
healthCheck.ParseCommandLineArguments()
stop, awaitCheck := addShutdownHook()
brokerUpdates, clusterUpdates := make(chan check.Update, 2), make(chan check.Update, 2)
go healthCheck.ServeHealth(brokerUpdates, clusterUpdates, stop)
healthCheck.CheckHealth(brokerUpdates, clusterUpdates, stop)
awaitCheck.Done()
}
func addShutdownHook() (chan struct{}, *sync.WaitGroup) {
stop := make(chan struct{})
awaitCheck := &sync.WaitGroup{}
awaitCheck.Add(1)
shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, os.Interrupt)
signal.Notify(shutdown, syscall.SIGTERM)
go func() {
for range shutdown {
close(stop)
awaitCheck.Wait()
}
}()
return stop, awaitCheck
}
var checkConfiguration = check.HealthCheckConfig{
CheckTimeout: 200 * time.Millisecond,
DataWaitInterval: 20 * time.Millisecond,
MessageLength: 20,
}