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

@ -7,13 +7,13 @@ import (
)
type Config struct {
Endpoint *EndpointConfig
Proxy *ProxyConfig
Email *EmailConfig
Registration *RegistrationConfig
Store *store.Config
Ziti *ZitiConfig
MetricsConfig *MetricsConfig
Endpoint *EndpointConfig
Proxy *ProxyConfig
Email *EmailConfig
Registration *RegistrationConfig
Store *store.Config
Ziti *ZitiConfig
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)
go mtr.run()
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,11 +2,11 @@ package controller
import (
"github.com/sirupsen/logrus"
"time"
)
type MetricsConfig struct {
Influx *InfluxConfig
ServiceName string
Influx *InfluxConfig
}
type InfluxConfig struct {
@ -17,18 +17,31 @@ type InfluxConfig struct {
}
type metricsAgent struct {
cfg *MetricsConfig
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
}