-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (59 loc) · 2.15 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
package main
import (
"flag"
"os"
"time"
log "github.com/cihub/seelog"
"github.com/HailoOSS/api-proxy/controlplane"
"github.com/HailoOSS/api-proxy/handler"
hc "github.com/HailoOSS/api-proxy/healthcheck"
"github.com/HailoOSS/api-proxy/stats"
service "github.com/HailoOSS/platform/server"
"github.com/HailoOSS/service/config"
"github.com/HailoOSS/service/zookeeper"
)
var (
accessLogName string
)
func init() {
service.Name = "com.HailoOSS.hailo-2-api"
service.Description = "Routing layer that handles all inbound client requests, routing them to H1, H2, or " +
"throttling them."
service.Version = ServiceVersion
service.Source = "github.com/HailoOSS/api-proxy"
service.OwnerEmail = "oliver.beattie@HailoOSS.com"
service.OwnerMobile = "+447584048620"
service.OwnerTeam = "h2o"
// Before we proceed, load the "last known good" config
controlplane.LoadLastGoodConfig()
flag.StringVar(&accessLogName, "accesslog", "access_log", "The location where Apache-style logs should be written")
service.Init()
}
func main() {
config.WaitUntilLoaded(2 * time.Second)
accessLog, err := os.OpenFile(accessLogName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Criticalf("Can't create access log: ", err)
os.Exit(6)
}
defer accessLog.Close()
// Register stats collection
stats.Init(service.Name, ServiceVersion, service.InstanceID)
stats.Register("/rpc")
stats.Register("/v2/h2/call")
stats.Register("/v1/point/batch")
stats.Register("/")
stats.Start()
server := handler.NewServer(accessLog)
// Initalise ZK and wait for us to get up and running (for status monitor)
zookeeper.WaitForConnect(time.Second)
// Initalise healthchecks
hc.Init(server.Monitor)
hc.RegisterErrorRateCheck(service.Name+".http.root", "/", 0.05)
hc.RegisterErrorRateCheck(service.Name+".http.v2-h2-call", "/v2/h2/call", 0.25)
hc.RegisterErrorRateCheck(service.Name+".http.rpc", "/rpc", 0.25)
hc.RegisterErrorRateCheck(service.Name+".http.v1-point-batch", "/v1/point/batch", 0.10)
hc.RegisterDropOffCheck(service.Name+".http.root.request-rate", "/", 0.5)
log.Infof("Listening at %v", server.HTTPServer.Addr)
log.Critical(server.HTTPServer.ListenAndServe())
}