forked from blind-oracle/cortex-tenant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (60 loc) · 1.41 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
package main
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
)
var (
version = "0.0.0"
)
func main() {
cfgFile := flag.String("config", "", "Path to a config file")
flag.Parse()
if *cfgFile == "" {
log.Fatalf("Config file required")
}
cfg, err := configLoad(*cfgFile)
if err != nil {
log.Fatal(err)
}
if cfg.ListenPprof != "" {
go func() {
if err := http.ListenAndServe(cfg.ListenPprof, nil); err != nil {
log.Fatalf("Unable to listen on %s: %s", cfg.ListenPprof, err)
}
}()
}
if cfg.LogLevel != "" {
lvl, err := log.ParseLevel(cfg.LogLevel)
if err != nil {
log.Fatalf("Unable to parse log level: %s", err)
}
log.SetLevel(lvl)
}
var disp *dispatcher
proc := newProcessor(*cfg, disp)
if cfg.Tenant.NamespaceLabel != "" {
disp, err = newdispatcher(cfg.Tenant.NamespaceLabel, cfg.Tenant.QueryInterval, proc)
if err != nil {
log.Fatalf("Unable to create k8s poller: %s", err)
}
go disp.run()
}
proc.disp = disp // FIXME please
if err = proc.run(); err != nil {
log.Fatalf("Unable to start: %s", err)
}
log.Warnf("Listening on %s", cfg.Listen)
log.Warnf("Started v%s", version)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, os.Interrupt)
<-ch
log.Warn("Shutting down, draining requests")
if err = proc.close(); err != nil {
log.Errorf("Error during shutdown: %s", err)
}
log.Warnf("Finished")
}