-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
112 lines (94 loc) · 2.96 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
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
111
112
package main
import (
"fmt"
log "github.com/Financial-Times/go-logger"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
"github.com/jawher/mow.cli"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
app := cli.App("upp-aggregate-healthcheck", "Monitoring health of multiple services in cluster.")
appName := app.String(cli.StringOpt{
Name: "app-name",
Value: "upp-aggregate-healthcheck",
Desc: "Application name",
EnvVar: "APP_NAME",
})
port := app.Int(cli.IntOpt{
Name: "port",
Value: 8080,
Desc: "Port to listen on",
EnvVar: "APP_PORT",
})
environment := app.String(cli.StringOpt{
Name: "environment",
Value: "Default-environment",
Desc: "Environment tag (e.g. local, pre-prod, prod-uk)",
EnvVar: "ENVIRONMENT",
})
pathPrefix := app.String(cli.StringOpt{
Name: "pathPrefix",
Value: "",
Desc: "Path prefix for all endpoints",
EnvVar: "PATH_PREFIX",
})
clusterURL := app.String(cli.StringOpt{
Name: "cluster-url",
Value: "",
Desc: "Cluster URL",
EnvVar: "CLUSTER_URL",
})
logLevel := app.String(cli.StringOpt{
Name: "log-level",
Value: "INFO",
Desc: "App log level",
EnvVar: "LOG_LEVEL",
})
log.InitLogger(*appName, *logLevel)
app.Action = func() {
log.Infof("Starting app with params: [environment: %s], [pathPrefix: %s]", *environment, *pathPrefix)
controller := initializeController(*environment)
handler := &httpHandler{
controller: controller,
pathPrefix: *pathPrefix,
clusterURL: *clusterURL,
}
prometheusFeeder := newPrometheusFeeder(*environment, controller)
go prometheusFeeder.feed()
listen(handler, *pathPrefix, *port)
}
err := app.Run(os.Args)
if err != nil {
panic(fmt.Sprintf("Cannot run the app. Error was: %v", err))
}
}
func listen(httpHandler *httpHandler, pathPrefix string, port int) {
r := mux.NewRouter()
r.HandleFunc("/__gtg", httpHandler.handleGoodToGo)
r.Handle("/metrics", promhttp.Handler())
s := r.PathPrefix(pathPrefix).Subrouter()
s.HandleFunc("/add-ack", httpHandler.handleAddAck).Methods("POST")
s.HandleFunc("/enable-category", httpHandler.handleEnableCategory)
s.HandleFunc("/disable-category", httpHandler.handleDisableCategory)
s.HandleFunc("/rem-ack", httpHandler.handleRemoveAck)
s.HandleFunc("/add-ack-form", httpHandler.handleAddAckForm)
s.HandleFunc("", httpHandler.handleServicesHealthCheck)
s.HandleFunc("/", httpHandler.handleServicesHealthCheck)
s.HandleFunc("/__pods-health", httpHandler.handlePodsHealthCheck)
s.HandleFunc("/__pod-individual-health", httpHandler.handleIndividualPodHealthCheck)
s.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("resources/"))))
srv := &http.Server{
Addr: fmt.Sprintf(":%d", port),
WriteTimeout: time.Second * 90,
ReadTimeout: time.Second * 90,
IdleTimeout: time.Second * 90,
Handler: r,
}
err := srv.ListenAndServe()
if err != nil {
panic(fmt.Sprintf("Cannot set up HTTP listener. Error was: %v", err))
}
}