-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
66 lines (50 loc) · 1.94 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/gojektech/heimdall/httpclient"
)
var kongHost = flag.String("kong", "", "kong host")
var kongAdminPort = flag.String("kong-admin-port", "8001", "kong admin port")
var kongClientTimeout = flag.Duration("kong-client-timeout", 1000, "http client timeout")
var healthCheckInterval = flag.String("health-check-interval", "2000", "health check interval in ms")
var healthCheckPath = flag.String("health-check-path", "/ping", "path to check for active health check")
var healthCheckType = flag.String("health-check-type", "tcp", "supports http or tcp checks")
var workerCount = flag.Int("worker-count", 100, "no of workers which participate in healthcheck of targets")
var targetsQLen = flag.Int("targets-queue-length", 100, "length of the queue for storing targets")
func main() {
flag.Parse()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
if *kongHost == "" {
log.Fatalf("`kong` flag did not provide kong host")
}
pingQ := make(chan target, *targetsQLen)
client := newKongClient(*kongHost, *kongAdminPort, *kongClientTimeout)
p := pinger{
client: client,
pingClient: httpclient.NewClient(),
pingPath: *healthCheckPath,
workQ: pingQ,
healthCheckType: *healthCheckType,
}
wm := newWorkerManager(*workerCount, p.start)
go wm.start()
defer wm.stop()
kongHealthCheckConfig := &kongHealthCheckConfig{
healthCheckPath: *healthCheckPath,
healthCheckInterval: *healthCheckInterval,
}
healthCheck, err := newKongHealthCheck(pingQ, client, kongHealthCheckConfig)
if err != nil {
log.Fatalf("failed to initialise health checker: %s", err)
}
go healthCheck.start()
defer healthCheck.stop()
log.Printf("started kong-healthcheck for kong host: %s with interval: %s ms", *kongHost, *healthCheckInterval)
sig := <-sigChan
log.Printf("stopping kong-healthcheck, received os signal: %v", sig)
}