metrics service name; metrics agent shutdown (#74, #76)

This commit is contained in:
Michael Quigley 2022-10-13 15:50:12 -04:00
parent dae4e9b1ec
commit 41d5c2b652
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 35 additions and 16 deletions

View File

@ -13,7 +13,7 @@ type Config struct {
Registration *RegistrationConfig
Store *store.Config
Ziti *ZitiConfig
MetricsConfig *MetricsConfig
Metrics *MetricsConfig
}
type EndpointConfig struct {

View File

@ -44,8 +44,14 @@ func Run(cfg *Config) error {
return errors.Wrap(err, "error opening store")
}
mtr = newMetricsAgent(cfg.MetricsConfig)
if cfg.Metrics != nil {
mtr = newMetricsAgent(cfg.Metrics)
go mtr.run()
defer func() {
mtr.stop()
mtr.join()
}()
}
server := rest_server_zrok.NewServer(api)
defer func() { _ = server.Shutdown() }()

View File

@ -2,10 +2,10 @@ package controller
import (
"github.com/sirupsen/logrus"
"time"
)
type MetricsConfig struct {
ServiceName string
Influx *InfluxConfig
}
@ -18,17 +18,30 @@ type InfluxConfig struct {
type metricsAgent struct {
cfg *MetricsConfig
shutdown chan struct{}
joined chan struct{}
}
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
return &metricsAgent{cfg: cfg}
return &metricsAgent{
cfg: cfg,
shutdown: make(chan struct{}),
joined: make(chan struct{}),
}
}
func (mtr *metricsAgent) run() {
logrus.Info("starting")
defer logrus.Info("exiting")
defer close(mtr.joined)
for {
time.Sleep(24 * time.Hour)
<-mtr.shutdown
}
func (mtr *metricsAgent) stop() {
close(mtr.shutdown)
}
func (mtr *metricsAgent) join() {
<-mtr.joined
}