-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
115 lines (99 loc) · 2.63 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
113
114
115
package main
import (
"context"
"errors"
"github.com/SoftwareDefinedBuildings/mortar/stages"
"github.com/heptiolabs/healthcheck"
"github.com/pkg/profile"
"github.com/prometheus/client_golang/prometheus/promhttp"
logrus "github.com/sirupsen/logrus"
"net/http"
"os"
)
var log = logrus.New()
func init() {
log.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, ForceColors: true})
log.SetOutput(os.Stdout)
log.SetLevel(logrus.DebugLevel)
}
func main() {
doCPUprofile := false
if doCPUprofile {
defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
}
doBlockprofile := false
if doBlockprofile {
defer profile.Start(profile.BlockProfile, profile.ProfilePath(".")).Stop()
}
maincontext, cancel := context.WithCancel(context.Background())
cfg, err := stages.ReadConfig("mortarconfig.yml")
if err != nil {
log.Fatal(err)
}
log.Infof("%+v", cfg)
brickready := false
health := healthcheck.NewHandler()
health.AddReadinessCheck("brick", func() error {
if !brickready {
return errors.New("Brick not ready")
}
return nil
})
go http.ListenAndServe("0.0.0.0:8086", health)
http.Handle("/metrics", promhttp.Handler())
go func() {
log.Infof("Prometheus endpoint at %s", cfg.PrometheusAddr)
if err := http.ListenAndServe(cfg.PrometheusAddr, nil); err != nil {
log.Fatal(err)
}
}()
frontend_stage_cfg := &stages.ApiFrontendBasicStageConfig{
StageContext: maincontext,
ListenAddr: cfg.ListenAddr,
AuthConfig: cfg.Cognito,
TLSCrtFile: cfg.TLSCrtFile,
TLSKeyFile: cfg.TLSKeyFile,
}
frontend_stage, err := stages.NewApiFrontendBasicStage(frontend_stage_cfg)
if err != nil {
log.Fatal(err)
}
md_stage_cfg := &stages.BrickQueryStageConfig{
Upstream: frontend_stage,
StageContext: maincontext,
HodConfigLocation: cfg.HodConfig,
}
md_stage, err := stages.NewBrickQueryStage(md_stage_cfg)
if err != nil {
log.Fatal(err)
}
brickready = true
ts_stage_cfg := &stages.TimeseriesStageConfig{
Upstream: md_stage,
StageContext: maincontext,
BTrDBAddress: cfg.BTrDBAddr,
}
ts_stage, err := stages.NewTimeseriesQueryStage(ts_stage_cfg)
if err != nil {
log.Fatal(err)
}
// ts_stage_cfg := &stages.InfluxDBTimeseriesStageConfig{
// Upstream: md_stage,
// StageContext: maincontext,
// Address: cfg.InfluxDBAddr,
// Username: cfg.InfluxDBUser,
// Password: cfg.InfluxDBPass,
// }
// ts_stage, err := stages.NewInfluxDBTimeseriesQueryStage(ts_stage_cfg)
// if err != nil {
// log.Fatal(err)
// }
//_ = ts_stage
var end stages.Stage = ts_stage
for end != nil {
log.Println(end)
end = end.GetUpstream()
}
select {}
cancel()
}