mirror of
https://github.com/openziti/zrok.git
synced 2024-11-29 11:34:07 +01:00
43 lines
719 B
Go
43 lines
719 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func Run(cfg *Config) error {
|
|
logrus.Info("starting")
|
|
defer logrus.Warn("stopping")
|
|
|
|
if cfg.Source == nil {
|
|
return errors.New("no 'source' configured; exiting")
|
|
}
|
|
|
|
src, ok := cfg.Source.(Source)
|
|
if !ok {
|
|
return errors.New("invalid 'source'; exiting")
|
|
}
|
|
|
|
events := make(chan map[string]interface{}, 1024)
|
|
srcJoin, err := src.Start(events)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error starting source")
|
|
}
|
|
|
|
go func() {
|
|
ingester := &UsageIngester{}
|
|
for {
|
|
select {
|
|
case event := <-events:
|
|
if err := ingester.Ingest(event); err != nil {
|
|
logrus.Error(err)
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
|
|
<-srcJoin
|
|
|
|
return nil
|
|
}
|