more limits.Agent elaboration (#271)

This commit is contained in:
Michael Quigley
2023-03-17 13:13:33 -04:00
parent b69237e9cc
commit 9418195150
4 changed files with 58 additions and 6 deletions

View File

@ -5,23 +5,56 @@ import (
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/sirupsen/logrus"
"time"
)
type Agent struct {
cfg *Config
ifx *influxReader
zCfg *zrokEdgeSdk.Config
str *store.Store
close chan struct{}
join chan struct{}
}
func NewAgent(cfg *Config, ifxCfg *metrics.InfluxConfig, zCfg *zrokEdgeSdk.Config, str *store.Store) (*Agent, error) {
return &Agent{}, nil
return &Agent{
cfg: cfg,
ifx: newInfluxReader(ifxCfg),
zCfg: zCfg,
str: str,
close: make(chan struct{}),
join: make(chan struct{}),
}, nil
}
func (a *Agent) Start() error {
return nil
func (a *Agent) Start() {
go a.run()
}
func (a *Agent) Stop() {
close(a.close)
<-a.join
}
func (a *Agent) Handle(u *metrics.Usage) error {
logrus.Infof("handling: %v", u)
return nil
}
func (a *Agent) run() {
logrus.Info("started")
defer logrus.Info("stopped")
mainLoop:
for {
select {
case <-time.After(a.cfg.Cycle):
logrus.Info("insepection cycle")
case <-a.close:
close(a.join)
break mainLoop
}
}
}