ncro: call Validate() in main; wire metrics, priority, and mesh stub
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I428e17606daf1833d5aea20a22461abe6a6a6964
This commit is contained in:
parent
8da709dc98
commit
02e7065171
1 changed files with 22 additions and 7 deletions
|
|
@ -10,8 +10,11 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"notashelf.dev/ncro/internal/cache"
|
"notashelf.dev/ncro/internal/cache"
|
||||||
"notashelf.dev/ncro/internal/config"
|
"notashelf.dev/ncro/internal/config"
|
||||||
|
"notashelf.dev/ncro/internal/mesh"
|
||||||
|
"notashelf.dev/ncro/internal/metrics"
|
||||||
"notashelf.dev/ncro/internal/prober"
|
"notashelf.dev/ncro/internal/prober"
|
||||||
"notashelf.dev/ncro/internal/router"
|
"notashelf.dev/ncro/internal/router"
|
||||||
"notashelf.dev/ncro/internal/server"
|
"notashelf.dev/ncro/internal/server"
|
||||||
|
|
@ -26,6 +29,10 @@ func main() {
|
||||||
slog.Error("failed to load config", "error", err)
|
slog.Error("failed to load config", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
if err := cfg.Validate(); err != nil {
|
||||||
|
slog.Error("invalid config", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
level := slog.LevelInfo
|
level := slog.LevelInfo
|
||||||
switch cfg.Logging.Level {
|
switch cfg.Logging.Level {
|
||||||
|
|
@ -44,6 +51,8 @@ func main() {
|
||||||
}
|
}
|
||||||
slog.SetDefault(slog.New(handler))
|
slog.SetDefault(slog.New(handler))
|
||||||
|
|
||||||
|
metrics.Register(prometheus.DefaultRegisterer)
|
||||||
|
|
||||||
db, err := cache.Open(cfg.Cache.DBPath, cfg.Cache.MaxEntries)
|
db, err := cache.Open(cfg.Cache.DBPath, cfg.Cache.MaxEntries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to open database", "path", cfg.Cache.DBPath, "error", err)
|
slog.Error("failed to open database", "path", cfg.Cache.DBPath, "error", err)
|
||||||
|
|
@ -68,18 +77,24 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
p := prober.New(cfg.Cache.LatencyAlpha)
|
p := prober.New(cfg.Cache.LatencyAlpha)
|
||||||
upstreamURLs := make([]string, len(cfg.Upstreams))
|
p.InitUpstreams(cfg.Upstreams)
|
||||||
for i, u := range cfg.Upstreams {
|
for _, u := range cfg.Upstreams {
|
||||||
upstreamURLs[i] = u.URL
|
go p.ProbeUpstream(u.URL)
|
||||||
}
|
|
||||||
p.InitUpstreams(upstreamURLs)
|
|
||||||
for _, u := range upstreamURLs {
|
|
||||||
go p.ProbeUpstream(u)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
probeDone := make(chan struct{})
|
probeDone := make(chan struct{})
|
||||||
go p.RunProbeLoop(30*time.Second, probeDone)
|
go p.RunProbeLoop(30*time.Second, probeDone)
|
||||||
|
|
||||||
|
if cfg.Mesh.Enabled {
|
||||||
|
node, err := mesh.NewNode(cfg.Mesh.PrivateKeyPath, nil)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("failed to create mesh node", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
slog.Info("mesh enabled", "node_id", node.ID(), "peers", len(cfg.Mesh.Peers))
|
||||||
|
slog.Warn("mesh gossip not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
r := router.New(db, p, cfg.Cache.TTL.Duration, 5*time.Second)
|
r := router.New(db, p, cfg.Cache.TTL.Duration, 5*time.Second)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: cfg.Server.Listen,
|
Addr: cfg.Server.Listen,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue