-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (58 loc) · 1.57 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/benbjohnson/clock"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
"go.uber.org/zap"
"github.com/synyx/tuwat/pkg/aggregation"
"github.com/synyx/tuwat/pkg/config"
"github.com/synyx/tuwat/pkg/log"
"github.com/synyx/tuwat/pkg/version"
"github.com/synyx/tuwat/pkg/web"
"github.com/synyx/tuwat/pkg/web/actuator"
"github.com/synyx/tuwat/pkg/web/api/alertmanager"
)
func main() {
appCtx := ApplicationContext()
cfg, err := config.NewConfiguration()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if cfg.PrintVersion {
fmt.Println(version.Info.HumanReadable())
return
}
log.Initialize(cfg)
log.InitializeTracer(appCtx, cfg)
clk := clock.New()
aggregator := aggregation.NewAggregator(cfg, clk)
webHandler := web.WebHandler(cfg, aggregator)
alertmanagerApi := alertmanager.ApiV2(cfg, aggregator)
acc := actuator.NewHealthAccumulator(clk)
acc.Register("aggregation", aggregation.NewAggregatorHealthCheck(aggregator))
go web.Handle(appCtx, cfg, webHandler, alertmanagerApi)
go aggregator.Run(appCtx)
go acc.Run(appCtx)
go actuator.Handle(appCtx, cfg)
reconfigure := make(chan os.Signal, 1)
signal.Notify(reconfigure, syscall.SIGHUP)
for {
select {
case <-reconfigure:
otelzap.Ctx(appCtx).Info("Rereading configuration")
cfg, err := config.NewConfiguration()
if err != nil {
otelzap.Ctx(appCtx).Error("Failed to read new configuration", zap.Error(err))
break
}
aggregator.Reconfigure(cfg)
case <-appCtx.Done():
otelzap.Ctx(appCtx).Info("Exiting")
return
}
}
}